removed memory leaks
This commit is contained in:
parent
cfa511d82f
commit
0ba144b8e7
@ -37,19 +37,23 @@ DeviceManager::DeviceSetupStatus DevicePluginTcpCommander::setupDevice(Device *d
|
||||
if (device->deviceClassId() == tcpOutputDeviceClassId) {
|
||||
QTcpSocket *tcpSocket = new QTcpSocket(this);
|
||||
m_tcpSockets.insert(tcpSocket, device);
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
connect(tcpSocket, &QTcpSocket::connected, this, &DevicePluginTcpCommander::onTcpSocketConnected);
|
||||
connect(tcpSocket, &QTcpSocket::disconnected, this, &DevicePluginTcpCommander::onTcpSocketDisconnected);
|
||||
connect(tcpSocket, &QTcpSocket::bytesWritten, this, &DevicePluginTcpCommander::onTcpSocketBytesWritten);
|
||||
return DeviceManager::DeviceSetupStatusAsync;
|
||||
}
|
||||
|
||||
if (device->deviceClassId() == tcpInputDeviceClassId) {
|
||||
int port = device->paramValue(portParamTypeId).toInt();
|
||||
TcpServer *tcpServer = new TcpServer(port, this);
|
||||
//TODO Connect TCP Server request received
|
||||
|
||||
if (tcpServer->isValid()) {
|
||||
m_tcpServer.insert(tcpServer, device);
|
||||
connect(tcpServer, &TcpServer::connected, this, &DevicePluginTcpCommander::onTcpServerConnected);
|
||||
connect(tcpServer, &TcpServer::disconnected, this, &DevicePluginTcpCommander::onTcpServerDisconnected);
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
} else {
|
||||
tcpServer->deleteLater();
|
||||
qDebug(dcTCPCommander()) << "Could not open TCP Server";
|
||||
}
|
||||
}
|
||||
@ -65,10 +69,7 @@ DeviceManager::DeviceError DevicePluginTcpCommander::executeAction(Device *devic
|
||||
int port = device->paramValue(portParamTypeId).toInt();
|
||||
QHostAddress address= QHostAddress(device->paramValue(ipv4addressParamTypeId).toString());
|
||||
QTcpSocket *tcpSocket = m_tcpSockets.key(device);
|
||||
QByteArray data = device->paramValue(outputDataAreaParamTypeId).toByteArray();
|
||||
tcpSocket->connectToHost(address, port);
|
||||
tcpSocket->write(data);
|
||||
tcpSocket->close();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
@ -80,8 +81,13 @@ DeviceManager::DeviceError DevicePluginTcpCommander::executeAction(Device *devic
|
||||
void DevicePluginTcpCommander::deviceRemoved(Device *device)
|
||||
{
|
||||
if(device->deviceClassId() == tcpOutputDeviceClassId){
|
||||
m_tcpSockets.remove(m_tcpSockets.key(device));
|
||||
|
||||
QTcpSocket *tcpSocket = m_tcpSockets.key(device);
|
||||
m_tcpSockets.remove(tcpSocket);
|
||||
tcpSocket->deleteLater();
|
||||
|
||||
}else if(device->deviceClassId() == tcpInputDeviceClassId){
|
||||
|
||||
TcpServer *tcpServer = m_tcpServer.key(device);
|
||||
m_tcpServer.remove(tcpServer);
|
||||
tcpServer->deleteLater();
|
||||
@ -89,12 +95,42 @@ void DevicePluginTcpCommander::deviceRemoved(Device *device)
|
||||
}
|
||||
|
||||
|
||||
void DevicePluginTcpCommander::onTcpSocketConnected()
|
||||
{
|
||||
QTcpSocket *tcpSocket = static_cast<QTcpSocket *>(sender());
|
||||
Device *device = m_tcpSockets.value(tcpSocket);
|
||||
if (!device->setupComplete()) {
|
||||
qDebug(dcTCPCommander()) << device->name() << "Setup finished" ;
|
||||
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess);
|
||||
} else {
|
||||
QByteArray data = device->paramValue(outputDataAreaParamTypeId).toByteArray();
|
||||
tcpSocket->write(data);
|
||||
}
|
||||
device->setStateValue(connectedStateTypeId, true);
|
||||
}
|
||||
|
||||
|
||||
void DevicePluginTcpCommander::onTcpSocketDisconnected()
|
||||
{
|
||||
QTcpSocket *tcpSocket = static_cast<QTcpSocket *>(sender());
|
||||
Device *device = m_tcpSockets.value(tcpSocket);
|
||||
device->setStateValue(connectedStateTypeId, false);
|
||||
}
|
||||
|
||||
|
||||
void DevicePluginTcpCommander::onTcpSocketBytesWritten()
|
||||
{
|
||||
QTcpSocket *tcpSocket = static_cast<QTcpSocket *>(sender());
|
||||
tcpSocket->close();
|
||||
}
|
||||
|
||||
void DevicePluginTcpCommander::onTcpServerConnected()
|
||||
{
|
||||
TcpServer *tcpServer = static_cast<TcpServer *>(sender());
|
||||
Device *device = m_tcpServer.value(tcpServer);
|
||||
qDebug(dcTCPCommander()) << device->name() << "Tcp Server Client connected" ;
|
||||
device->setStateValue(connectedStateTypeId, true);
|
||||
|
||||
connect(tcpServer, &TcpServer::textMessageReceived, this, &DevicePluginTcpCommander::onTcpServerTextMessageReceived);
|
||||
//send signal device Setup was successfull
|
||||
}
|
||||
@ -113,7 +149,7 @@ void DevicePluginTcpCommander::onTcpServerTextMessageReceived(QByteArray data)
|
||||
TcpServer *tcpServer = static_cast<TcpServer *>(sender());
|
||||
Device *device = m_tcpServer.value(tcpServer);
|
||||
qDebug(dcTCPCommander()) << device->name() << "Message received" << data;
|
||||
device->setStateValue(responseStateTypeId, data); //TODO change wording
|
||||
device->setStateValue(dataReceivedStateTypeId, data);
|
||||
|
||||
if (device->paramValue(comparisionParamTypeId).toString() == "Is exactly") {
|
||||
qDebug(dcTCPCommander()) << "is exacly";
|
||||
|
||||
@ -47,6 +47,10 @@ private:
|
||||
QHash<TcpServer *, Device *> m_tcpServer;
|
||||
|
||||
private slots:
|
||||
void onTcpSocketConnected();
|
||||
void onTcpSocketDisconnected();
|
||||
void onTcpSocketBytesWritten();
|
||||
|
||||
void onTcpServerConnected();
|
||||
void onTcpServerDisconnected();
|
||||
void onTcpServerTextMessageReceived(QByteArray message);
|
||||
|
||||
@ -105,7 +105,7 @@
|
||||
{
|
||||
"id": "23051bdf-3f50-41fa-abde-bc4fe0bcc4fc",
|
||||
"idName": "inputData",
|
||||
"name": "Data",
|
||||
"name": "Command",
|
||||
"type": "QString",
|
||||
"inputType": "TextArea",
|
||||
"defaultValue": "",
|
||||
@ -124,12 +124,12 @@
|
||||
},
|
||||
{
|
||||
"id": "b98fdacc-59d7-41c4-b790-1fdca50dfb22",
|
||||
"idName": "response",
|
||||
"name": "Response",
|
||||
"idName": "dataReceived",
|
||||
"name": "Data Received",
|
||||
"type": "QString",
|
||||
"inputType": "TextArea",
|
||||
"defaultValue": "",
|
||||
"eventTypeName": "response received",
|
||||
"eventTypeName": "Data received",
|
||||
"index" : 1
|
||||
}
|
||||
],
|
||||
|
||||
@ -53,11 +53,8 @@
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="65"/>
|
||||
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="74"/>
|
||||
<source>Data</source>
|
||||
<extracomment>The name of the paramType (6604c852-6b24-4707-b8e5-1ddd8032efcc) of TCP Output
|
||||
----------
|
||||
The name of the paramType (23051bdf-3f50-41fa-abde-bc4fe0bcc4fc) of TCP Input</extracomment>
|
||||
<extracomment>The name of the paramType (6604c852-6b24-4707-b8e5-1ddd8032efcc) of TCP Output</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
@ -72,15 +69,21 @@ The name of the paramType (23051bdf-3f50-41fa-abde-bc4fe0bcc4fc) of TCP Input</e
|
||||
<extracomment>The name of the paramType (d99f55c7-0e14-45ee-b0f0-33f2d1d2e674) of TCP Input</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="74"/>
|
||||
<source>Command</source>
|
||||
<extracomment>The name of the paramType (23051bdf-3f50-41fa-abde-bc4fe0bcc4fc) of TCP Input</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="77"/>
|
||||
<source>response received</source>
|
||||
<source>Data received</source>
|
||||
<extracomment>The name of the autocreated EventType (b98fdacc-59d7-41c4-b790-1fdca50dfb22)</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="80"/>
|
||||
<source>Response</source>
|
||||
<source>Data Received</source>
|
||||
<extracomment>The name of the ParamType of StateType (b98fdacc-59d7-41c4-b790-1fdca50dfb22) of DeviceClass TCP Input</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
||||
@ -53,11 +53,8 @@
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="65"/>
|
||||
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="74"/>
|
||||
<source>Data</source>
|
||||
<extracomment>The name of the paramType (6604c852-6b24-4707-b8e5-1ddd8032efcc) of TCP Output
|
||||
----------
|
||||
The name of the paramType (23051bdf-3f50-41fa-abde-bc4fe0bcc4fc) of TCP Input</extracomment>
|
||||
<extracomment>The name of the paramType (6604c852-6b24-4707-b8e5-1ddd8032efcc) of TCP Output</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
@ -72,15 +69,21 @@ The name of the paramType (23051bdf-3f50-41fa-abde-bc4fe0bcc4fc) of TCP Input</e
|
||||
<extracomment>The name of the paramType (d99f55c7-0e14-45ee-b0f0-33f2d1d2e674) of TCP Input</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="74"/>
|
||||
<source>Command</source>
|
||||
<extracomment>The name of the paramType (23051bdf-3f50-41fa-abde-bc4fe0bcc4fc) of TCP Input</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="77"/>
|
||||
<source>response received</source>
|
||||
<source>Data received</source>
|
||||
<extracomment>The name of the autocreated EventType (b98fdacc-59d7-41c4-b790-1fdca50dfb22)</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="80"/>
|
||||
<source>Response</source>
|
||||
<source>Data Received</source>
|
||||
<extracomment>The name of the ParamType of StateType (b98fdacc-59d7-41c4-b790-1fdca50dfb22) of DeviceClass TCP Input</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user