OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
SessionService.h
Go to the documentation of this file.
1/*
2 * SessionService.h
3 *
4 * Created on: November 26, 2020
5 * Author: Alexander Kuester
6 * Copyright (c) 2020 openTwin
7 */
8
9#pragma once
10
11// SessionService header
12#include "globalDatatypes.h"
13#include "PortManager.h"
14#include "Service.h"
16
17#include "OTCore/ServiceBase.h"
23
24// C++ header
25#include <map>
26#include <vector>
27#include <string>
28
29class Session;
30class RelayService;
32
34public:
36 virtual ~SessionService() {}; // todo: add cleanup
37
38 static SessionService * instance(void);
39
40 // ######################################################################################
41
42 // Setter / Getter
43
44 void setIp(const std::string& _ip) { m_ip = _ip; };
45 const std::string& ip(void) const { return m_ip; };
46
47 void setPort(const std::string& _port);
48 const std::string& port(void) const { return m_port; };
49
50 void setId(ot::serviceID_t _id) { m_id = _id; };
51 ot::serviceID_t id(void) const { return m_id; };
52
53 std::string url(void) const { return m_ip + ":" + m_port; };
54
57 void setDataBaseURL(const std::string& _url) { m_dataBaseURL = _url; }
58
60 const std::string& dataBaseURL(void) const { return m_dataBaseURL; }
61
64 void setSiteID(std::string _ID) { m_siteID = _ID; }
65
67 const std::string& siteID(void) const { return m_siteID; }
68
71 void setAuthorisationServiceURL(const std::string& _url) { m_serviceAuthorisationURL = _url; }
72
74 const std::string& serviceAuthorisationURL(void) const { return m_serviceAuthorisationURL; }
75
76 void setGlobalDirectoryServiceURL(const std::string& _url);
77
79 bool isServiceInDebugMode(const std::string& _serviceName);
80
81 // ######################################################################################
82
83 // Getter
84
85 // ######################################################################################
86
87 // Service management
88
98 const std::string & _sessionID,
99 const std::string & _userName,
100 const std::string & _projectName,
101 const std::string & _collectionName,
102 const std::string & _sessionType
103 );
104
109 Session * getSession(const std::string& _sessionID);
110
114 const std::string & _sessionID
115 );
116
120 Session * _session
121 );
122
124 void serviceClosing(
125 Service * _service,
126 bool _notifyOthers,
127 bool _autoCloseSessionIfMandatory = true
128 );
129
134 void removeSession(Session* _session);
135
137 void forgetSession(Session* _session);
138
139 std::list<const Session *> sessions(void);
140
141 bool runServiceInDebug(const std::string& _serviceName, const std::string& _serviceType, Session* _session, std::string& _serviceURL);
142
143 bool runRelayService(Session * _session, std::string& _websocketURL, std::string& _serviceURL);
144
145 void setGlobalSessionService(GlobalSessionService * _gss) { m_globalSessionService = _gss; }
146
147 Service * getServiceFromURL(const std::string& _url);
148
151
152 void updateLogMode(const ot::LogModeManager& _newData);
153
154private:
155 // Message handling
156
160
163
166
177 OT_HANDLER(handleReset, SessionService, OT_ACTION_CMD_Reset, ot::SECURE_MESSAGE_TYPES) // todo: you thought i work? well.. no i do not (yet) :D
185
187
188 void workerShutdownSession(ot::serviceID_t _serviceId, Session* _session);
189
190 std::string m_dataBaseURL;
191 std::string m_siteID;
192 std::string m_serviceAuthorisationURL;
193
194 std::string m_ip;
195 std::string m_port;
196 ot::serviceID_t m_id;
197 ot::SystemInformation m_systemLoadInformation;
198
199 //NOTE, debug only this variable contains the IP address that is used for the services
200
201 std::map<std::string, bool> m_serviceDebugList;
202 std::map<std::string,
203 std::vector<ot::ServiceBase> *> m_mandatoryServicesMap;
204 std::map<std::string, Session *> m_sessionMap;
205
206 GlobalSessionService * m_globalSessionService;
207 GlobalDirectoryService * m_globalDirectoryService;
208
209 std::list<std::string> m_sessionShutdownQueue;
210
211 ot::LogModeManager m_logModeManager;
212
213 SessionService(const SessionService&) = delete;
214 SessionService & operator =(const SessionService&) = delete;
215};
#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_ServiceDisableDebug
Definition ActionTypes.h:70
#define OT_ACTION_CMD_GetGlobalServicesUrl
Definition ActionTypes.h:23
#define OT_ACTION_CMD_CheckStartupCompleted
Definition ActionTypes.h:73
#define OT_ACTION_CMD_GetSystemInformation
Definition ActionTypes.h:43
#define OT_ACTION_CMD_ServiceFailure
Definition ActionTypes.h:49
#define OT_ACTION_CMD_GetSessionExists
Definition ActionTypes.h:45
#define OT_ACTION_CMD_AddMandatoryService
Definition ActionTypes.h:51
#define OT_ACTION_CMD_Message
Definition ActionTypes.h:27
#define OT_ACTION_CMD_ServiceEnableDebug
Definition ActionTypes.h:69
#define OT_ACTION_CMD_ServiceHide
Definition ActionTypes.h:71
#define OT_ACTION_CMD_GetDatabaseUrl
Definition ActionTypes.h:21
#define OT_ACTION_CMD_Reset
Definition ActionTypes.h:56
#define OT_ACTION_CMD_IsProjectOpen
Definition ActionTypes.h:37
#define OT_ACTION_CMD_GetSessionServices
Definition ActionTypes.h:46
#define OT_ACTION_CMD_ShutdownSession
Definition ActionTypes.h:47
#define OT_ACTION_CMD_RegisterNewGlobalDirecotoryService
Definition ActionTypes.h:40
#define OT_ACTION_CMD_GetDebugInformation
Definition ActionTypes.h:57
#define OT_ACTION_CMD_ServiceClosing
Definition ActionTypes.h:29
#define OT_ACTION_CMD_GetAuthorisationServerUrl
Definition ActionTypes.h:22
#define OT_ACTION_CMD_SetGlobalLogFlags
Definition ActionTypes.h:63
#define OT_ACTION_CMD_RegisterNewService
Definition ActionTypes.h:30
#define OT_ACTION_CMD_ServiceShow
Definition ActionTypes.h:72
#define OT_ACTION_CMD_SendBroadcastMessage
Definition ActionTypes.h:38
#define OT_ACTION_CMD_ServiceStartupFailed
Definition ActionTypes.h:50
#define OT_ACTION_CMD_GetMandatoryServices
Definition ActionTypes.h:24
#define OT_ACTION_CMD_CreateNewSession
Definition ActionTypes.h:35
const char const char const char * _sessionID
Definition dllmain.cpp:62
const char * _serviceURL
Definition dllmain.cpp:93
Definition GlobalDirectoryService.h:7
Definition GlobalSessionService.h:28
Definition relayService.h:19
Definition Service.h:17
Definition Session.h:11
Definition SessionService.h:33
const std::string & port(void) const
Definition SessionService.h:48
void setGlobalDirectoryServiceURL(const std::string &_url)
Definition SessionService.cpp:128
const std::string & serviceAuthorisationURL(void) const
Will return the session service service directory IP.
Definition SessionService.h:74
Service * getServiceFromURL(const std::string &_url)
Definition SessionService.cpp:383
void updateLogMode(const ot::LogModeManager &_newData)
Definition SessionService.cpp:1097
bool runServiceInDebug(const std::string &_serviceName, const std::string &_serviceType, Session *_session, std::string &_serviceURL)
Definition SessionService.cpp:292
const std::string & ip(void) const
Definition SessionService.h:45
bool runMandatoryServices(const std::string &_sessionID)
Will ensure that all mandatory services for the specified session are running.
Definition SessionService.cpp:166
static SessionService * instance(void)
Definition SessionService.cpp:109
virtual ~SessionService()
Definition SessionService.h:36
Session * createSession(const std::string &_sessionID, const std::string &_userName, const std::string &_projectName, const std::string &_collectionName, const std::string &_sessionType)
Will create a new session with the provided session information Will return a pointer to the new sess...
Definition SessionService.cpp:136
void forgetSession(Session *_session)
Removes the session from the service run starter and all maps.
Definition SessionService.cpp:279
std::string url(void) const
Definition SessionService.h:53
void setAuthorisationServiceURL(const std::string &_url)
Will set the authorisation service IP.
Definition SessionService.h:71
void setPort(const std::string &_port)
Definition SessionService.cpp:120
void setId(ot::serviceID_t _id)
Definition SessionService.h:50
std::list< const Session * > sessions(void)
Definition SessionService.cpp:284
Session * getSession(const std::string &_sessionID)
Returns the session with the specified id.
Definition SessionService.cpp:155
void initializeSystemInformation()
Initialize the collection of system information (e.g. CPU time and memory).
Definition SessionService.cpp:1092
void setGlobalSessionService(GlobalSessionService *_gss)
Definition SessionService.h:145
void setDataBaseURL(const std::string &_url)
Will set the database IP.
Definition SessionService.h:57
SessionService()
Definition SessionService.cpp:37
void removeSession(Session *_session)
Will remove the session and close its logger. Will NOT perform the session shutdown()....
Definition SessionService.cpp:274
void setIp(const std::string &_ip)
Definition SessionService.h:44
void serviceClosing(Service *_service, bool _notifyOthers, bool _autoCloseSessionIfMandatory=true)
Will close the service and deregister it from its session.
Definition SessionService.cpp:231
ot::serviceID_t id(void) const
Definition SessionService.h:51
void setSiteID(std::string _ID)
Will set the site ID.
Definition SessionService.h:64
bool runRelayService(Session *_session, std::string &_websocketURL, std::string &_serviceURL)
Definition SessionService.cpp:336
bool isServiceInDebugMode(const std::string &_serviceName)
Will return true if the provided service is in debug mode.
Definition SessionService.cpp:105
const std::string & siteID(void) const
Will return the session service site ID.
Definition SessionService.h:67
const std::string & dataBaseURL(void) const
Will return the database IP.
Definition SessionService.h:60
Definition ActionHandler.h:14
Definition LogModeManager.h:13
Definition SystemInformation.h:19
@ SECURE_MESSAGE_TYPES
Definition CommunicationTypes.h:14
@ ALL_MESSAGE_TYPES
Definition CommunicationTypes.h:15
unsigned short serviceID_t
ID type used to identify a service (16 bit unsigned integer).
Definition CoreTypes.h:14