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#include <mutex>
14
16
17class CommunicationHandler : public QLocalServer {
18 Q_OBJECT
21public:
22 CommunicationHandler(SubprocessManager* _manager, const std::string& _serverName);
24
25 bool sendToClient(const ot::JsonDocument& _document, std::string& _response);
26
27 void setModelUrl(const std::string& _url) { m_modelUrl = _url; m_modelUrlSet = false; };
28 void setFrontendUrl(const std::string& _url) { m_frontendUrl = _url; m_frontendUrlSet = false; };
29 void setDataBaseInfo(const DataBaseInfo& _info) { m_databaseInfo = _info; m_databaseInfoSet = false; };
30
31 const std::string& getServerName(void) const { return m_serverName; };
32
33 bool sendConfigToClient(void);
34
35 void cleanupAfterCrash(void);
36
37private Q_SLOTS:
38 void slotNewConnection(void);
39 void slotMessageReceived(void);
40 void slotClientDisconnected(void);
41 void slotProcessMessage(std::string _message);
42
43private:
44 enum class ClientState {
45 Disconnected,
46 WaitForPing,
47 Ready,
48 WaitForResponse,
49 ReponseReceived
50 };
51
52 void processNextEvent(void);
53
54 bool sendServiceInfoToClient(void);
55 bool sendModelConfigToClient(void);
56 bool sendFrontendConfigToClient(void);
57 bool sendDataBaseConfigToClient(void);
58
59 ClientState getClientState();
60 void setClientState(ClientState _clientState);
61
63 bool waitForClient(void);
64
66 bool sendToClient(const QByteArray& _data, bool _expectResponse, std::string& _response);
67
68 SubprocessManager* m_manager;
69 std::string m_serverName;
70
71 QLocalSocket* m_client;
72 ClientState m_clientState; //State is accessed by two threads, use the threadsafe getter and setter
73 std::mutex m_clientStateMutex;
74
75 bool m_isInitializingClient;
76
77 bool m_serviceAndSessionInfoSet;
78
79 std::string m_frontendUrl;
80 bool m_frontendUrlSet;
81
82 std::string m_modelUrl;
83 bool m_modelUrlSet;
84
85 DataBaseInfo m_databaseInfo;
86 bool m_databaseInfoSet;
87
88 std::string m_response;
89
90};
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:29
void setModelUrl(const std::string &_url)
Definition CommunicationHandler.h:27
bool sendToClient(const ot::JsonDocument &_document, std::string &_response)
Definition CommunicationHandler.cpp:31
const std::string & getServerName(void) const
Definition CommunicationHandler.h:31
void cleanupAfterCrash(void)
Definition CommunicationHandler.cpp:67
CommunicationHandler()
Definition CommunicationHandler.cpp:16
void setFrontendUrl(const std::string &_url)
Definition CommunicationHandler.h:28
bool sendConfigToClient(void)
Definition CommunicationHandler.cpp:41
Definition DataBaseInfo.h:6
Definition SubprocessManager.h:19
JSON document.
Definition JSON.h:276