#pragma once
#include <QWidget>
#include <QDebug>
#include <QDateTime>
#include <iostream>
#include <QThread>
#include <qtcpsocket.h>
#include "common.h"
#include "SyncQueue.h"
#include <QTcpServer>

class _TCPSendInfo
{
public:
    std::string pics_name;
    std::string result;
    std::string num;



    _TCPSendInfo()
    {
        pics_name = "";
        
    }
};

class threadSendTCP : public QThread {
public:
    QString ip;
    int port;
    int num = 0;

    threadSendTCP(QObject* o = nullptr) :QThread(o)
    {
        isLoop = true;
    }

    ~threadSendTCP()
    {
        stop();
        _TCPSendInfo TCPSendInfo;
        Local_TCP_Info_queue->put(TCPSendInfo);
        quit();
        wait();
    }
    void stop();
#ifndef __TCPServer
    bool connectTCP();
#endif
protected:
    void run();

public:
    void init(SyncQueue<_TCPSendInfo>* p_TCP_Info_queue, std::string ip_, int port_);
    void start_work();
    void sendData(_TCPSendInfo* TCPSendInfo, int Num);
#ifdef __TCPServer
private slots:
    void    onNewConnection();
    void    onClientConnected();
    void    onClientDisconnected();
#endif
public:
    SyncQueue<_TCPSendInfo>* Local_TCP_Info_queue;
    std::atomic_bool isLoop = { 0 };
    QTcpSocket* mySocket = NULL;
#ifdef __TCPServer
    QTcpServer *tcpServer = NULL;
    QAbstractSocket::SocketState ClientStatus;
#endif
};
