cisst-saw
Loading...
Searching...
No Matches
mtsManagerLocal.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
6 Created on: 2009-12-07
7
8 (C) Copyright 2009-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
31
32#ifndef _mtsManagerLocal_h
33#define _mtsManagerLocal_h
34
35#include <string>
36#include <set>
37#include <stack>
38
40#include <cisstCommon/cmnPath.h>
45
47
48// Forward declaration
49class ManagerLocalComponent;
50
52{
54
55private:
57 std::set<std::string> ValidComponentTags;
59 std::set<std::string> ValidInterfaceTags;
60
62 static mtsManagerLocal * Instance;
63
66 osaThreadId MainThreadId;
67
70 std::string ProcessName;
71
74 std::string Name;
75
77 mtsManagerComponent *ManagerComponent;
78
80 osaThread LogThread;
81 osaThreadSignal LogThreadFinished;
82 bool LogThreadFinishWaiting;
83 void* LogDispatchThread(void * arg);
84
85protected:
88
91
93 void Initialize(void);
94
97
100
101 /* Local component */
102 ManagerLocalComponent * LocalComponent;
103
106 const std::string & componentName,
107 const std::string & interfaceName,
108 mtsInterfaceProvidedDescription & interfaceProvidedDescription);
109
113 const std::string & componentName,
114 const std::string & interfaceName,
115 mtsInterfaceRequiredDescription & interfaceRequiredDescription);
116
119
120public:
121
125
130 void Cleanup(void);
131
139 static void DeleteInstance(void);
140
142 inline const std::string CISST_DEPRECATED GetName(void) const {
143 return Name;
144 }
145
146 //------------------------------------------------------------------------------
147 // Access to underlying services.
148 //
149 // In most cases, it easier to instead call a method of this class, e.g.,
150 // LCM->AddComponent(component)
151 // rather than
152 // LCM->GetManagerServices()->ComponentAdd(component)
153 //
154 //------------------------------------------------------------------------------
155
160
164 const ManagerLocalComponent * GetLoggerServices() const;
165
166 //-------------------------------------------------------------------------
167 // Component Management
168 //-------------------------------------------------------------------------
171 mtsComponent * CreateComponentDynamically(const std::string & className, const std::string & componentName,
172 const std::string & constructorArgSerialized);
173
176 mtsComponent * CreateComponentDynamically(const std::string & className,
177 const mtsGenericObject & constructorArg);
178
179#if CISST_HAS_JSON
185 bool ConfigureJSON(const std::string & filename);
186 bool ConfigureJSON(const std::list<std::string> & filenames);
187
194 bool ConfigureJSON(const Json::Value & configuration, const cmnPath & configPath);
195
202 bool ConfigureComponentJSON(const Json::Value & componentConfiguration, const cmnPath & configPath);
203
207 bool ConfigureConnectionJSON(const Json::Value & connectionConfiguration);
208
216 mtsComponent * CreateComponentDynamicallyJSON(const std::string & sharedLibrary,
217 const std::string & className,
218 const std::string & constructorArgSerialized);
219#endif
220
223 bool AddComponent(mtsComponent * component);
224 bool CISST_DEPRECATED AddTask(mtsTask * component); // For backward compatibility
225 bool CISST_DEPRECATED AddDevice(mtsComponent * component); // For backward compatibility
226
228 bool RemoveComponent(mtsComponent * component);
229 bool RemoveComponent(const std::string & componentName);
230
234
236 mtsComponent * GetComponent(const std::string & componentName) const;
237 mtsTask * GetComponentAsTask(const std::string & componentName) const;
238
239 mtsComponent CISST_DEPRECATED * GetDevice(const std::string & deviceName); // For backward compatibility
240 mtsTask CISST_DEPRECATED * GetTask(const std::string & taskName); // For backward compatibility
241
243 bool FindComponent(const std::string & componentName) const;
244
248 bool WaitForStateAll(mtsComponentState desiredState, double timeout = 3.0 * cmn_minute) const;
249
252 void CreateAll(void);
253
255 bool CreateAllAndWait(double timeoutInSeconds);
256
259 void StartAll(void);
260
262 bool StartAllAndWait(double timeoutInSeconds);
263
266 void KillAll(void);
267
269 bool KillAllAndWait(double timeoutInSeconds);
270
271 //-------------------------------------------------------------------------
272 // Connection Management
273 //-------------------------------------------------------------------------
283 bool Connect(const std::string & clientComponentName, const std::string & clientInterfaceRequiredName,
284 const std::string & serverComponentName, const std::string & serverInterfaceProvidedName);
285
308 bool Connect(const std::string & clientProcessName, const std::string & clientComponentName,
309 const std::string & clientInterfaceRequiredName,
310 const std::string & serverProcessName, const std::string & serverComponentName,
311 const std::string & serverInterfaceProvidedName);
312
314 bool Disconnect(const ConnectionIDType connectionID);
315
316 bool Disconnect(const std::string & clientComponentName, const std::string & clientInterfaceRequiredName,
317 const std::string & serverComponentName, const std::string & serverInterfaceProvidedName);
318
319 bool Disconnect(const std::string & clientProcessName, const std::string & clientComponentName,
320 const std::string & clientInterfaceRequiredName,
321 const std::string & serverProcessName, const std::string & serverComponentName,
322 const std::string & serverInterfaceProvidedName);
323
324 //-------------------------------------------------------------------------
325 // Getters and Utilities
326 //-------------------------------------------------------------------------
327
329 inline const std::string GetProcessName(void) const {
330 return ProcessName;
331 }
332
334 void GetNamesOfProcesses(std::vector<std::string>& namesOfProcesses) const;
335
337 std::vector<std::string> GetNamesOfComponents(void) const;
338 void GetNamesOfComponents(std::vector<std::string>& namesOfComponents) const;
339 void GetNamesOfComponents(const std::string & processName,
340 std::vector<std::string>& namesOfComponents) const;
341
342 std::vector<mtsDescriptionComponent> GetDescriptionsOfComponents(const std::string & processName = "") const;
343
344 bool GetNamesOfInterfaces(const std::string & processName,
345 const std::string & componentName,
346 std::vector<std::string> & namesOfInterfacesRequired,
347 std::vector<std::string> & namesOfInterfacesProvided) const;
348
349 bool GetNamesOfInterfaces(const std::string & componentName,
350 std::vector<std::string> & namesOfInterfacesRequired,
351 std::vector<std::string> & namesOfInterfacesProvided) const
352 { return GetNamesOfInterfaces("", componentName, namesOfInterfacesRequired, namesOfInterfacesProvided); }
353
354 bool GetDescriptionsOfInterfaces(const std::string & processName,
355 const std::string & componentName,
356 std::vector<mtsDescriptionInterfaceFullName> & descriptionsRequired,
357 std::vector<mtsDescriptionInterfaceFullName> & descriptionsProvided) const;
358
359 bool GetDescriptionsOfInterfaces(const std::string & componentName,
360 std::vector<mtsDescriptionInterfaceFullName> & descriptionsRequired,
361 std::vector<mtsDescriptionInterfaceFullName> & descriptionsProvided) const
362 { return GetDescriptionsOfInterfaces("", componentName, descriptionsRequired, descriptionsProvided); }
363
364 std::vector<mtsDescriptionConnection> GetListOfConnections(void) const;
365
366 std::vector<mtsDescriptionComponentClass> GetListOfComponentClasses(const std::string & processName = "") const;
367
369 const std::string & componentName, const std::string & interfaceName) const;
370
371 mtsInterfaceProvidedDescription GetInterfaceProvidedDescription(const std::string & componentName, const std::string & interfaceName) const
372 { return GetInterfaceProvidedDescription("", componentName, interfaceName); }
373
375 const std::string & componentName, const std::string & interfaceName) const;
376 mtsInterfaceRequiredDescription GetInterfaceRequiredDescription(const std::string & componentName, const std::string & interfaceName) const
377 { return GetInterfaceRequiredDescription("", componentName, interfaceName); }
378
380 const osaTimeServer & GetTimeServer(void) const;
381
382 //---------------------------------------------------------------------------------------------
383 // Methods to track the "main" thread, which actually is the thread in which the Instance
384 // of this class was created. In most cases, that will be the main thread of the process.
385
389 void SetMainThreadId(void) { MainThreadId = osaGetCurrentThreadId(); }
390
394 void SetMainThreadId(const osaThreadId &threadId) { MainThreadId = threadId; }
395
397 osaThreadId GetMainThreadId(void) const { return MainThreadId; }
398
399 //---------------------------------------------------------------------------------------------
400
402 void GetNamesOfCommands(std::vector<std::string>& namesOfCommands,
403 const std::string & componentName,
404 const std::string & providedInterfaceName);
405
407 void GetNamesOfEventGenerators(std::vector<std::string>& namesOfEventGenerators,
408 const std::string & componentName,
409 const std::string & providedInterfaceName);
410
412 void GetNamesOfFunctions(std::vector<std::string>& namesOfFunctions,
413 const std::string & componentName,
414 const std::string & requiredInterfaceName);
415
417 void GetNamesOfEventHandlers(std::vector<std::string>& namesOfEventHandlers,
418 const std::string & componentName,
419 const std::string & requiredInterfaceName);
420
422 void GetDescriptionOfCommand(std::string & description,
423 const std::string & componentName,
424 const std::string & providedInterfaceName,
425 const std::string & commandName);
426
428 void GetDescriptionOfEventGenerator(std::string & description,
429 const std::string & componentName,
430 const std::string & providedInterfaceName,
431 const std::string & eventGeneratorName);
432
434 void GetDescriptionOfFunction(std::string & description,
435 const std::string & componentName,
436 const std::string & requiredInterfaceName,
437 const std::string & functionName);
438
440 void GetDescriptionOfEventHandler(std::string & description,
441 const std::string & componentName,
442 const std::string & requiredInterfaceName,
443 const std::string & eventHandlerName);
444
446 inline std::string CISST_DEPRECATED GetIPAddress(void) const { return ""; }
447
449 static std::vector<std::string> GetIPAddressList(void);
450 static void GetIPAddressList(std::vector<std::string> & ipAddresses);
451
455
457 static bool IsLogForwardingEnabled(void);
458
462 static void SetLogForwarding(bool activate);
463
465 static void GetLogForwardingState(bool & state);
466 static bool GetLogForwardingState(void);
467
469 static void LogDispatcher(const char * str, int len);
470
471 // TODO: should the following be moved somewhere else?
472 bool IsValidComponentTag(const std::string & tag) const;
473 bool IsValidInterfaceTag(const std::string & tag) const;
474 void AddValidComponentTag(const std::string & tag);
475 void AddValidInterfaceTag(const std::string & tag);
476 const std::set<std::string> & GetValidComponentTags(void) const;
477 const std::set<std::string> & GetValidInterfaceTags(void) const;
478};
479
481
482#endif // _mtsManagerLocal_h
Base class for high level objects.
Definition cmnGenericObject.h:53
Search path to find a file. This class contains a list of directories used to locate a file.
Definition cmnPath.h:66
Definition mtsComponent.h:150
Definition mtsComponentState.h:34
Base class for data object in cisstMultiTask.
Definition mtsGenericObject.h:52
Definition mtsInterfaceCommon.h:888
Definition mtsInterfaceCommon.h:1007
Definition mtsManagerComponent.h:48
Definition mtsManagerComponentServices.h:52
Definition mtsManagerLocal.h:52
void GetDescriptionOfCommand(std::string &description, const std::string &componentName, const std::string &providedInterfaceName, const std::string &commandName)
std::vector< std::string > GetNamesOfComponents(void) const
bool CreateManagerComponent(void)
Create internal manager component.
void GetNamesOfEventGenerators(std::vector< std::string > &namesOfEventGenerators, const std::string &componentName, const std::string &providedInterfaceName)
void SetMainThreadId(void)
Definition mtsManagerLocal.h:389
void GetNamesOfComponents(const std::string &processName, std::vector< std::string > &namesOfComponents) const
void AddValidInterfaceTag(const std::string &tag)
std::vector< mtsDescriptionComponent > GetDescriptionsOfComponents(const std::string &processName="") const
const std::string CISST_DEPRECATED GetName(void) const
Definition mtsManagerLocal.h:142
mtsInterfaceRequiredDescription GetInterfaceRequiredDescription(const std::string &processName, const std::string &componentName, const std::string &interfaceName) const
bool RemoveComponent(const std::string &componentName)
bool KillAllAndWait(double timeoutInSeconds)
const osaTimeServer & GetTimeServer(void) const
bool WaitForStateAll(mtsComponentState desiredState, double timeout=3.0 *cmn_minute) const
mtsComponent * CreateComponentDynamically(const std::string &className, const std::string &componentName, const std::string &constructorArgSerialized)
Create a component. Does not add it to the local component manager. In this method,...
bool Connect(const std::string &clientProcessName, const std::string &clientComponentName, const std::string &clientInterfaceRequiredName, const std::string &serverProcessName, const std::string &serverComponentName, const std::string &serverInterfaceProvidedName)
Connect two remote interfaces.
void GetInterfaceProvidedDescription(const std::string &componentName, const std::string &interfaceName, mtsInterfaceProvidedDescription &interfaceProvidedDescription)
bool Disconnect(const ConnectionIDType connectionID)
mtsComponent CISST_DEPRECATED * GetDevice(const std::string &deviceName)
static void GetIPAddressList(std::vector< std::string > &ipAddresses)
bool RemoveComponent(mtsComponent *component)
Remove component from component manager.
bool Disconnect(const std::string &clientComponentName, const std::string &clientInterfaceRequiredName, const std::string &serverComponentName, const std::string &serverInterfaceProvidedName)
void StartAll(void)
Start all components. If a component is of type mtsTask, mtsTask::Start() is called internally.
void GetInterfaceRequiredDescription(const std::string &componentName, const std::string &interfaceName, mtsInterfaceRequiredDescription &interfaceRequiredDescription)
void GetNamesOfProcesses(std::vector< std::string > &namesOfProcesses) const
static std::vector< std::string > GetIPAddressList(void)
void GetNamesOfFunctions(std::vector< std::string > &namesOfFunctions, const std::string &componentName, const std::string &requiredInterfaceName)
const mtsManagerComponentServices * GetManagerComponentServices() const
void AddValidComponentTag(const std::string &tag)
void Cleanup(void)
Cleanup. Left in the public API for backwards compatibility. Client code should not call this method ...
void DestroyManagerComponent(void)
Destroy internal manager component.
void CreateAll(void)
Create all components. If a component is of type mtsTask, mtsTask::Create() is called internally.
bool GetDescriptionsOfInterfaces(const std::string &componentName, std::vector< mtsDescriptionInterfaceFullName > &descriptionsRequired, std::vector< mtsDescriptionInterfaceFullName > &descriptionsProvided) const
Definition mtsManagerLocal.h:359
void GetNamesOfComponents(std::vector< std::string > &namesOfComponents) const
static void DeleteInstance(void)
DeleteInstance. Since a local component manager is a singleton, and demand-created by the first calle...
const ManagerLocalComponent * GetLoggerServices() const
bool StartAllAndWait(double timeoutInSeconds)
std::string CISST_DEPRECATED GetIPAddress(void) const
Definition mtsManagerLocal.h:446
const std::set< std::string > & GetValidInterfaceTags(void) const
static bool GetLogForwardingState(void)
bool AddComponent(mtsComponent *component)
Add a component to the component manager.
virtual ~mtsManagerLocal()
static bool IsLogForwardingEnabled(void)
static void SetLogForwarding(bool activate)
bool FindComponent(const std::string &componentName) const
Check if a component exists by its name.
const std::string GetProcessName(void) const
Definition mtsManagerLocal.h:329
mtsInterfaceRequiredDescription GetInterfaceRequiredDescription(const std::string &componentName, const std::string &interfaceName) const
Definition mtsManagerLocal.h:376
bool IsValidInterfaceTag(const std::string &tag) const
bool CreateAllAndWait(double timeoutInSeconds)
void GetNamesOfCommands(std::vector< std::string > &namesOfCommands, const std::string &componentName, const std::string &providedInterfaceName)
mtsComponent * GetComponent(const std::string &componentName) const
Retrieve a component by name.
void SetMainThreadId(const osaThreadId &threadId)
Definition mtsManagerLocal.h:394
mtsComponent * CreateComponentDynamically(const std::string &className, const mtsGenericObject &constructorArg)
Create a component. Does not add it to the local component manager. In this method,...
void GetNamesOfEventHandlers(std::vector< std::string > &namesOfEventHandlers, const std::string &componentName, const std::string &requiredInterfaceName)
static bool CISST_DEPRECATED IsLogAllowed(void)
void GetDescriptionOfEventHandler(std::string &description, const std::string &componentName, const std::string &requiredInterfaceName, const std::string &eventHandlerName)
bool GetDescriptionsOfInterfaces(const std::string &processName, const std::string &componentName, std::vector< mtsDescriptionInterfaceFullName > &descriptionsRequired, std::vector< mtsDescriptionInterfaceFullName > &descriptionsProvided) const
mtsTask * GetComponentAsTask(const std::string &componentName) const
static void LogDispatcher(const char *str, int len)
bool GetNamesOfInterfaces(const std::string &processName, const std::string &componentName, std::vector< std::string > &namesOfInterfacesRequired, std::vector< std::string > &namesOfInterfacesProvided) const
mtsTask CISST_DEPRECATED * GetTask(const std::string &taskName)
static void GetLogForwardingState(bool &state)
std::vector< mtsDescriptionComponentClass > GetListOfComponentClasses(const std::string &processName="") const
bool Connect(const std::string &clientComponentName, const std::string &clientInterfaceRequiredName, const std::string &serverComponentName, const std::string &serverInterfaceProvidedName)
Connect two local interfaces.
bool Disconnect(const std::string &clientProcessName, const std::string &clientComponentName, const std::string &clientInterfaceRequiredName, const std::string &serverProcessName, const std::string &serverComponentName, const std::string &serverInterfaceProvidedName)
void GetDescriptionOfFunction(std::string &description, const std::string &componentName, const std::string &requiredInterfaceName, const std::string &functionName)
bool GetNamesOfInterfaces(const std::string &componentName, std::vector< std::string > &namesOfInterfacesRequired, std::vector< std::string > &namesOfInterfacesProvided) const
Definition mtsManagerLocal.h:349
static mtsManagerLocal * GetInstance(void)
size_t RemoveAllUserComponents(void)
Remove all user components from this local component manager.
mtsInterfaceProvidedDescription GetInterfaceProvidedDescription(const std::string &componentName, const std::string &interfaceName) const
Definition mtsManagerLocal.h:371
bool CISST_DEPRECATED AddTask(mtsTask *component)
void KillAll(void)
Stop all components. If a component is of type mtsTask, mtsTask::Kill() is called internally.
ManagerLocalComponent * LocalComponent
Definition mtsManagerLocal.h:102
mtsInterfaceProvidedDescription GetInterfaceProvidedDescription(const std::string &processName, const std::string &componentName, const std::string &interfaceName) const
void SetupSystemLogger(void)
bool IsValidComponentTag(const std::string &tag) const
osaThreadId GetMainThreadId(void) const
Definition mtsManagerLocal.h:397
std::vector< mtsDescriptionConnection > GetListOfConnections(void) const
void Initialize(void)
const std::set< std::string > & GetValidComponentTags(void) const
void GetDescriptionOfEventGenerator(std::string &description, const std::string &componentName, const std::string &providedInterfaceName, const std::string &eventGeneratorName)
bool CISST_DEPRECATED AddDevice(mtsComponent *component)
Definition mtsTask.h:60
Define a thread object.
Definition osaThread.h:168
ThreadId type.
Definition osaThread.h:77
Definition osaThreadSignal.h:41
Class for relative time.
Definition osaTimeServer.h:74
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition cmnClassRegisterMacros.h:199
const int CMN_NO_DYNAMIC_CREATION
Definition cmnClassRegisterMacros.h:325
#define CISST_EXPORT
Definition cmnExportMacros.h:50
#define CMN_LOG_ALLOW_DEFAULT
Definition cmnLogLoD.h:76
Declaration of cmnPath.
#define CISST_DEPRECATED
Definition cmnPortability.h:314
Declaration of units and unit conversion methods.
const double cmn_minute
Definition cmnUnits.h:217
Declaration of mtsComponent.
Rules of exporting.
Forward declarations and #define for cisstMultiTask.
unsigned int ConnectionIDType
Definition mtsForwardDeclarations.h:149
Declaration of osaThread.
CISST_EXPORT osaThreadId osaGetCurrentThreadId(void)