#include "dmpdataserver.h"

DMPDataServer::DMPDataServer(QObject *parent) : QTcpServer (parent)
{

}

void DMPDataServer::start()
{
    if(listen(QHostAddress::Any,51211)){
        printf("listen port 51211\n");
    }else{
        exit(-1);
    }
}

void DMPDataServer::incomingConnection(qintptr socketDescriptor)
{
    DMPCommThread *thread = new DMPCommThread(socketDescriptor,this);
    connect(thread,&DMPCommThread::CommData,this,&DMPDataServer::eCommData);
    connect(thread,&DMPCommThread::DatabaseData,this,&DMPDataServer::eDatabaseData);
    connect(thread,&DMPCommThread::getERealtimeValue,this,&DMPDataServer::getERealtimeValue);
    connect(thread,&DMPCommThread::finished,thread,&DMPCommThread::quit);
    thread->start();
}

void DMPDataServer::eCommData(QString data)
{
    emit CommData(data);
}

void DMPDataServer::eDatabaseData(QString sql)
{
    emit DatabaseData(sql);
}

void DMPDataServer::egetERealtimeValue(QString DeviceCode, QString bstr, QString pointstr, QDateTime t)
{
    emit getERealtimeValue(DeviceCode, bstr, pointstr,t);
}
