ImagingTools Core SDK
CUdpServerComp.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 <QtNetwork/QUdpSocket>
7#include <QtNetwork/QNetworkDatagram>
8
9// ACF includes
10#include <istd/TPointerVector.h>
11#include <ibase/TRuntimeStatusHanderCompWrap.h>
12#include <ilog/TLoggerCompWrap.h>
13#include <istd/TDelPtr.h>
14#include <iprm/IParamsSet.h>
15#include <ifile/IFileNameParam.h>
16#include <imod/CMultiModelDispatcherBase.h>
17
18// ImtCore includes
19#include <imtcom/IServerConnectionInterface.h>
20#include <imtrest/IRequest.h>
21#include <imtrest/IRequestServlet.h>
22#include <imtrest/IProtocolEngine.h>
23#include <imtrest/IResponseDispatcher.h>
24#include <imtrest/IServer.h>
25#include <imtrest/CUdpRequest.h>
26
27namespace imtrest
28{
29
30
36 public QObject,
37 public ibase::TRuntimeStatusHanderCompWrap<ilog::CLoggerComponentBase>,
38 private imod::CMultiModelDispatcherBase,
39 virtual public IResponseDispatcher,
40 virtual public IServer
41{
42 Q_OBJECT
43public:
44 typedef ibase::TRuntimeStatusHanderCompWrap<ilog::CLoggerComponentBase> BaseClass;
45 typedef imod::CMultiModelDispatcherBase BaseClass2;
46
47 I_BEGIN_COMPONENT(CUdpServerComp);
48 I_REGISTER_INTERFACE(IResponseDispatcher)
49 I_REGISTER_INTERFACE(IServer)
50 I_ASSIGN(m_requestHandlerCompPtr, "RequestHandler", "Request handler registered for the server", true, "RequestHandler");
51 I_ASSIGN(m_protocolEngineCompPtr, "ProtocolEngine", "Protocol engine used in the server", true, "ProtocolEngine");
52 I_ASSIGN(m_startServerOnCreateAttrPtr, "StartServerOnCreate", "If enabled, the server will be started on after component creation", true, true);
53 I_ASSIGN(m_serverConnnectionInterfaceCompPtr, "ServerInterface", "Parameter providing the server connection interface to be listened", true, "ServerInterface");
54 I_END_COMPONENT
55
58
59 imtrest::IRequestServlet* GetRequestServlet();
60 int GetThreadsLimit();
61
62protected:
63 // reimplemented (imod::CMultiModelDispatcherBase)
64 virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet& changeSet) override;
65
66 // reimplemented (ibase::TRuntimeStatusHanderCompWrap)
67 virtual void OnSystemShutdown() override;
68
69 // reimplemented (icomp::CComponentBase)
70 virtual void OnComponentCreated() override;
71
72 // reimplemented (imtrest::IResponseDispatcher)
73 virtual bool SendResponse(const QByteArray& requestId, ConstResponsePtr& response) const override;
74 virtual bool SendRequest(const QByteArray& requestId, ConstRequestPtr& request) const override;
75
76 // reimplemented (imtrest::IServer)
77 virtual bool StartServer() override;
78 virtual bool StopServer() override;
79 virtual ServerStatus GetServerStatus() const override;
80
81private:
82 bool StartListening(const QHostAddress& address = QHostAddress::Any, quint16 port = 0);
83 bool EnsureServerStarted();
84
85private Q_SLOTS:
86 void ReadPendingDatagrams();
87 void SendedResponse(QByteArray);
88
89private:
90 I_REF(imtrest::IRequestServlet, m_requestHandlerCompPtr);
91 I_REF(IProtocolEngine, m_protocolEngineCompPtr);
92 I_REF(imtcom::IServerConnectionInterface, m_serverConnnectionInterfaceCompPtr);
93
94 I_ATTR(bool, m_startServerOnCreateAttrPtr);
95
96 QUdpSocket m_udpSocket;
97
98 typedef istd::TPointerVector<CUdpRequest> Requests;
99 Requests m_requests;
100
101 bool m_isInitialized = false;
102};
103
104
105} // namespace imtrest
106
107
Interface for describing server connection configuration with multi-protocol support.