-
Notifications
You must be signed in to change notification settings - Fork 1
/
msgserverthread.cpp
71 lines (61 loc) · 1.99 KB
/
msgserverthread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* @class SCDMsgServerThread - https://github.com/SC-Develop/SCD_MC
*
* @author Ing. Salvatore Cerami - dev.salvatore.cerami@gmail.com - https://github.com/SC-Develop/
*
* @brief Message Center Server Thread Managent
*
* This is a part of SCD Message Center QT Class Library
*
* This is the Message Center Server Thread Management of a realtime messaging/commands system for exchange of
* inter-process messages/commands based on Tcp Socket
*
* This file must be distribuited with files:
*
* - msgcenter.cpp,
* - msgcenter.h,
* - msgserver.h,
* - msgserver.cpp,
* - msgthreadhandler.h
* - msgthreadhandler.cpp
*
*/
#include "QObject"
#include "msgserverthread.h"
#include "msgserver.h"
#include "msgthreadhandler.h"
/**
* @brief SCDMsgServerThread::SCDMsgServerThread
* @param Id
* @param parent
*/
SCDMsgServerThread::SCDMsgServerThread(int socketDescriptor, SCDMsgCenter *mc, QObject *parent) :
QThread(parent), SocketDescriptor(socketDescriptor), mc(mc)
{
}
/**
* @brief SCDMsgServerThread::~SCDMsgServerThread
*/
SCDMsgServerThread::~SCDMsgServerThread()
{
}
/**
* @brief SCDMsgServerThread::run starts remote client connection thread
*/
void SCDMsgServerThread::run()
{
SCDMsgThreadHandler *tev = new SCDMsgThreadHandler(SocketDescriptor, mc); // Thread handler class live into thread
if (tev->start()) // start socket connection and set the socket signal handler slot
{
if (mc)
{
mc->addClient(SocketDescriptor); // register client to message center. client can receive message from application message senders
}
exec(); // start thared event loop e do not return until quit or exit is not called (on socket disconnect, exits from event loop)
if (mc) // remove client from message center client list
{
mc->removeClient(SocketDescriptor);
}
}
delete tev; // delete thread event loop object and associated socket
}