cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsManagerComponentServices.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, Peter Kazanzides
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 
20 #ifndef _mtsManagerComponentServices_h
21 #define _mtsManagerComponentServices_h
22 
30 
32 
34 
35 protected:
37 
39  // Dynamic component management
48  mtsFunctionQualifiedRead GetState; // in: process, component, out: state
49  mtsFunctionQualifiedRead LoadLibrary; // in: process, library name, out: result (bool)
50  } ServiceComponentManagement;
51 
52  struct LogStruct {
56  } ServiceLogManagement;
57 
58  // Getters
59  struct GetterStruct {
61  mtsFunctionQualifiedRead GetNamesOfComponents; // in: process name, out: components' names
62  mtsFunctionQualifiedRead GetNamesOfInterfaces; // in: process name, out: interfaces' names
64  mtsFunctionQualifiedRead GetListOfComponentClasses; // in: process name, out: list of classes
68  } ServiceGetters;
69 
70  // Event receivers
71  struct EventStruct {
76  } EventReceivers;
77 
78  // private function used by WaitFor methods.
79  bool CheckAndWait(const std::vector<std::string> &list, const std::string &key, double &timeoutInSec,
80  mtsEventReceiverWrite &eventReceiver);
81 public:
82  mtsManagerComponentServices(mtsInterfaceRequired * internalInterfaceRequired);
84 
85  bool InitializeInterfaceInternalRequired(void);
86 
87  bool IsConnected(void) const
88  { return (InternalInterfaceRequired->GetConnectedInterface() != 0); }
89 
92  template <class __classType>
93  bool AddComponentEventHandler(void (__classType::*method)(const mtsDescriptionComponent &),
94  __classType * classInstantiation,
96  {
97  return (EventReceivers.AddComponent.SetHandler(method, classInstantiation, queueingPolicy) != 0);
98  }
99 
100  template <class __classType>
101  bool AddConnectionEventHandler(void (__classType::*method)(const mtsDescriptionConnection &),
102  __classType * classInstantiation,
104  {
105  return (EventReceivers.AddConnection.SetHandler(method, classInstantiation, queueingPolicy) != 0);
106  }
107 
108  template <class __classType>
109  bool RemoveConnectionEventHandler(void (__classType::*method)(const mtsDescriptionConnection &),
110  __classType * classInstantiation,
112  {
113  return (EventReceivers.RemoveConnection.SetHandler(method, classInstantiation, queueingPolicy) != 0);
114  }
115 
116  template <class __classType>
117  bool ChangeStateEventHandler(void (__classType::*method)(const mtsComponentStateChange &),
118  __classType * classInstantiation,
120  {
121  return (EventReceivers.ChangeState.SetHandler(method, classInstantiation, queueingPolicy) != 0);
122  }
124 
127  bool ComponentCreate(const std::string & className, const std::string & componentName) const;
128  bool ComponentCreate(const std::string & processName, const std::string & className,
129  const std::string & componentName) const;
130 
131  bool ComponentCreate(const std::string & className, const mtsGenericObject & constructorArg) const;
132  bool ComponentCreate(
133  const std::string& processName, const std::string & className, const mtsGenericObject & constructorArg) const;
134 
135  bool ComponentConfigure(const std::string & componentName, const std::string & configString) const;
136  bool ComponentConfigure(
137  const std::string& processName, const std::string & componentName, const std::string & configString) const;
138 
139  bool Connect(const std::string & clientComponentName, const std::string & clientInterfaceName,
140  const std::string & serverComponentName, const std::string & serverInterfaceName) const;
141  bool Connect(const std::string & clientProcessName,
142  const std::string & clientComponentName, const std::string & clientInterfaceName,
143  const std::string & serverProcessName,
144  const std::string & serverComponentName, const std::string & serverInterfaceName) const;
145  bool Connect(const mtsDescriptionConnection & connection) const;
146 
147  bool Disconnect(
148  const std::string & clientComponentName, const std::string & clientInterfaceName,
149  const std::string & serverComponentName, const std::string & serverInterfaceName) const;
150  bool Disconnect(
151  const std::string & clientProcessName,
152  const std::string & clientComponentName, const std::string & clientInterfaceName,
153  const std::string & serverProcessName,
154  const std::string & serverComponentName, const std::string & serverInterfaceName) const;
155  bool Disconnect(const mtsDescriptionConnection & connection) const;
156  bool Disconnect(ConnectionIDType connectionID) const;
157 
158  bool ComponentStart(const std::string & componentName, const double delayInSecond) const;
159  bool ComponentStart(const std::string & componentName) const
160  { return ComponentStart(componentName, 0.0); }
161  bool ComponentStart(const std::string& processName, const std::string & componentName,
162  const double delayInSecond) const;
163  bool ComponentStart(const std::string& processName, const std::string & componentName) const
164  { return ComponentStart(processName, componentName, 0.0); }
165 
166 
167  bool ComponentStop(const std::string & componentName, const double delayInSecond) const;
168  bool ComponentStop(const std::string & componentName) const
169  { return ComponentStop(componentName, 0.0); }
170  bool ComponentStop(const std::string& processName, const std::string & componentName,
171  const double delayInSecond) const;
172  bool ComponentStop(const std::string& processName, const std::string & componentName) const
173  { return ComponentStop(processName, componentName, 0.0); }
174 
175  bool ComponentResume(const std::string & componentName, const double delayInSecond = 0.0) const;
176  bool ComponentResume(const std::string& processName, const std::string & componentName,
177  const double delayInSecond = 0.0) const;
178 
179  mtsComponentState ComponentGetState(const mtsDescriptionComponent &component) const;
180  std::string ComponentGetState(const std::string componentName) const;
181  std::string ComponentGetState(const std::string & processName, const std::string componentName) const;
182 
183  std::vector<std::string> GetNamesOfProcesses(void) const;
184  std::vector<std::string> GetNamesOfComponents(const std::string & processName) const;
185  bool GetNamesOfInterfaces(const std::string & processName,
186  const std::string & componentName,
187  std::vector<std::string> & namesOfInterfacesRequired,
188  std::vector<std::string> & namesOfInterfacesProvided) const;
189 
190  std::vector<mtsDescriptionConnection> GetListOfConnections(void) const;
191 
192  std::vector<mtsDescriptionComponentClass> GetListOfComponentClasses(void) const;
193  std::vector<mtsDescriptionComponentClass> GetListOfComponentClasses(const std::string &processName) const;
194 
196  GetInterfaceProvidedDescription(const std::string & processName,
197  const std::string & componentName, const std::string &interfaceName) const;
199  GetInterfaceRequiredDescription(const std::string & processName,
200  const std::string & componentName, const std::string &interfaceName) const;
201 
202  // Dynamically load the file (fileName) into the current process
203  bool Load(const std::string & fileName) const;
204  // Dynamically load the file (fileName) into the process processName
205  bool Load(const std::string & processName, const std::string & fileName) const;
206 
207  // Enable/disable log forwarding
208  void EnableLogForwarding(void); // for all processes
209  void EnableLogForwarding(const std::vector<std::string> &processNames);
210  void DisableLogForwarding(void); // for all processes
211  void DisableLogForwarding(const std::vector<std::string> &processNames);
212  void GetLogForwardingStates(stdCharVec & states) const; // for all processes
213  void GetLogForwardingStates(const stdStringVec & processNames, stdCharVec & states) const;
214 
215  // Get absolute time differences of specified processes with respect to GCM
216  std::vector<double> GetAbsoluteTimeDiffs(const std::vector<std::string> &processNames) const;
217 
218  // Wait for component state change. This can be used to wait for a process to be created, or for a component
219  // to be created (in those cases, any state is acceptable). A negative timeout is used to wait indefinitely.
220  // Returns false if timeout occurred.
221  bool WaitFor(const std::string & processName, double timeoutInSec = -1.0);
222  bool WaitFor(const std::string & processName, const std::string & componentName, double timeoutInSec = -1.0);
223  bool WaitFor(const std::string & processName, const std::string & componentName, const std::string & state,
224  double timeoutInSec = -1.0);
226 
227 };
228 
230 
231 #endif // _mtsManagerComponentServices_h
Defines the command interfaces.
mtsEventReceiverWrite RemoveConnection
Definition: mtsManagerComponentServices.h:74
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
mtsFunctionRead GetNamesOfProcesses
Definition: mtsManagerComponentServices.h:60
Definition: mtsManagerComponentServices.h:40
Defines the command interfaces.
Definition: mtsFunctionRead.h:37
bool ComponentStop(const std::string &componentName) const
Definition: mtsManagerComponentServices.h:168
Declaration of mtsInterfaceRequired.
Definition: mtsManagerComponentServices.h:52
mtsFunctionQualifiedRead GetAbsoluteTimeDiffs
Definition: mtsManagerComponentServices.h:67
Definition: mtsParameterTypes.h:100
Definition: mtsForwardDeclarations.h:49
Definition: mtsFunctionQualifiedRead.h:37
mtsFunctionWrite Connect
Definition: mtsManagerComponentServices.h:43
Definition: mtsInterfaceRequired.h:85
mtsFunctionQualifiedRead GetLogForwardingStates
Definition: mtsManagerComponentServices.h:55
bool RemoveConnectionEventHandler(void(__classType::*method)(const mtsDescriptionConnection &), __classType *classInstantiation, mtsEventQueueingPolicy queueingPolicy=MTS_INTERFACE_EVENT_POLICY)
Definition: mtsManagerComponentServices.h:109
mtsFunctionWrite Configure
Definition: mtsManagerComponentServices.h:42
mtsFunctionQualifiedRead LoadLibrary
Definition: mtsManagerComponentServices.h:49
~mtsManagerComponentServices()
Definition: mtsManagerComponentServices.h:83
unsigned int ConnectionIDType
Definition: mtsForwardDeclarations.h:150
std::vector< std::string > stdStringVec
Definition: mtsGenericObjectProxy.h:39
mtsFunctionWrite DisableLogForwarding
Definition: mtsManagerComponentServices.h:54
Definition: mtsInterfaceCommon.h:1046
Declaration of mtsEventReceiverBase, mtsEventReceiverVoid, and mtsEventReceiverWrite.
Base class for high level objects.
Definition: cmnGenericObject.h:51
Base class for data object in cisstMultiTask.
Definition: mtsGenericObject.h:56
mtsFunctionQualifiedRead GetState
Definition: mtsManagerComponentServices.h:48
Defines the command interfaces.
Declaration of Base Class for Manager ComponentsIn the networked configuration, the communication bet...
mtsFunctionQualifiedRead GetListOfComponentClasses
Definition: mtsManagerComponentServices.h:64
bool ComponentStart(const std::string &componentName) const
Definition: mtsManagerComponentServices.h:159
mtsFunctionWrite Disconnect
Definition: mtsManagerComponentServices.h:44
mtsEventReceiverWrite ChangeState
Definition: mtsManagerComponentServices.h:75
Definition: mtsEventReceiver.h:180
mtsEventQueueingPolicy
Definition: mtsForwardDeclarations.h:49
mtsEventReceiverWrite AddComponent
Definition: mtsManagerComponentServices.h:72
Definition: mtsInterfaceCommon.h:928
Definition: mtsParameterTypes.h:533
mtsFunctionWrite EnableLogForwarding
Definition: mtsManagerComponentServices.h:53
mtsFunctionQualifiedRead GetInterfaceRequiredDescription
Definition: mtsManagerComponentServices.h:66
bool AddConnectionEventHandler(void(__classType::*method)(const mtsDescriptionConnection &), __classType *classInstantiation, mtsEventQueueingPolicy queueingPolicy=MTS_INTERFACE_EVENT_POLICY)
Definition: mtsManagerComponentServices.h:101
Definition: mtsComponentState.h:34
mtsFunctionQualifiedRead GetInterfaceProvidedDescription
Definition: mtsManagerComponentServices.h:65
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
Definition: mtsManagerComponentServices.h:59
mtsEventReceiverWrite AddConnection
Definition: mtsManagerComponentServices.h:73
mtsFunctionWriteReturn Create
Definition: mtsManagerComponentServices.h:41
bool AddComponentEventHandler(void(__classType::*method)(const mtsDescriptionComponent &), __classType *classInstantiation, mtsEventQueueingPolicy queueingPolicy=MTS_INTERFACE_EVENT_POLICY)
Definition: mtsManagerComponentServices.h:93
Definition: mtsManagerComponentServices.h:71
mtsFunctionWrite Resume
Definition: mtsManagerComponentServices.h:47
bool ComponentStart(const std::string &processName, const std::string &componentName) const
Definition: mtsManagerComponentServices.h:163
bool IsConnected(void) const
Definition: mtsManagerComponentServices.h:87
mtsFunctionQualifiedRead GetNamesOfInterfaces
Definition: mtsManagerComponentServices.h:62
std::vector< char > stdCharVec
Definition: mtsGenericObjectProxy.h:41
Definition: mtsFunctionWrite.h:37
bool ChangeStateEventHandler(void(__classType::*method)(const mtsComponentStateChange &), __classType *classInstantiation, mtsEventQueueingPolicy queueingPolicy=MTS_INTERFACE_EVENT_POLICY)
Definition: mtsManagerComponentServices.h:117
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition: cmnClassRegisterMacros.h:202
mtsFunctionQualifiedRead GetNamesOfComponents
Definition: mtsManagerComponentServices.h:61
Definition: mtsParameterTypes.h:769
mtsInterfaceRequired * InternalInterfaceRequired
Definition: mtsManagerComponentServices.h:36
mtsFunctionRead GetListOfConnections
Definition: mtsManagerComponentServices.h:63
Definition: mtsManagerComponentServices.h:31
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76
mtsFunctionWrite Start
Definition: mtsManagerComponentServices.h:45
Definition: mtsFunctionWriteReturn.h:38
bool ComponentStop(const std::string &processName, const std::string &componentName) const
Definition: mtsManagerComponentServices.h:172
mtsFunctionWrite Stop
Definition: mtsManagerComponentServices.h:46