ImagingTools Core SDK
CMultiThreadServer.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QReadWriteLock>
7
8#if QT_VERSION >= 0x060400
9#include <QtNetwork/QSslServer>
10#endif
11#include <QtNetwork/QSslConfiguration>
12
13// ImtCore includes
14#include <imtrest/CTcpServerComp.h>
15#include <imtrest/IResponseDispatcher.h>
16#include <imtrest/CSocketThread.h>
17
18
19namespace imtrest
20{
21
22
23class CMultiThreadServer :
24#if QT_VERSION >= 0x060400
25 public QSslServer,
26#else
27 public QTcpServer,
28#endif
29 virtual public ilog::CLoggerBase,
30 virtual public IResponseDispatcher
31{
32 Q_OBJECT
33public:
34#if QT_VERSION >= 0x060400
35 typedef QSslServer BaseClass;
36#else
37 typedef QTcpServer BaseClass;
38#endif
39 typedef ilog::CLoggerBase BaseClass2;
40
41 explicit CMultiThreadServer(CTcpServerComp* rootServer);
42 virtual ~CMultiThreadServer();
43
44 imtrest::IRequestServlet* GetRequestServlet();
45 imtrest::IProtocolEngine* GetProtocolEngine();
46
47 [[nodiscard]] bool IsSecureConnection() const;
48 void EnableSecureConnection(bool isSecureConnection = true);
49
57 void SetSslConfiguration(const QSslConfiguration& sslConfiguration);
58
59 // reimplemented (imtrest::IResponseDispatcher)
60 virtual bool SendResponse(const QByteArray& requestId, ConstResponsePtr& response) const override;
61 virtual bool SendRequest(const QByteArray& requestId, ConstRequestPtr& request) const override;
62
63Q_SIGNALS:
64 void NewThreadConnection(const IRequest* request, const QByteArray& subCommandId);
65
66public Q_SLOTS:
67 void Disconnected(QByteArray requestId);
68
69protected Q_SLOTS:
70 void ShutdownServer();
71
72protected:
73 void AddSocketDescriptor(qintptr socketDescriptor);
74 qintptr PopSocketDescriptor();
75
76 // reimplemented (QTcpServer)
77 virtual void incomingConnection(qintptr socketDescriptor) override;
78
79protected:
80 QList<QPointer<CSocketThread>> m_threadSocketList;
81 CTcpServerComp& m_rootServer;
82 mutable QList<qintptr> m_descriptorList;
83 mutable QMutex m_descriptorListMutex;
84 mutable QReadWriteLock m_threadSocketListGuard;
85 bool m_isActive;
86 bool m_isSecureConnection;
87 QSslConfiguration m_sslConfiguration;
88};
89
90
91} // namespace imtrest
92
93