cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsManagerComponentClient.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: 2010-08-29
8 
9  (C) Copyright 2010-2013 Johns Hopkins University (JHU), All Rights Reserved.
10 
11 --- begin cisst license - do not edit ---
12 
13 This software is provided "as is" under an open source license, with
14 no warranty. The complete license can be found in license.txt and
15 http://www.cisst.org/cisst/license.txt.
16 
17 --- end cisst license ---
18 */
19 
36 #ifndef _mtsManagerComponentClient_h
37 #define _mtsManagerComponentClient_h
38 
40 
42 {
43  CMN_DECLARE_SERVICES(CMN_NO_DYNAMIC_CREATION, CMN_LOG_ALLOW_DEFAULT);
44 
45  friend class mtsManagerLocal;
46 
47 protected:
50 
52  bool MCSReady;
53 
58  typedef struct {
69 
72 
74  typedef struct {
75  // Dynamic component management
89  // Getters
91  mtsFunctionQualifiedRead GetNamesOfComponents; // in: process name, out: components' names
92  mtsFunctionQualifiedRead GetNamesOfInterfaces; // in: process name, out: interfaces' names
99 
101 
102  // Event handlers for InterfaceLCM's required interface (handle events from MCS)
103  void HandleAddComponentEvent(const mtsDescriptionComponent &component);
104  void HandleChangeStateEvent(const mtsComponentStateChange &componentStateChange);
105  void HandleAddConnectionEvent(const mtsDescriptionConnection &connection);
107  void HandleMCSReadyEvent(void);
108 
109  // Event handlers for InterfaceComponent's required interface (handle events from Component)
110  void HandleChangeStateFromComponent(const mtsComponentStateChange & componentStateChange);
111 
112  // General-purpose interface. These are used to allow a class method to be invoked from
113  // any thread, but still allow that method to queue commands for execution by the MCC.
114  // Because any thread can call these methods, thread-safety is obtained by using a mutex.
119 
129  bool ConnectLocally(const std::string & clientComponentName, const std::string & clientInterfaceName,
130  const std::string & serverComponentName, const std::string & serverInterfaceName,
131  const std::string & clientProcessName = "");
132 
133  bool DisconnectLocally(const std::string & clientComponentName, const std::string & clientInterfaceName,
134  const std::string & serverComponentName, const std::string & serverInterfaceName);
135 
136  // If connection between InterfaceComponent.required - InterfaceInternal.provided is
137  // disconnected, required interface instance of InterfaceComponent that corresponds
138  // to the connection should be removed.
139  bool DisconnectCleanup(const std::string & componentName);
140 
141  bool AddInterfaceLCM(void);
142  bool AddInterfaceComponent(void);
143 
147  bool AddNewClientComponent(const std::string & clientComponentName);
148 
151  bool CanForwardLog(void) const;
152 
154  bool ForwardLog(const mtsLogMessage & log) const;
155 
156  // Called from LCM
157  bool Connect(const std::string & clientComponentName, const std::string & clientInterfaceRequiredName,
158  const std::string & serverComponentName, const std::string & serverInterfaceProvidedName);
159 
160  bool IsLocalProcess(const std::string &procName) const;
161 
163  void InterfaceLCMCommands_ComponentCreate(const mtsDescriptionComponent & componentDescription, bool & result);
165  void InterfaceLCMCommands_ComponentConnect(const mtsDescriptionConnection & connectionDescription /*, bool & result*/);
171  mtsComponentState &state) const;
173  mtsInterfaceProvidedDescription & description) const;
175  mtsInterfaceRequiredDescription & description) const;
176  void InterfaceLCMCommands_LoadLibrary(const std::string &fileName, bool &result) const;
178  std::vector<mtsDescriptionComponentClass> & listOfComponentClasses) const;
179  void InterfaceLCMCommands_SetLogForwarding(const bool &state);
180  void InterfaceLCMCommands_GetLogForwardingState(bool & state) const;
181  void InterfaceLCMCommands_GetAbsoluteTimeInSeconds(double &time) const;
182 
185 
187  void InterfaceComponentCommands_ComponentCreate(const mtsDescriptionComponent & componentDescription, bool & result);
189  void InterfaceComponentCommands_ComponentConnect(const mtsDescriptionConnection & connectionDescription /*, bool & result*/);
195  mtsComponentState &state) const;
196 
197  void InterfaceComponentCommands_GetNamesOfProcesses(std::vector<std::string> & names) const;
198  void InterfaceComponentCommands_GetNamesOfComponents(const std::string & processName,
199  std::vector<std::string> & names) const;
201  void InterfaceComponentCommands_GetListOfConnections(std::vector <mtsDescriptionConnection> & listOfConnections) const;
202  void InterfaceComponentCommands_GetListOfComponentClasses(const std::string &processName,
203  std::vector <mtsDescriptionComponentClass> & listOfComponentClasses) const;
205  mtsInterfaceProvidedDescription & description) const;
207  mtsInterfaceRequiredDescription & description) const;
208  void InterfaceComponentCommands_LoadLibrary(const mtsDescriptionLoadLibrary &lib, bool &result) const;
209  void InterfaceComponentCommands_EnableLogForwarding(const std::vector<std::string> &processNames);
210  void InterfaceComponentCommands_DisableLogForwarding(const std::vector<std::string> &processNames);
211  void InterfaceComponentCommands_GetLogForwardingStates(const stdStringVec & processNames, stdCharVec & states) const;
212  void InterfaceComponentCommands_GetAbsoluteTimeDiffs(const std::vector<std::string> &processNames,
213  std::vector<double> &processTimes) const;
214 
220 
221  void GetAbsoluteTimeInSeconds(mtsDouble &time) const; // DEPRECATED
222 
223 
224 public:
225  mtsManagerComponentClient(const std::string & componentName);
227 
228  void Startup(void);
229  void Run(void);
230  void Cleanup(void);
231 
232 };
233 
235 
236 #endif // _mtsManagerComponentClient_h
mtsFunctionWrite DisableLogForwarding
Definition: mtsManagerComponentClient.h:87
void InterfaceComponentCommands_GetListOfComponentClasses(const std::string &processName, std::vector< mtsDescriptionComponentClass > &listOfComponentClasses) const
void InterfaceComponentCommands_EnableLogForwarding(const std::vector< std::string > &processNames)
mtsFunctionQualifiedRead GetLogForwardingStates
Definition: mtsManagerComponentClient.h:88
void GetAbsoluteTimeInSeconds(mtsDouble &time) const
void InterfaceLCMCommands_ComponentStop(const mtsComponentStatusControl &arg)
mtsFunctionRead ComponentGetState
Definition: mtsManagerComponentClient.h:61
mtsFunctionWrite InterfaceComponentEvents_RemoveConnection
Definition: mtsManagerComponentClient.h:219
void InterfaceLCMCommands_ComponentResume(const mtsComponentStatusControl &arg)
Definition: mtsFunctionRead.h:37
Define a Mutex object.
Definition: osaMutex.h:48
void InterfaceLCMCommands_SetLogForwarding(const bool &state)
void InterfaceLCMCommands_GetInterfaceRequiredDescription(const mtsDescriptionInterface &intfc, mtsInterfaceRequiredDescription &description) const
void InterfaceComponentCommands_DisableLogForwarding(const std::vector< std::string > &processNames)
Definition: mtsManagerComponentClient.h:58
Definition: mtsParameterTypes.h:100
void InterfaceComponentCommands_ComponentResume(const mtsComponentStatusControl &arg)
void InterfaceLCMCommands_GetListOfComponentClasses(std::vector< mtsDescriptionComponentClass > &listOfComponentClasses) const
void InterfaceLCMCommands_ComponentGetState(const mtsDescriptionComponent &component, mtsComponentState &state) const
Definition: mtsParameterTypes.h:652
void InterfaceComponentCommands_ComponentConfigure(const mtsDescriptionComponent &arg)
Definition: mtsFunctionQualifiedRead.h:37
mtsFunctionQualifiedRead GetNamesOfComponents
Definition: mtsManagerComponentClient.h:91
mtsFunctionWrite EnableLogForwarding
Definition: mtsManagerComponentClient.h:86
mtsFunctionWrite ComponentConnect
Definition: mtsManagerComponentClient.h:117
mtsFunctionQualifiedRead GetNamesOfInterfaces
Definition: mtsManagerComponentClient.h:92
mtsFunctionRead GetNamesOfProcesses
Definition: mtsManagerComponentClient.h:49
bool IsLocalProcess(const std::string &procName) const
InterfaceLCMFunctionType InterfaceLCMFunction
Definition: mtsManagerComponentClient.h:100
mtsFunctionVoid ComponentStop
Definition: mtsManagerComponentClient.h:59
bool Connect(const std::string &clientComponentName, const std::string &clientInterfaceRequiredName, const std::string &serverComponentName, const std::string &serverInterfaceProvidedName)
void InterfaceLCMCommands_ComponentConnect(const mtsDescriptionConnection &connectionDescription)
std::vector< std::string > stdStringVec
Definition: mtsGenericObjectProxy.h:39
Definition: mtsInterfaceCommon.h:1046
mtsManagerComponentClient(const std::string &componentName)
void InterfaceLCMCommands_ComponentConfigure(const mtsDescriptionComponent &arg)
Definition: mtsFunctionVoid.h:36
void InterfaceComponentCommands_ComponentCreate(const mtsDescriptionComponent &componentDescription, bool &result)
bool MCSReady
Definition: mtsManagerComponentClient.h:52
mtsFunctionWrite InterfaceComponentEvents_AddConnection
Definition: mtsManagerComponentClient.h:218
mtsFunctionWrite ComponentConfigure
Definition: mtsManagerComponentClient.h:77
Definition: mtsParameterTypes.h:873
mtsFunctionQualifiedRead GetInterfaceRequiredDescription
Definition: mtsManagerComponentClient.h:96
bool AddInterfaceComponent(void)
Declaration of Base Class for Manager ComponentsIn the networked configuration, the communication bet...
void InterfaceComponentCommands_GetNamesOfProcesses(std::vector< std::string > &names) const
mtsFunctionQualifiedRead GetInterfaceProvidedDescription
Definition: mtsManagerComponentClient.h:95
Definition: mtsManagerLocal.h:89
Declaration of Manager Component ClientThis class defines the manager component client which is manag...
Definition: mtsManagerComponentClient.h:41
mtsFunctionWrite InterfaceComponentEvents_ChangeState
Definition: mtsManagerComponentClient.h:217
mtsFunctionWrite ComponentStartOther
Definition: mtsManagerComponentClient.h:67
void InterfaceLCMCommands_LoadLibrary(const std::string &fileName, bool &result) const
void InterfaceComponentCommands_GetLogForwardingStates(const stdStringVec &processNames, stdCharVec &states) const
osaMutex Mutex
Definition: mtsManagerComponentClient.h:116
Definition: mtsInterfaceCommon.h:928
Definition: mtsParameterTypes.h:533
Definition: mtsManagerComponentClient.h:74
CMN_DECLARE_SERVICES_INSTANTIATION(mtsManagerComponentClient)
Definition: mtsManagerComponentBase.h:99
bool ConnectLocally(const std::string &clientComponentName, const std::string &clientInterfaceName, const std::string &serverComponentName, const std::string &serverInterfaceName, const std::string &clientProcessName="")
Connect two local interfaces.
void InterfaceLCMCommands_GetInterfaceProvidedDescription(const mtsDescriptionInterface &intfc, mtsInterfaceProvidedDescription &description) const
mtsFunctionWriteReturn RemoveObserverList
Definition: mtsManagerComponentClient.h:65
mtsFunctionWrite ComponentDisconnect
Definition: mtsManagerComponentClient.h:79
Definition: mtsParameterTypes.h:322
mtsFunctionVoid ComponentResume
Definition: mtsManagerComponentClient.h:60
mtsFunctionWriteReturn RemoveEndUserInterface
Definition: mtsManagerComponentClient.h:64
mtsFunctionWrite ComponentResume
Definition: mtsManagerComponentClient.h:82
bool AddNewClientComponent(const std::string &clientComponentName)
mtsFunctionWrite ComponentStop
Definition: mtsManagerComponentClient.h:81
mtsFunctionWrite InterfaceComponentEvents_AddComponent
Definition: mtsManagerComponentClient.h:216
Definition: mtsComponentState.h:34
void InterfaceLCMCommands_GetAbsoluteTimeInSeconds(double &time) const
bool DisconnectCleanup(const std::string &componentName)
void InterfaceComponentCommands_GetAbsoluteTimeDiffs(const std::vector< std::string > &processNames, std::vector< double > &processTimes) const
void InterfaceComponentCommands_GetInterfaceProvidedDescription(const mtsDescriptionInterface &intfc, mtsInterfaceProvidedDescription &description) const
struct mtsManagerComponentClient::GeneralInterfaceStruct GeneralInterface
bool ForwardLog(const mtsLogMessage &log) const
void InterfaceComponentCommands_ComponentDisconnect(const mtsDescriptionConnection &arg)
mtsFunctionWriteReturn AddObserverList
Definition: mtsManagerComponentClient.h:63
void InterfaceComponentCommands_ComponentStart(const mtsComponentStatusControl &arg)
mtsFunctionWriteReturn GetEndUserInterface
Definition: mtsManagerComponentClient.h:62
void InterfaceComponentCommands_ComponentGetState(const mtsDescriptionComponent &component, mtsComponentState &state) const
void InterfaceComponentCommands_GetNamesOfInterfaces(const mtsDescriptionComponent &component, mtsDescriptionInterface &interfaces) const
bool DisconnectLocally(const std::string &clientComponentName, const std::string &clientInterfaceName, const std::string &serverComponentName, const std::string &serverInterfaceName)
void InterfaceLCMCommands_ComponentCreate(const mtsDescriptionComponent &componentDescription, bool &result)
void InterfaceLCMCommands_GetLogForwardingState(bool &state) const
mtsFunctionRead GetListOfConnections
Definition: mtsManagerComponentClient.h:93
mtsFunctionWrite ComponentStart
Definition: mtsManagerComponentClient.h:80
Definition: mtsManagerComponentClient.h:115
void HandleChangeStateFromComponent(const mtsComponentStateChange &componentStateChange)
void InterfaceComponentCommands_ComponentConnect(const mtsDescriptionConnection &connectionDescription)
void InterfaceComponentCommands_GetListOfConnections(std::vector< mtsDescriptionConnection > &listOfConnections) const
mtsFunctionRead GetNamesOfProcesses
Definition: mtsManagerComponentClient.h:90
void InterfaceLCMCommands_ComponentDisconnect(const mtsDescriptionConnection &arg)
std::vector< char > stdCharVec
Definition: mtsGenericObjectProxy.h:41
void InterfaceLCMCommands_ComponentStart(const mtsComponentStatusControl &arg)
void HandleAddComponentEvent(const mtsDescriptionComponent &component)
mtsFunctionWrite PrintLog
Definition: mtsManagerComponentClient.h:85
mtsFunctionQualifiedRead ComponentGetState
Definition: mtsManagerComponentClient.h:83
Definition: mtsParameterTypesOld.h:84
InterfaceComponentFunctionMapType InterfaceComponentFunctionMap
Definition: mtsManagerComponentClient.h:71
Definition: mtsFunctionWrite.h:37
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
cmnNamedMap< InterfaceComponentFunctionType > InterfaceComponentFunctionMapType
Definition: mtsManagerComponentClient.h:70
mtsFunctionWrite ComponentConnect
Definition: mtsManagerComponentClient.h:78
mtsFunctionQualifiedRead GetAbsoluteTimeDiffs
Definition: mtsManagerComponentClient.h:97
bool CanForwardLog(void) const
Definition: mtsParameterTypes.h:769
void InterfaceComponentCommands_GetNamesOfComponents(const std::string &processName, std::vector< std::string > &names) const
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76
mtsFunctionQualifiedRead LoadLibrary
Definition: mtsManagerComponentClient.h:84
Definition: mtsFunctionWriteReturn.h:38
mtsFunctionQualifiedRead GetListOfComponentClasses
Definition: mtsManagerComponentClient.h:94
void InterfaceComponentCommands_GetInterfaceRequiredDescription(const mtsDescriptionInterface &intfc, mtsInterfaceRequiredDescription &description) const
mtsFunctionWrite InterfaceLCMEvents_ChangeState
Definition: mtsManagerComponentClient.h:184
void HandleRemoveConnectionEvent(const mtsDescriptionConnection &connection)
mtsFunctionWriteReturn ComponentCreate
Definition: mtsManagerComponentClient.h:66
void HandleAddConnectionEvent(const mtsDescriptionConnection &connection)
void InterfaceComponentCommands_LoadLibrary(const mtsDescriptionLoadLibrary &lib, bool &result) const
mtsFunctionWriteReturn ComponentCreate
Definition: mtsManagerComponentClient.h:76
void HandleChangeStateEvent(const mtsComponentStateChange &componentStateChange)
void InterfaceComponentCommands_ComponentStop(const mtsComponentStatusControl &arg)