OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
CommunicationHandler.h
Go to the documentation of this file.
1#pragma once
2
3// Service header
4#include "DataBaseInfo.h"
5
6// OpenTwin header
7#include "OTCore/JSON.h"
8#include "OTCore/Flags.h"
10
11// Qt header
12#include <QtNetwork/qlocalserver.h>
13
15
16class CommunicationHandler : public QLocalServer {
17 Q_OBJECT
20public:
21 CommunicationHandler(SubprocessManager* _manager, const std::string& _serverName);
23
24 bool sendToClient(const ot::JsonDocument& _document, std::string& _response);
25
26 void setModelUrl(const std::string& _url) { m_modelUrl = _url; m_modelUrlSet = false; };
27 void setFrontendUrl(const std::string& _url) { m_frontendUrl = _url; m_frontendUrlSet = false; };
28 void setDataBaseInfo(const DataBaseInfo& _info) { m_databaseInfo = _info; m_databaseInfoSet = false; };
29
30 const std::string& getServerName(void) const { return m_serverName; };
31
32 bool sendConfigToClient(void);
33
34 void cleanupAfterCrash(void);
35
36private Q_SLOTS:
37 void slotNewConnection(void);
38 void slotMessageReceived(void);
39 void slotClientDisconnected(void);
40 void slotProcessMessage(std::string _message);
41
42private:
43 enum class ClientState {
44 Disconnected,
45 WaitForPing,
46 Ready,
47 WaitForResponse,
48 ReponseReceived
49 };
50
51 void processNextEvent(void);
52
53 bool sendServiceInfoToClient(void);
54 bool sendModelConfigToClient(void);
55 bool sendFrontendConfigToClient(void);
56 bool sendDataBaseConfigToClient(void);
57
58 bool waitForClient(void);
59 bool sendToClient(const QByteArray& _data, bool _expectResponse, std::string& _response);
60
61 SubprocessManager* m_manager;
62 std::string m_serverName;
63
64 QLocalSocket* m_client;
65 ClientState m_clientState;
66 bool m_isInitializingClient;
67
68 bool m_serviceAndSessionInfoSet;
69
70 std::string m_frontendUrl;
71 bool m_frontendUrlSet;
72
73 std::string m_modelUrl;
74 bool m_modelUrlSet;
75
76 DataBaseInfo m_databaseInfo;
77 bool m_databaseInfoSet;
78
79 std::string m_response;
80
81};
This file contains defines that may be used simplyfy class creation.
#define OT_DECL_NODEFAULT(___class)
Removes the default copy constructor and assignment operator.
Definition OTClassHelper.h:22
#define OT_DECL_NOCOPY(___class)
Removes the default copy constructor and assignment operator.
Definition OTClassHelper.h:14
Definition CommunicationHandler.h:11
void setDataBaseInfo(const DataBaseInfo &_info)
Definition CommunicationHandler.h:28
void setModelUrl(const std::string &_url)
Definition CommunicationHandler.h:26
bool sendToClient(const ot::JsonDocument &_document, std::string &_response)
Definition CommunicationHandler.cpp:31
const std::string & getServerName(void) const
Definition CommunicationHandler.h:30
void cleanupAfterCrash(void)
Definition CommunicationHandler.cpp:63
CommunicationHandler()
Definition CommunicationHandler.cpp:16
void setFrontendUrl(const std::string &_url)
Definition CommunicationHandler.h:27
bool sendConfigToClient(void)
Definition CommunicationHandler.cpp:41
Definition DataBaseInfo.h:6
Definition SubprocessManager.h:19
JSON document.
Definition JSON.h:276