#include <QDebug>
#include <QSystemSemaphore>
#include <QThread>
#include "handlelocalmessage.h"
HandleLocalMessage::HandleLocalMessage(IniFile* i, QObject *parent) :
HandleMessage(i, parent),
socket(this),
toTimer(this),
conn(false) {
interval = 30000;
toTimer.setSingleShot(true);
toTimer.setInterval(ini->integer("GLOBALSERVER","TIMEOUT",5)*1000);
connect(&socket , SIGNAL(connected()) , this, SLOT(connected()) );
connect(&socket , SIGNAL(readyRead()) , this, SLOT(readyRead()) );
connect(&socket , SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)) );
connect(&socket , SIGNAL(disconnected()) , this, SLOT(checkEnd()) );
connect(&toTimer, SIGNAL(timeout()) , this, SLOT(timeout()) );
connect(this , SIGNAL(stopTimer()) , &toTimer, SLOT(stop()) );
}
HandleLocalMessage::~HandleLocalMessage() {
}
void HandleLocalMessage:: processMessage() {
socket.connectToHost("host", 5000, QIODevice::ReadWrite);
toTimer.start();
} else {
endProcess();
}
}
void HandleLocalMessage::endProcess() {
emit log(LogFile:: Debug,"HandleLocalMessage: endProcess: End Process called");
if (toend) {
...
} else {
timer->start();
}
}
void HandleLocalMessage::writeList() {
....
}
void HandleLocalMessage::errorHandling() {
....
}
void HandleLocalMessage::connected() {
conn = true;
socket.write(transArray+"### End of Message ###");
}
void HandleLocalMessage::error(QAbstractSocket::SocketE rror socketError) {
// Q_UNUSED(socketError);
emit log(LogFile:: Debug,"Error during communication with global server: "+QString().setNum(socketError));
toTimer.stop();
emit log(LogFile:: Debug,"Timeout-Timer with Id "+QString().setNum(toTimer.timerId())+" active after stop: "+QString(toTimer.isActive() ? "YES" : "NO"));
errorHandling();
socket.close();
socket.disconnectFromHost();
}
void HandleLocalMessage::timeout() {
emit log(LogFile:: Debug,"Timeout during communication with global server. Timeout-Timer Id: "+QString().setNum(toTimer.timerId()));
errorHandling();
socket.close();
if (conn) {
socket.disconnectFromHost();
} else {
checkEnd();
}
}
void HandleLocalMessage::readyRead() {
toTimer.stop();
QByteArray res(socket.readAll());
if (!(res == QByteArray("OK"))) {
errorHandling();
}
socket.close();
socket.disconnectFromHost();
}
void HandleLocalMessage::checkEnd() {
endProcess();
}
Bookmarks