#ifndef NETWORK_DEVICE_MONITOR_H
#define NETWORK_DEVICE_MONITOR_H

#include <QObject>
#include "device_information.h"

enum class MonitorStatus : int
{
    START_DETECT = 0,
    STOP_DETECT
};


// NetworkDeviceMonitor 用法：
// NetworkDeviceMonitor *p = NetworkDeviceMonitor::getInstance();

// 设置是否发送测试信息 默认为false
// 如果修改为true 发送一条测试信息
// p->sendTestinfo = false;
// connect (p,     SIGNAL(findNetworkConnect(DeviceInformation &)   ),
//           类名,  SLOT (要触发的槽  ));

// 开启自动寻找网络打印机
// p->start();

// 通过
// p->setHost("192.168.17.90")
class NetworkDeviceMonitor : public QObject
{
    Q_OBJECT
public:
    // 设置是否发送测试信息 默认为false
    // 如果修改为true 发送一条测试信息
    bool m_sendTestinfo;
    static NetworkDeviceMonitor *getInstance();
    ~NetworkDeviceMonitor();
    
    /**
     * @brief 通过ip返回 设备信息
     * 
     * @return DeviceInformation
     * 如果connectType 的值为 ConnectType::InfoFrom_Invalid,
     * 则是没有检测到打印机；
     */
    static QList<DeviceInformation> getDeviceFromIP(const QString &ip, const int port = 9100, ProtocolType protocolType = ProtocolType::SOCKET);
private:
    NetworkDeviceMonitor(/* args */);
    void detectStart ();

signals:
    void getDeviceFromIP_async(const QString &ip, const int port = 9100, ProtocolType protocolType = ProtocolType::SOCKET);
    void getDeviceFromIP_cb(DeviceInformation &devInfo);
    void start();
    void setHost(const QString &);
    void findNetworkConnect(DeviceInformation &);
};

#endif // NETWORK_DEVICE_MONITOR_H