OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
ApplicationBase.h
Go to the documentation of this file.
1
5// ###########################################################################################################################################################################################################################################################################################################################
6
7#pragma once
8#pragma warning(disable : 4251)
9
10// OpenTwin header
11#include "OTCore/JSON.h"
12#include "OTCore/CoreTypes.h"
13#include "OTCore/ServiceBase.h"
19#include "EntityInformation.h"
20
21#include "ClassFactory.h"
22
23// std header
24#include <list>
25#include <map>
26#include <string>
27
28namespace ot {
29
30 namespace components {
31 class UiComponent;
32 class ModelComponent;
33 }
34
35 namespace intern {
37 }
38
39 class ModalCommandBase;
40 class AbstractUiNotifier;
41 class AbstractSettingsItem;
42 class AbstractModelNotifier;
43
45 {
47 public:
48 ApplicationBase(const std::string & _serviceName, const std::string & _serviceType, AbstractUiNotifier * _uiNotifier = nullptr, AbstractModelNotifier * _modelNotifier = nullptr);
49 virtual ~ApplicationBase();
50
51 // ##########################################################################################################################################
52
53 // Pure virtual functions
54
56 virtual void run(void) = 0;
57
61 virtual std::string processAction(const std::string & _action, JsonDocument& _doc) = 0;
62
67 virtual std::string processMessage(ServiceBase * _sender, const std::string & _message, JsonDocument& _doc) = 0;
68
70 virtual void uiConnected(components::UiComponent * _ui) = 0;
71
73 virtual void uiDisconnected(const components::UiComponent * _serviceInfo) = 0;
74
76 virtual void modelConnected(components::ModelComponent * _model) = 0;
77
79 virtual void modelDisconnected(const components::ModelComponent * _serviceInfo) = 0;
80
83 virtual void serviceConnected(ServiceBase * _service) = 0;
84
87 virtual void serviceDisconnected(const ServiceBase * _service) = 0;
88
91 virtual void preShutdown(void) = 0;
92
96 virtual void shuttingDown(void) = 0;
97
99 virtual bool startAsRelayService(void) const = 0;
100
105 virtual PropertyGridCfg createSettings(void) const = 0;
106
110 virtual void settingsSynchronized(const PropertyGridCfg& _config) = 0;
111
117 virtual bool settingChanged(const Property* _property) = 0;
118
121 virtual std::string deploymentPath(void) const;
122
123 virtual void modelSelectionChanged(void) {};
124
125 // ####################################################################################################################################################################################################################################################################################
126
127 // Setter
128
131 void setDataBaseURL(const std::string & _url) { m_databaseURL = _url; }
132
135 void setSiteID(const std::string & _id) { m_siteID = _id; }
136
139 void setWebSocketURL(const std::string & _url) { m_websocketURL = _url; }
140
143 void setDirectoryServiceURL(const std::string& _url);
144
147 void setSessionServiceURL(const std::string & _url);
148
151 void setSessionID(const std::string & _id);
152
154 void setProjectType(const std::string& _type) { m_projectType = _type; };
155
156 // ##########################################################################################################################################
157
158 // Getter
159
160 //void refreshSessionServiceList(void);
161
163 std::string dataBaseURL(void) { return m_databaseURL; }
164
166 std::string siteID(void) { return m_siteID; }
167
169 std::string webSocketURL(void) { return m_websocketURL; }
170
172 std::string sessionServiceURL(void) { return m_sessionService.service->getServiceURL(); }
173
175 std::string directoryServiceURL(void) { return m_directoryService.service->getServiceURL(); }
176
178 std::string sessionID(void) { return m_sessionID; }
179
181 const std::string& projectType(void) const { return m_projectType; };
182
183 const std::string& getCollectionName() const { return m_collectionName; }
184
186 bool isUiConnected(void) const { return m_uiComponent != nullptr; }
187
189 bool isModelConnected(void) const { return m_modelComponent != nullptr; }
190
193 components::ModelComponent * modelComponent(void) const { return m_modelComponent; }
194
197 components::UiComponent * uiComponent(void) const { return m_uiComponent; }
198
201 ServiceBase * getConnectedServiceByID(serviceID_t _id);
202
205 ServiceBase * getConnectedServiceByName(const std::string & _name);
206
208 AbstractUiNotifier * uiNotifier(void) { return m_uiNotifier; }
209
211 AbstractModelNotifier * modelNotifier(void) { return m_modelNotifier; }
212
214 ClassFactory& getClassFactory(void) { return classFactory; }
215
216
217 // ##########################################################################################################################################
218
219 // Modal Commands
220
221 void addModalCommand(ModalCommandBase *command);
222 void removeModalCommand(ModalCommandBase *command);
223 std::string processActionWithModalCommands(const std::string & _action, JsonDocument& _doc);
224
225 // ##########################################################################################################################################
226
227 // IO
228
233 void enableMessageQueuing(const std::string & _serviceName, bool _flag);
234
237 void flushQueuedHttpRequests(const std::string & _serviceName);
238
244 bool sendMessage(bool _queue, const std::string & _serviceName, const JsonDocument& _doc, std::string& _response);
245
252 bool sendMessage(bool _queue, const std::string & _serviceName, const JsonDocument& _doc, std::list<std::pair<UID, UID>> & _prefetchIds, std::string& _response);
253
257 bool broadcastMessage(bool _queue, const std::string& _message);
258
262 bool broadcastMessage(bool _queue, const JsonDocument& _doc);
263
264 void prefetchDocumentsFromStorage(const std::list<UID> &entities);
265 void prefetchDocumentsFromStorage(const std::list<ot::EntityInformation> &entityInfo);
266 UID getPrefetchedEntityVersion(UID entityID);
267
268
269 std::string getLogInUserName() const;
270 std::string getLogInUserPsw() const;
271
272 // ##########################################################################################################################################
273 protected:
274
275 bool EnsureDataBaseConnection(void);
276
277 bool storeSettingToDataBase(const PropertyGridCfg& _config, const std::string& _databaseURL, const std::string& _siteID, const std::string& _userName, const std::string& _userPassword, const std::string& _userCollection);
278
279 PropertyGridCfg getSettingsFromDataBase(const std::string& _databaseURL, const std::string& _siteID, const std::string& _userName, const std::string& _userPassword, const std::string& _userCollection);
280
281 // ##########################################################################################################################################
282
283 // Member
284
286
292
293 std::map<std::string, structServiceInformation> m_serviceNameMap;
294
295 std::map<serviceID_t, structServiceInformation> m_serviceIdMap;
296
303
304 std::string m_databaseURL;
305 std::string m_siteID;
306 std::string m_websocketURL;
307
308 std::string m_sessionID;
309 std::string m_projectName;
310 std::string m_collectionName;
311 std::string m_projectType;
312
313 std::list<ot::ModalCommandBase *> m_modalCommands;
314
315 std::list<UID> m_selectedEntities;
316
317 std::map<UID, UID> m_prefetchedEntityVersions;
318
319 void __serviceConnected(const std::string& _name, const std::string& _type, const std::string& _url, serviceID_t _id);
320
321 private:
323
326
327 void __serviceDisconnected(const std::string & _name, const std::string & _type, const std::string & _url, serviceID_t _id);
328 std::string __processMessage(const std::string & _message, JsonDocument&doc, serviceID_t _senderID);
329 void __shuttingDown(bool _requestedAsCommand);
330
331 std::string m_DBuserCollection;
332 ClassFactory classFactory;
333
334 ApplicationBase() = delete;
335 };
336
337}
#define OT_HANDLER(___functionName, ___className, ___actionName, ___messageTypeFlags)
Creates a function that will be registered in the dispatch system. The generated function will look l...
Definition ActionHandleConnector.h:26
#define OT_ACTION_CMD_KeySequenceActivated
Definition ActionTypes.h:81
#define OT_ACTION_CMD_UI_SettingsItemChanged
Definition ActionTypes.h:169
#define OT_SERVICEFOUNDATION_API_EXPORT
Definition FoundationAPIExport.h:7
#define OT_DECL_NOCOPY(___class)
Removes the default copy constructor and assignment operator.
Definition OTClassHelper.h:14
Definition ExternalServicesComponent.h:62
Definition AbstractModelNotifier.h:11
Definition AbstractUiNotifier.h:11
Definition ActionHandler.h:14
Definition ApplicationBase.h:45
virtual void settingsSynchronized(const PropertyGridCfg &_config)=0
This function will be called when the settings were synchronized with the database....
std::string webSocketURL(void)
Will return the websocket URL, it is only set if a websocket was required on startup: startAsRelaySer...
Definition ApplicationBase.h:169
virtual void run(void)=0
Will be called when the service was successfully started, the hppt and/or websocket connection is est...
std::string m_collectionName
Definition ApplicationBase.h:310
virtual void shuttingDown(void)=0
Will be called when the application is shutting down (shut down can not be stopped) At this point all...
std::map< std::string, structServiceInformation > m_serviceNameMap
Definition ApplicationBase.h:293
virtual void modelDisconnected(const components::ModelComponent *_serviceInfo)=0
Will be called when a mode service disconnected from the session (is already closed)
structServiceInformation m_sessionService
Definition ApplicationBase.h:297
virtual bool startAsRelayService(void) const =0
Will return true if this application requires a relay service for a websocket connection.
virtual void preShutdown(void)=0
Will be called before the whole session starts to shut down (shut down can not be stopped) At this po...
const std::string & getCollectionName() const
Definition ApplicationBase.h:183
ClassFactory & getClassFactory(void)
Returns a handle to the global class factory for the service.
Definition ApplicationBase.h:214
void setDataBaseURL(const std::string &_url)
Will set the database URL of the database this application is using.
Definition ApplicationBase.h:131
std::string m_databaseURL
Definition ApplicationBase.h:304
std::string m_projectName
Definition ApplicationBase.h:309
components::UiComponent * uiComponent(void) const
Will return the ui component used in this application The UI component only exists when a ui service ...
Definition ApplicationBase.h:197
virtual void uiDisconnected(const components::UiComponent *_serviceInfo)=0
Will be called when a UI disconnected from the session (is already closed)
components::UiComponent * m_uiComponent
Definition ApplicationBase.h:300
virtual std::string processMessage(ServiceBase *_sender, const std::string &_message, JsonDocument &_doc)=0
Will be called whenever a message should be processed. Core messages will be processed in the base an...
virtual void modelSelectionChanged(void)
Definition ApplicationBase.h:123
bool m_uiMessageQueuingEnabled
Definition ApplicationBase.h:285
std::string dataBaseURL(void)
Will return the URL of the database.
Definition ApplicationBase.h:163
virtual void serviceDisconnected(const ServiceBase *_service)=0
Will be called when a service is disconnected from the session (is already closed) (UI and model serv...
bool isModelConnected(void) const
Will return true if a model service is running in the session.
Definition ApplicationBase.h:189
const std::string & projectType(void) const
The current project type.
Definition ApplicationBase.h:181
components::ModelComponent * modelComponent(void) const
Will return the model component used in this application The model component only exists when a model...
Definition ApplicationBase.h:193
virtual PropertyGridCfg createSettings(void) const =0
Create settings that your application uses that are editable in the uiService. The created class will...
bool isUiConnected(void) const
Will return true if a UI is running in the session.
Definition ApplicationBase.h:186
virtual void modelConnected(components::ModelComponent *_model)=0
Will be called when a model service connected to the session and is ready to work.
virtual void uiConnected(components::UiComponent *_ui)=0
Will be called when a UI connected to the session and is ready to work.
void setSiteID(const std::string &_id)
Will set the site ID this application is running on.
Definition ApplicationBase.h:135
virtual void serviceConnected(ServiceBase *_service)=0
Will be called when a service is connected to the session (UI and model services will not trigger thi...
std::list< ot::ModalCommandBase * > m_modalCommands
Definition ApplicationBase.h:313
std::string m_siteID
Definition ApplicationBase.h:305
components::ModelComponent * m_modelComponent
Definition ApplicationBase.h:299
std::string m_websocketURL
Definition ApplicationBase.h:306
std::string m_projectType
Definition ApplicationBase.h:311
virtual std::string processAction(const std::string &_action, JsonDocument &_doc)=0
Will be called whenever a action should be processed. Core actions will be processed in the base and ...
std::string directoryServiceURL(void)
Will return the local directory service URL.
Definition ApplicationBase.h:175
std::list< UID > m_selectedEntities
Definition ApplicationBase.h:315
std::map< UID, UID > m_prefetchedEntityVersions
Definition ApplicationBase.h:317
void setWebSocketURL(const std::string &_url)
Will set the websocket URL that this application is connected to (only required if socket connection ...
Definition ApplicationBase.h:139
std::string m_sessionID
Definition ApplicationBase.h:308
AbstractModelNotifier * m_modelNotifier
Definition ApplicationBase.h:302
AbstractUiNotifier * m_uiNotifier
Definition ApplicationBase.h:301
std::string siteID(void)
Will return the site ID this application is running on.
Definition ApplicationBase.h:166
AbstractModelNotifier * modelNotifier(void)
Will return the modelNotifier attached to this application.
Definition ApplicationBase.h:211
AbstractUiNotifier * uiNotifier(void)
Will return the uiNotifier attached to this application.
Definition ApplicationBase.h:208
structServiceInformation m_directoryService
Definition ApplicationBase.h:298
std::string sessionID(void)
Will return the session ID this service is running in.
Definition ApplicationBase.h:178
std::string sessionServiceURL(void)
Will return the session service URL.
Definition ApplicationBase.h:172
std::map< serviceID_t, structServiceInformation > m_serviceIdMap
Definition ApplicationBase.h:295
virtual bool settingChanged(const Property *_property)=0
This function will be called when the settings were changed in the uiService. The value of the provid...
void setProjectType(const std::string &_type)
Set the project type.
Definition ApplicationBase.h:154
JSON document.
Definition JSON.h:276
Definition ModalCommandBase.h:18
Definition PropertyGridCfg.h:21
The Property class is used as a base class for all Properties that can be displayed and modified in t...
Definition Property.h:21
General service information. The ServiceBase class is used to store the general service information.
Definition ServiceBase.h:24
Definition ModelComponent.h:42
Definition UiComponent.h:31
This is the main class interacting with external services. Use the static instance() function to get ...
Definition ExternalServicesComponent.h:27
Definition GraphicsPicker.cpp:29
Definition Connector.h:8
@ SECURE_MESSAGE_TYPES
Definition CommunicationTypes.h:14
unsigned long UID
Unique identifier (32 bit unsigned integer)
Definition CoreTypes.h:27
unsigned short serviceID_t
ID type used to identify a service (16 bit unsigned integer).
Definition CoreTypes.h:14
Definition ApplicationBase.h:287
JsonDocument * doc
Definition ApplicationBase.h:290
int enabledCounter
Definition ApplicationBase.h:289
ServiceBase * service
Definition ApplicationBase.h:288