cisst-saw
Loading...
Searching...
No Matches
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 Author(s): Min Yang Jung, Peter Kazanzides
6 Created on: 2010-08-29
7
8 (C) Copyright 2010-2026 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19#ifndef _mtsManagerComponentServices_h
20#define _mtsManagerComponentServices_h
21
29
30// Always include last
32
33// Allows a component pointer to be passed through command pattern.
34// There may be a better way to implement this.
36{
38 mtsComponent * component;
39
40public:
41 mtsComponentPointer() : component(0) {}
42 mtsComponentPointer(mtsComponent *cptr) : component(cptr) {}
44 void SetPointer(mtsComponent * cptr) { component = cptr; }
45 mtsComponent * GetPointer() const { return component; }
46
47 void ToStream(std::ostream & outputStream) const override;
48 void SerializeRaw(std::ostream & outputStream) const override;
49 void DeSerializeRaw(std::istream & inputStream) override;
50};
51
53
55
56protected:
58
60 // Dynamic component management
75
76 // Getters
88
89 // Event receivers
96
97 // private function used by WaitFor methods.
98 bool CheckAndWait(const std::vector<std::string> &list, const std::string &key, double &timeoutInSec,
99 mtsEventReceiverWrite &eventReceiver);
100public:
103
105
106 bool IsConnected(void) const
108
111 template <class __classType>
112 bool AddComponentEventHandler(void (__classType::*method)(const mtsDescriptionComponent &),
113 __classType * classInstantiation,
115 {
116 return (EventReceivers.AddComponent.SetHandler(method, classInstantiation, queueingPolicy) != 0);
117 }
118
119 template <class __classType>
120 bool AddConnectionEventHandler(void (__classType::*method)(const mtsDescriptionConnection &),
121 __classType * classInstantiation,
123 {
124 return (EventReceivers.AddConnection.SetHandler(method, classInstantiation, queueingPolicy) != 0);
125 }
126
127 template <class __classType>
128 bool RemoveConnectionEventHandler(void (__classType::*method)(const mtsDescriptionConnection &),
129 __classType * classInstantiation,
131 {
132 return (EventReceivers.RemoveConnection.SetHandler(method, classInstantiation, queueingPolicy) != 0);
133 }
134
135 template <class __classType>
136 bool ChangeStateEventHandler(void (__classType::*method)(const mtsComponentStateChange &),
137 __classType * classInstantiation,
139 {
140 return (EventReceivers.ChangeState.SetHandler(method, classInstantiation, queueingPolicy) != 0);
141 }
142
143
146 bool ComponentCreate(const std::string & className, const std::string & componentName) const;
147 bool ComponentCreate(const std::string & processName, const std::string & className,
148 const std::string & componentName) const;
149
150 bool ComponentCreate(const std::string & className, const mtsGenericObject & constructorArg) const;
152 const std::string& processName, const std::string & className, const mtsGenericObject & constructorArg) const;
153
154 bool ComponentAdd(const mtsComponent *component) const;
155 bool ComponentRemove(const mtsComponent *component) const;
156 bool ComponentRemove(const std::string &componentName) const;
157 mtsComponent *ComponentGet(const std::string &componentName) const;
158
159 bool ComponentConfigure(const std::string & componentName, const std::string & configString) const;
161 const std::string& processName, const std::string & componentName, const std::string & configString) const;
162
163 bool Connect(const std::string & clientComponentName, const std::string & clientInterfaceName,
164 const std::string & serverComponentName, const std::string & serverInterfaceName) const;
165 bool Connect(const std::string & clientProcessName,
166 const std::string & clientComponentName, const std::string & clientInterfaceName,
167 const std::string & serverProcessName,
168 const std::string & serverComponentName, const std::string & serverInterfaceName) const;
169 bool Connect(const mtsDescriptionConnection & connection) const;
170
172 const std::string & clientComponentName, const std::string & clientInterfaceName,
173 const std::string & serverComponentName, const std::string & serverInterfaceName) const;
175 const std::string & clientProcessName,
176 const std::string & clientComponentName, const std::string & clientInterfaceName,
177 const std::string & serverProcessName,
178 const std::string & serverComponentName, const std::string & serverInterfaceName) const;
179 bool Disconnect(const mtsDescriptionConnection & connection) const;
180 bool Disconnect(ConnectionIDType connectionID) const;
181
182 bool ComponentStart(const std::string & componentName, const double delayInSecond) const;
183 bool ComponentStart(const std::string & componentName) const
184 { return ComponentStart(componentName, 0.0); }
185 bool ComponentStart(const std::string& processName, const std::string & componentName,
186 const double delayInSecond) const;
187 bool ComponentStart(const std::string& processName, const std::string & componentName) const
188 { return ComponentStart(processName, componentName, 0.0); }
189
190
191 bool ComponentStop(const std::string & componentName, const double delayInSecond) const;
192 bool ComponentStop(const std::string & componentName) const
193 { return ComponentStop(componentName, 0.0); }
194 bool ComponentStop(const std::string& processName, const std::string & componentName,
195 const double delayInSecond) const;
196 bool ComponentStop(const std::string& processName, const std::string & componentName) const
197 { return ComponentStop(processName, componentName, 0.0); }
198
199 bool ComponentResume(const std::string & componentName, const double delayInSecond = 0.0) const;
200 bool ComponentResume(const std::string& processName, const std::string & componentName,
201 const double delayInSecond = 0.0) const;
202
204 std::string ComponentGetState(const std::string componentName) const;
205 std::string ComponentGetState(const std::string & processName, const std::string componentName) const;
206
207 std::vector<std::string> GetNamesOfProcesses(void) const;
208 std::vector<std::string> GetNamesOfComponents(const std::string & processName) const;
209 std::vector<std::string> GetNamesOfComponents(void) const
210 { return GetNamesOfComponents(""); }
211 std::vector<mtsDescriptionComponent> GetDescriptionsOfComponents(const std::string & processName) const;
212 bool GetNamesOfInterfaces(const std::string & processName,
213 const std::string & componentName,
214 std::vector<std::string> & namesOfInterfacesRequired,
215 std::vector<std::string> & namesOfInterfacesProvided) const;
216
217 bool GetDescriptionsOfInterfaces(const std::string & processName,
218 const std::string & componentName,
219 std::vector<mtsDescriptionInterfaceFullName> & descriptionsRequired,
220 std::vector<mtsDescriptionInterfaceFullName> & descriptionsProvided) const;
221
222 std::vector<mtsDescriptionConnection> GetListOfConnections(void) const;
223
224 std::vector<mtsDescriptionComponentClass> GetListOfComponentClasses(const std::string & processName = "") const;
225
227 GetInterfaceProvidedDescription(const std::string & processName,
228 const std::string & componentName, const std::string & interfaceName) const;
229
231 GetInterfaceProvidedDescription(const std::string & componentName, const std::string & interfaceName) const {
232 return GetInterfaceProvidedDescription("", componentName, interfaceName);
233 }
234
237 return GetInterfaceProvidedDescription(interfaceDescription.ProcessName,
238 interfaceDescription.ComponentName,
239 interfaceDescription.InterfaceName);
240 }
241
243 GetInterfaceRequiredDescription(const std::string & processName,
244 const std::string & componentName, const std::string & interfaceName) const;
246 GetInterfaceRequiredDescription(const std::string & componentName, const std::string & interfaceName) const {
247 return GetInterfaceRequiredDescription("", componentName, interfaceName);
248 }
249
252 return GetInterfaceRequiredDescription(interfaceDescription.ProcessName,
253 interfaceDescription.ComponentName,
254 interfaceDescription.InterfaceName);
255 }
256
257 // Dynamically load the file (fileName) into the current process
258 bool Load(const std::string & fileName) const;
259 // Dynamically load the file (fileName) into the process processName
260 bool Load(const std::string & processName, const std::string & fileName) const;
261
262 // Wait for component state change. This can be used to wait for a process to be created, or for a component
263 // to be created (in those cases, any state is acceptable). A negative timeout is used to wait indefinitely.
264 // Returns false if timeout occurred.
265 bool WaitFor(const std::string & processName, double timeoutInSec = -1.0);
266 bool WaitFor(const std::string & processName, const std::string & componentName, double timeoutInSec = -1.0);
267 bool WaitFor(const std::string & processName, const std::string & componentName, const std::string & state,
268 double timeoutInSec = -1.0);
270
271};
272
275
276#endif // _mtsManagerComponentServices_h
Base class for high level objects.
Definition cmnGenericObject.h:53
Definition mtsComponent.h:150
Definition mtsManagerComponentServices.h:36
void ToStream(std::ostream &outputStream) const override
~mtsComponentPointer()
Definition mtsManagerComponentServices.h:43
void DeSerializeRaw(std::istream &inputStream) override
mtsComponentPointer(mtsComponent *cptr)
Definition mtsManagerComponentServices.h:42
mtsComponentPointer()
Definition mtsManagerComponentServices.h:41
mtsComponent * GetPointer() const
Definition mtsManagerComponentServices.h:45
void SetPointer(mtsComponent *cptr)
Definition mtsManagerComponentServices.h:44
void SerializeRaw(std::ostream &outputStream) const override
Definition mtsParameterTypes.h:869
Definition mtsComponentState.h:34
Definition mtsParameterTypes.h:58
Definition mtsParameterTypes.h:624
Definition mtsParameterTypes.h:397
std::string ProcessName
Definition mtsParameterTypes.h:407
std::string InterfaceName
Definition mtsParameterTypes.h:413
std::string ComponentName
Definition mtsParameterTypes.h:410
Definition mtsEventReceiver.h:221
Definition mtsFunctionQualifiedRead.h:37
Definition mtsFunctionRead.h:37
Definition mtsFunctionWrite.h:37
Definition mtsFunctionWriteReturn.h:38
Base class for data object in cisstMultiTask.
Definition mtsGenericObject.h:52
mtsGenericObject(void)
Definition mtsGenericObject.h:77
Definition mtsInterfaceCommon.h:888
Definition mtsInterfaceCommon.h:1007
Definition mtsInterfaceRequired.h:83
const mtsInterfaceProvided * GetConnectedInterface(void) const
Definition mtsManagerComponentServices.h:52
mtsInterfaceProvidedDescription GetInterfaceProvidedDescription(const std::string &componentName, const std::string &interfaceName) const
Definition mtsManagerComponentServices.h:231
bool ComponentRemove(const mtsComponent *component) const
std::string ComponentGetState(const std::string componentName) const
mtsComponentState ComponentGetState(const mtsDescriptionComponent &component) const
bool Disconnect(const std::string &clientProcessName, const std::string &clientComponentName, const std::string &clientInterfaceName, const std::string &serverProcessName, const std::string &serverComponentName, const std::string &serverInterfaceName) const
std::vector< std::string > GetNamesOfComponents(const std::string &processName) const
bool ComponentResume(const std::string &componentName, const double delayInSecond=0.0) const
std::vector< std::string > GetNamesOfComponents(void) const
Definition mtsManagerComponentServices.h:209
bool ChangeStateEventHandler(void(__classType::*method)(const mtsComponentStateChange &), __classType *classInstantiation, mtsEventQueueingPolicy queueingPolicy=MTS_INTERFACE_EVENT_POLICY)
Definition mtsManagerComponentServices.h:136
mtsInterfaceProvidedDescription GetInterfaceProvidedDescription(const std::string &processName, const std::string &componentName, const std::string &interfaceName) const
bool Disconnect(const std::string &clientComponentName, const std::string &clientInterfaceName, const std::string &serverComponentName, const std::string &serverInterfaceName) const
bool Disconnect(ConnectionIDType connectionID) const
bool Load(const std::string &fileName) const
mtsInterfaceRequiredDescription GetInterfaceRequiredDescription(const mtsDescriptionInterfaceFullName &interfaceDescription) const
Definition mtsManagerComponentServices.h:251
bool AddConnectionEventHandler(void(__classType::*method)(const mtsDescriptionConnection &), __classType *classInstantiation, mtsEventQueueingPolicy queueingPolicy=MTS_INTERFACE_EVENT_POLICY)
Definition mtsManagerComponentServices.h:120
bool Connect(const std::string &clientProcessName, const std::string &clientComponentName, const std::string &clientInterfaceName, const std::string &serverProcessName, const std::string &serverComponentName, const std::string &serverInterfaceName) const
bool GetDescriptionsOfInterfaces(const std::string &processName, const std::string &componentName, std::vector< mtsDescriptionInterfaceFullName > &descriptionsRequired, std::vector< mtsDescriptionInterfaceFullName > &descriptionsProvided) const
bool ComponentResume(const std::string &processName, const std::string &componentName, const double delayInSecond=0.0) const
bool ComponentCreate(const std::string &className, const std::string &componentName) const
bool WaitFor(const std::string &processName, const std::string &componentName, const std::string &state, double timeoutInSec=-1.0)
mtsInterfaceRequired * InternalInterfaceRequired
Definition mtsManagerComponentServices.h:57
std::vector< mtsDescriptionComponent > GetDescriptionsOfComponents(const std::string &processName) const
bool ComponentStop(const std::string &componentName) const
Definition mtsManagerComponentServices.h:192
bool ComponentStart(const std::string &processName, const std::string &componentName, const double delayInSecond) const
mtsInterfaceRequiredDescription GetInterfaceRequiredDescription(const std::string &processName, const std::string &componentName, const std::string &interfaceName) const
bool ComponentConfigure(const std::string &componentName, const std::string &configString) const
bool ComponentStart(const std::string &processName, const std::string &componentName) const
Definition mtsManagerComponentServices.h:187
bool ComponentConfigure(const std::string &processName, const std::string &componentName, const std::string &configString) const
mtsInterfaceRequiredDescription GetInterfaceRequiredDescription(const std::string &componentName, const std::string &interfaceName) const
Definition mtsManagerComponentServices.h:246
bool Load(const std::string &processName, const std::string &fileName) const
bool ComponentStop(const std::string &processName, const std::string &componentName, const double delayInSecond) const
std::vector< mtsDescriptionConnection > GetListOfConnections(void) const
bool Disconnect(const mtsDescriptionConnection &connection) const
bool ComponentRemove(const std::string &componentName) const
std::vector< mtsDescriptionComponentClass > GetListOfComponentClasses(const std::string &processName="") const
bool ComponentStop(const std::string &componentName, const double delayInSecond) const
bool RemoveConnectionEventHandler(void(__classType::*method)(const mtsDescriptionConnection &), __classType *classInstantiation, mtsEventQueueingPolicy queueingPolicy=MTS_INTERFACE_EVENT_POLICY)
Definition mtsManagerComponentServices.h:128
bool ComponentStop(const std::string &processName, const std::string &componentName) const
Definition mtsManagerComponentServices.h:196
bool InitializeInterfaceInternalRequired(void)
std::string ComponentGetState(const std::string &processName, const std::string componentName) const
~mtsManagerComponentServices()
Definition mtsManagerComponentServices.h:102
bool ComponentCreate(const std::string &processName, const std::string &className, const mtsGenericObject &constructorArg) const
bool AddComponentEventHandler(void(__classType::*method)(const mtsDescriptionComponent &), __classType *classInstantiation, mtsEventQueueingPolicy queueingPolicy=MTS_INTERFACE_EVENT_POLICY)
Definition mtsManagerComponentServices.h:112
bool ComponentStart(const std::string &componentName) const
Definition mtsManagerComponentServices.h:183
bool Connect(const std::string &clientComponentName, const std::string &clientInterfaceName, const std::string &serverComponentName, const std::string &serverInterfaceName) const
struct mtsManagerComponentServices::EventStruct EventReceivers
std::vector< std::string > GetNamesOfProcesses(void) const
bool ComponentCreate(const std::string &className, const mtsGenericObject &constructorArg) const
bool WaitFor(const std::string &processName, double timeoutInSec=-1.0)
mtsComponent * ComponentGet(const std::string &componentName) const
bool CheckAndWait(const std::vector< std::string > &list, const std::string &key, double &timeoutInSec, mtsEventReceiverWrite &eventReceiver)
mtsManagerComponentServices(mtsInterfaceRequired *internalInterfaceRequired)
bool Connect(const mtsDescriptionConnection &connection) const
bool ComponentAdd(const mtsComponent *component) const
bool ComponentStart(const std::string &componentName, const double delayInSecond) const
bool GetNamesOfInterfaces(const std::string &processName, const std::string &componentName, std::vector< std::string > &namesOfInterfacesRequired, std::vector< std::string > &namesOfInterfacesProvided) const
bool WaitFor(const std::string &processName, const std::string &componentName, double timeoutInSec=-1.0)
mtsInterfaceProvidedDescription GetInterfaceProvidedDescription(const mtsDescriptionInterfaceFullName &interfaceDescription) const
Definition mtsManagerComponentServices.h:236
bool IsConnected(void) const
Definition mtsManagerComponentServices.h:106
bool ComponentCreate(const std::string &processName, const std::string &className, const std::string &componentName) const
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition cmnClassRegisterMacros.h:199
const int CMN_NO_DYNAMIC_CREATION
Definition cmnClassRegisterMacros.h:325
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition cmnClassRegisterMacros.h:113
const int CMN_DYNAMIC_CREATION
Definition cmnClassRegisterMacros.h:328
#define CISST_EXPORT
Definition cmnExportMacros.h:50
#define CMN_LOG_ALLOW_DEFAULT
Definition cmnLogLoD.h:76
Declaration of mtsEventReceiverBase, mtsEventReceiverVoid, and mtsEventReceiverWrite.
Rules of exporting.
mtsEventQueueingPolicy
Definition mtsForwardDeclarations.h:48
@ MTS_INTERFACE_EVENT_POLICY
Definition mtsForwardDeclarations.h:48
unsigned int ConnectionIDType
Definition mtsForwardDeclarations.h:149
Defines the command interfaces.
Defines the command interfaces.
Defines the command interfaces.
Declaration of mtsInterfaceRequired.
Declaration of Base Class for Manager Components.
Definition mtsManagerComponentServices.h:90
mtsEventReceiverWrite AddComponent
Definition mtsManagerComponentServices.h:91
mtsEventReceiverWrite AddConnection
Definition mtsManagerComponentServices.h:92
mtsEventReceiverWrite ChangeState
Definition mtsManagerComponentServices.h:94
mtsEventReceiverWrite RemoveConnection
Definition mtsManagerComponentServices.h:93
Definition mtsManagerComponentServices.h:77
mtsFunctionQualifiedRead GetNamesOfInterfaces
Definition mtsManagerComponentServices.h:81
mtsFunctionQualifiedRead GetDescriptionsOfInterfaces
Definition mtsManagerComponentServices.h:82
mtsFunctionRead GetNamesOfProcesses
Definition mtsManagerComponentServices.h:78
mtsFunctionQualifiedRead GetInterfaceProvidedDescription
Definition mtsManagerComponentServices.h:85
mtsFunctionQualifiedRead GetListOfComponentClasses
Definition mtsManagerComponentServices.h:84
mtsFunctionQualifiedRead GetInterfaceRequiredDescription
Definition mtsManagerComponentServices.h:86
mtsFunctionRead GetListOfConnections
Definition mtsManagerComponentServices.h:83
mtsFunctionQualifiedRead GetNamesOfComponents
Definition mtsManagerComponentServices.h:79
mtsFunctionQualifiedRead GetDescriptionsOfComponents
Definition mtsManagerComponentServices.h:80
Definition mtsManagerComponentServices.h:61
mtsFunctionQualifiedRead GetState
Definition mtsManagerComponentServices.h:72
mtsFunctionWriteReturn Add
Definition mtsManagerComponentServices.h:63
mtsFunctionWrite Start
Definition mtsManagerComponentServices.h:69
mtsFunctionWriteReturn Disconnect
Definition mtsManagerComponentServices.h:68
mtsFunctionQualifiedRead LoadLibrary
Definition mtsManagerComponentServices.h:73
mtsFunctionWriteReturn Connect
Definition mtsManagerComponentServices.h:67
mtsFunctionQualifiedRead Get
Definition mtsManagerComponentServices.h:65
mtsFunctionWrite Stop
Definition mtsManagerComponentServices.h:70
mtsFunctionWrite Configure
Definition mtsManagerComponentServices.h:66
mtsFunctionWriteReturn Create
Definition mtsManagerComponentServices.h:62
mtsFunctionWriteReturn Remove
Definition mtsManagerComponentServices.h:64
mtsFunctionWrite Resume
Definition mtsManagerComponentServices.h:71