cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsManagerGlobal.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Min Yang Jung
7  Created on: 2009-11-12
8 
9  (C) Copyright 2009-2011 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
30 #ifndef _mtsManagerGlobal_h
31 #define _mtsManagerGlobal_h
32 
35 
39 
45 
47 
48 // Forward declaration
50 
52 {
53  friend class mtsManagerGlobalTest;
54  friend class mtsManagerLocalTest;
55 
57 
58 protected:
59  //-------------------------------------------------------------------------
60  // Data Structure of Process Map
61  //-------------------------------------------------------------------------
62  /*
63  P1 - C1 - p1 - r1 Process Map: (P, ComponentMap)
64  | | | | Component Map: (C, InterfaceMap)
65  | | | r2 Interface Map: { (PI, ConnectionMap) where PI is Provided Interface
66  | | | (RI, ConnectionMap) where RI is Required Interface }
67  | | p2 - r3 Connection Map: (name of connected interface, list of connection id(s))
68  | | |
69  | | r1 - p1
70  | |
71  | C2 - r1 - p2
72  |
73  P2 - C1
74  |
75  C2
76  */
77 
81  //typedef cmnNamedMap<mtsManagerGlobal::ConnectedInterfaceInfo> ConnectionMapType;
82  typedef std::vector<ConnectionIDType> ConnectionIDListType;
83 
86  //typedef cmnNamedMap<ConnectionIDListType> ConnectedInterfaceMapType;
88 
90  typedef struct {
91  //ConnectedInterfaceMapType InterfaceProvidedOrOutputMap;
92  //ConnectedInterfaceMapType InterfaceRequiredOrInputMap;
96 
101 
107 
115  typedef std::map<ConnectionIDType, mtsConnection> ConnectionMapType;
117 
132 
134  osaMutex ProcessMapChange; // for thread-safe ProcessMap update
135  osaMutex ConnectionMapChange; // for thread-safe ConnectionMap update
136  osaMutex ConnectionChange; // to process Connect() request one-by-one
137  osaMutex DisconnectedProcessCleanupMapChange; // for thread-safe DisconnectedProcessCleanupMap update
138 
141 
143  mtsManagerProxyServer * ProxyServer;
144 
147 
149  typedef std::map<ConnectionIDType, ConnectionIDType> DisconnectQueueType;
152 
155 
159  void * ThreadDisconnectProcess(void * arg);
160 
162  typedef struct CleanupElementType {
163  std::string ProcessName;
164  std::string ComponentProxyName;
166  typedef std::list<CleanupElementType> CleanupElementListType;
169 
171  void ShowInternalStructure(void);
172 
173  //-------------------------------------------------------------------------
174  // Processing Methods
175  //-------------------------------------------------------------------------
177  void Cleanup(void);
178 
180  ConnectionIDListType * GetConnectionsOfInterfaceProvidedOrOutput(
181  const std::string & serverProcessName, const std::string & serverComponentName,
182  const std::string & interfaceName) const;
183 
184  ConnectionIDListType * GetConnectionsOfInterfaceProvidedOrOutput(
185  const std::string & serverProcessName, const std::string & serverComponentName,
186  const std::string & interfaceName, InterfaceMapType ** interfaceMap) const;
187 
189  ConnectionIDListType * GetConnectionsOfInterfaceRequiredOrInput(
190  const std::string & clientProcessName, const std::string & clientComponentName,
191  const std::string & interfaceName) const;
192 
193  ConnectionIDListType * GetConnectionsOfInterfaceRequiredOrInput(
194  const std::string & clientProcessName, const std::string & clientComponentName,
195  const std::string & interfaceName, InterfaceMapType ** interfaceMap) const;
196 
198  bool AddConnectionToInterfaceProvidedOrOutput(
199  const std::string & serverProcessName, const std::string & serverComponentName,
200  const std::string & interfaceName, const ConnectionIDType connectionID);
201 
202  bool AddConnectionToInterfaceRequiredOrInput(
203  const std::string & clientProcessName, const std::string & clientComponentName,
204  const std::string & interfaceName, const ConnectionIDType connectionID);
205 
207  bool RemoveConnectionOfInterfaceProvidedOrOutput(
208  const std::string & serverProcessName, const std::string & serverComponentName,
209  const std::string & interfaceName, const ConnectionIDType connectionID);
210 
211  bool RemoveConnectionOfInterfaceRequiredOrInput(
212  const std::string & clientProcessName, const std::string & clientComponentName,
213  const std::string & interfaceName, const ConnectionIDType connectionID);
214 
217  bool CleanupDisconnectedProcess(const std::string & nameOfProcessDisconnected);
218 
220  bool IsAlreadyConnected(const mtsDescriptionConnection & description) const;
221 
223  int GetNumberOfInterfaces(const std::string & processName, const std::string & componentName, const bool includeInternalInterface = true) const;
224 
226  ConnectionIDType GetConnectionID(const std::string & clientProcessName,
227  const std::string & clientComponentName, const std::string & interfaceName) const;
228 
230  mtsConnection * GetConnectionInformation(const ConnectionIDType connectionID);
231 
235  void DisconnectInternal(void);
236 
238  void AddToDisconnectedProcessCleanup(const std::string & sourceProcessName,
239  const std::string & targetProcessName, const std::string & targetComponentProxyName);
240 
241 public:
244  ~mtsManagerGlobal();
245 
246  void SetMCS(mtsManagerComponentServer *mcs) { ManagerComponentServer = mcs; }
247 
248  //-------------------------------------------------------------------------
249  // Process Management
250  //-------------------------------------------------------------------------
251  bool AddProcess(const std::string & processName);
252 
253  bool AddProcessObject(mtsManagerLocalInterface * localManagerObject, const bool isManagerProxyServer = false);
254 
255  bool FindProcess(const std::string & processName) const;
256 
257  bool RemoveProcess(const std::string & processName, const bool networkDisconnect = false);
258 
259  //-------------------------------------------------------------------------
260  // Component Management
261  //-------------------------------------------------------------------------
262  bool AddComponent(const std::string & processName, const std::string & componentName);
263 
264  bool FindComponent(const std::string & processName, const std::string & componentName) const;
265 
266  bool RemoveComponent(const std::string & processName, const std::string & componentName, const bool lock = true);
267 
268  //-------------------------------------------------------------------------
269  // Interface Management
270  //-------------------------------------------------------------------------
271  bool AddInterfaceProvidedOrOutput(const std::string & processName, const std::string & componentName, const std::string & interfaceName);
272 
273  bool AddInterfaceRequiredOrInput(const std::string & processName, const std::string & componentName, const std::string & interfaceName);
274 
275  bool FindInterfaceProvidedOrOutput(const std::string & processName, const std::string & componentName, const std::string & interfaceName) const;
276 
277  bool FindInterfaceRequiredOrInput(const std::string & processName, const std::string & componentName, const std::string & interfaceName) const;
278 
279  bool RemoveInterfaceProvidedOrOutput(const std::string & processName, const std::string & componentName, const std::string & interfaceName, const bool lock = true);
280 
281  bool RemoveInterfaceRequiredOrInput(const std::string & processName, const std::string & componentName, const std::string & interfaceName, const bool lock = true);
282 
283  //-------------------------------------------------------------------------
284  // Connection Management
285  //-------------------------------------------------------------------------
286  ConnectionIDType Connect(const std::string & requestProcessName,
287  const std::string & clientProcessName, const std::string & clientComponentName, const std::string & clientInterfaceName,
288  const std::string & serverProcessName, const std::string & serverComponentName, const std::string & serverInterfaceName);
289 
290  bool ConnectConfirm(const ConnectionIDType connectionID);
291 
292  bool Disconnect(const ConnectionIDType connectionID);
293 
294  bool Disconnect(const mtsDescriptionConnection & connection);
295 
296  bool Disconnect(
297  const std::string & clientProcessName, const std::string & clientComponentName, const std::string & clientInterfaceName,
298  const std::string & serverProcessName, const std::string & serverComponentName, const std::string & serverInterfaceName);
299 
300  bool InitiateConnect(const ConnectionIDType connectionID);
301 
302  bool ConnectServerSideInterfaceRequest(const ConnectionIDType connectionID);
303 
304  void GetListOfConnections(std::vector<mtsDescriptionConnection> & list) const;
305 
306  //-------------------------------------------------------------------------
307  // Getters
308  //-------------------------------------------------------------------------
310  inline static std::string GetName(void) {
311  return "GlobalComponentManager";
312  }
313 
315  std::vector<std::string> GetIPAddress(void) const;
316  void GetIPAddress(std::vector<std::string> & ipAddresses) const;
317 
319  void GetNamesOfProcesses(std::vector<std::string>& namesOfProcesses) const;
320 
322  void GetNamesOfComponents(const std::string & processName,
323  std::vector<std::string>& namesOfComponents) const;
324 
326  void GetNamesOfInterfacesProvidedOrOutput(const std::string & processName,
327  const std::string & componentName,
328  std::vector<std::string> & namesOfInterfacesProvided) const;
329 
331  void GetNamesOfInterfacesRequiredOrInput(const std::string & processName,
332  const std::string & componentName,
333  std::vector<std::string> & namesOfInterfacesRequired) const;
334 
336  void GetNamesOfCommands(const std::string & processName,
337  const std::string & componentName,
338  const std::string & providedInterfaceName,
339  std::vector<std::string>& namesOfCommands) const;
340 
342  void GetNamesOfEventGenerators(const std::string & processName,
343  const std::string & componentName,
344  const std::string & providedInterfaceName,
345  std::vector<std::string>& namesOfEventGenerators) const;
346 
348  void GetNamesOfFunctions(const std::string & processName,
349  const std::string & componentName,
350  const std::string & requiredInterfaceName,
351  std::vector<std::string>& namesOfFunctions) const;
352 
354  void GetNamesOfEventHandlers(const std::string & processName,
355  const std::string & componentName,
356  const std::string & requiredInterfaceName,
357  std::vector<std::string>& namesOfEventHandlers) const;
358 
360  void GetDescriptionOfCommand(const std::string & processName,
361  const std::string & componentName,
362  const std::string & providedInterfaceName,
363  const std::string & commandName,
364  std::string & description) const;
365 
367  void GetDescriptionOfEventGenerator(const std::string & processName,
368  const std::string & componentName,
369  const std::string & providedInterfaceName,
370  const std::string & eventGeneratorName,
371  std::string & description) const;
372 
374  void GetDescriptionOfFunction(const std::string & processName,
375  const std::string & componentName,
376  const std::string & requiredInterfaceName,
377  const std::string & functionName,
378  std::string & description) const;
379 
381  void GetDescriptionOfEventHandler(const std::string & processName,
382  const std::string & componentName,
383  const std::string & requiredInterfaceName,
384  const std::string & eventHandlerName,
385  std::string & description) const;
386 
388  static bool IsProxyComponent(const std::string & componentName);
389 
391  static const std::string GetComponentProxyName(const std::string & processName, const std::string & componentName);
392 
394  mtsManagerLocalInterface * GetProcessObject(const std::string & processName) const;
395 
397  static const std::string GetInterfaceUID(
398  const std::string & processName, const std::string & componentName, const std::string & interfaceName);
399 
400  //-------------------------------------------------------------------------
401  // Networking
402  //-------------------------------------------------------------------------
405  bool StartServer(void);
406 
408  bool StopServer(void);
409 
411  bool SetInterfaceProvidedProxyAccessInfo(const ConnectionIDType connectionID, const std::string & endpointInfo);
412 
414  bool GetInterfaceProvidedProxyAccessInfo(const ConnectionIDType connectionID, std::string & endpointInfo);
415 
416  bool GetInterfaceProvidedProxyAccessInfo(const std::string & clientProcessName,
417  const std::string & serverProcessName, const std::string & serverComponentName,
418  const std::string & serverInterfaceName, std::string & endpointInfo);
419 
423  void CheckConnectConfirmTimeout(void);
424 };
425 
427 
428 #endif // _mtsManagerGlobal_h
virtual bool ConnectConfirm(const ConnectionIDType connectionID)=0
Confirm that connection has been successfully established.
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
osaMutex ConnectionChange
Definition: mtsManagerGlobal.h:136
Definition: mtsConnection.h:35
virtual bool AddComponent(const std::string &processName, const std::string &componentName)=0
Register component.
bool ThreadDisconnectRunning
Definition: mtsManagerGlobal.h:158
Declaration of osaMutex.
osaMutex QueueDisconnectWaitingChange
Definition: mtsManagerGlobal.h:153
Define a Mutex object.
Definition: osaMutex.h:48
virtual bool Disconnect(const ConnectionIDType connectionID)=0
Disconnect two interfaces.
virtual bool RemoveComponent(const std::string &processName, const std::string &componentName, const bool lock=true)=0
Remove component.
void SetMCS(mtsManagerComponentServer *mcs)
Definition: mtsManagerGlobal.h:246
virtual bool RemoveInterfaceProvidedOrOutput(const std::string &processName, const std::string &componentName, const std::string &interfaceName, const bool lock=true)=0
Remove provided interface. Can be called at run-time.
ProcessMapType ProcessMap
Definition: mtsManagerGlobal.h:106
Definition: mtsManagerGlobalInterface.h:43
mtsManagerLocalInterface * LocalManagerConnected
Definition: mtsManagerGlobal.h:131
virtual bool AddProcess(const std::string &processName)=0
Register process.
Declaration of cmnNamedMap.
osaThread ThreadDisconnect
Definition: mtsManagerGlobal.h:156
std::map< ConnectionIDType, ConnectionIDType > DisconnectQueueType
Definition: mtsManagerGlobal.h:149
Defines connection between two interfaces.
mtsManagerProxyServer * ProxyServer
Definition: mtsManagerGlobal.h:143
unsigned int ConnectionIDType
Definition: mtsForwardDeclarations.h:150
mtsManagerLocal * LocalManager
Definition: mtsManagerGlobal.h:130
cmnNamedMap< ConnectionIDListType > InterfaceMapElementType
Definition: mtsManagerGlobal.h:87
cmnNamedMap< InterfaceMapType > ComponentMapType
Definition: mtsManagerGlobal.h:100
Class register definitions and log macros.
Declaration of osaThread.
Define a thread object.
Definition: osaThread.h:164
ConnectionIDType ConnectionID
Definition: mtsManagerGlobal.h:140
Definition: mtsManagerLocal.h:89
Declaration of mtsManagerGlobalInterfaceThis class declares an interface used by local component mana...
virtual bool AddInterfaceRequiredOrInput(const std::string &processName, const std::string &componentName, const std::string &interfaceName)=0
Register required interface. Can be called at run-time.
virtual bool InitiateConnect(const ConnectionIDType connectionID)=0
Initiate connection process.
virtual bool FindInterfaceProvidedOrOutput(const std::string &processName, const std::string &componentName, const std::string &interfaceName) const =0
Find provided interface using process name, component name, and interface name.
std::map< ConnectionIDType, mtsConnection > ConnectionMapType
Definition: mtsManagerGlobal.h:115
Definition: mtsParameterTypes.h:533
DisconnectedProcessCleanupMapType DisconnectedProcessCleanupMap
Definition: mtsManagerGlobal.h:168
osaMutex ProcessMapChange
Definition: mtsManagerGlobal.h:134
Forward declarations and #define for cisstMultiTask.
static std::string GetName(void)
Definition: mtsManagerGlobal.h:310
mtsManagerComponentServer * ManagerComponentServer
Definition: mtsManagerGlobal.h:146
virtual bool RemoveProcess(const std::string &processName, const bool networkDisconnect)=0
Remove process.
osaMutex DisconnectedProcessCleanupMapChange
Definition: mtsManagerGlobal.h:137
std::list< CleanupElementType > CleanupElementListType
Definition: mtsManagerGlobal.h:166
virtual bool FindComponent(const std::string &processName, const std::string &componentName) const =0
Find component using process name and component name.
ConnectionMapType ConnectionMap
Definition: mtsManagerGlobal.h:116
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
osaMutex QueueDisconnectedChange
Definition: mtsManagerGlobal.h:154
InterfaceMapElementType InterfaceRequiredOrInputMap
Definition: mtsManagerGlobal.h:94
std::string ComponentProxyName
Definition: mtsManagerGlobal.h:164
Definition of mtsManagerLocalInterfaceThis class defines an interface used by the global component ma...
cmnNamedMap< ComponentMapType > ProcessMapType
Definition: mtsManagerGlobal.h:105
cmnNamedMap< CleanupElementListType > DisconnectedProcessCleanupMapType
Definition: mtsManagerGlobal.h:167
Definition: mtsManagerComponentServer.h:45
virtual bool FindProcess(const std::string &processName) const =0
Find process.
Definition: mtsManagerGlobal.h:90
Definition: mtsManagerGlobal.h:162
osaMutex ConnectionMapChange
Definition: mtsManagerGlobal.h:135
std::string ProcessName
Definition: mtsManagerGlobal.h:163
Declaration of osaGetTime.
virtual bool FindInterfaceRequiredOrInput(const std::string &processName, const std::string &componentName, const std::string &interfaceName) const =0
Find required interface using process name, component name, and interface name.
Rules of exporting.
virtual bool ConnectServerSideInterfaceRequest(const ConnectionIDType connectionID)=0
Request the global component manager to connect interfaces at server side.
Definition: osaThreadSignal.h:40
DisconnectQueueType QueueDisconnectWaiting
Definition: mtsManagerGlobal.h:150
virtual void GetListOfConnections(std::vector< mtsDescriptionConnection > &list) const =0
InterfaceMapElementType InterfaceProvidedOrOutputMap
Definition: mtsManagerGlobal.h:93
virtual bool SetInterfaceProvidedProxyAccessInfo(const ConnectionIDType connectionID, const std::string &endpointInfo)=0
Set access information of the provided interface proxy.
std::vector< ConnectionIDType > ConnectionIDListType
Definition: mtsManagerGlobal.h:82
DisconnectQueueType QueueDisconnected
Definition: mtsManagerGlobal.h:151
Definition: mtsManagerGlobal.h:51
virtual ConnectionIDType Connect(const std::string &requestProcessName, const std::string &clientProcessName, const std::string &clientComponentName, const std::string &clientInterfaceRequiredName, const std::string &serverProcessName, const std::string &serverComponentName, const std::string &serverInterfaceProvidedName)=0
Connect two interfaces.
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
osaThreadSignal ThreadDisconnectFinished
Definition: mtsManagerGlobal.h:157
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition: cmnClassRegisterMacros.h:202
virtual bool GetInterfaceProvidedProxyAccessInfo(const ConnectionIDType connectionID, std::string &endpointInfo)=0
Get access information of the provided interface proxy.
virtual bool AddInterfaceProvidedOrOutput(const std::string &processName, const std::string &componentName, const std::string &interfaceName)=0
Register provided interface. Can be called at run-time.
Definition: mtsManagerLocalInterface.h:54
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76
virtual bool RemoveInterfaceRequiredOrInput(const std::string &processName, const std::string &componentName, const std::string &interfaceName, const bool lock=true)=0
Remove required interface. Can be called at run-time.