File size: 7,861 Bytes
68ce2fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-    */
/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */

/*

  Author(s):  Anton Deguet, Min Yang Jung
  Created on: 2010-08-29

  (C) Copyright 2010-2026 Johns Hopkins University (JHU), All Rights Reserved.

--- begin cisst license - do not edit ---

This software is provided "as is" under an open source license, with
no warranty.  The complete license can be found in license.txt and
http://www.cisst.org/cisst/license.txt.

--- end cisst license ---
*/

#include <cisstMultiTask/mtsManagerComponentBase.h>
#include <cisstMultiTask/mtsInterfaceProvided.h>
#include <cisstMultiTask/mtsInterfaceRequired.h>

// MJ: If naming convention changes, all the check and getter methods should be updated accordingly.
// Names of components
const std::string mtsManagerComponentBase::ComponentNames::ManagerComponent = "MCS";
const std::string mtsManagerComponentBase::ComponentNames::ManagerLocal = "LCM";
// Names of interfaces
const std::string mtsManagerComponentBase::InterfaceNames::InterfaceInternalProvided  = "InterfaceInternalProvided";
const std::string mtsManagerComponentBase::InterfaceNames::InterfaceInternalRequired  = "InterfaceInternalRequired";
const std::string mtsManagerComponentBase::InterfaceNames::InterfaceComponentProvided = "InterfaceComponentProvided";
const std::string mtsManagerComponentBase::InterfaceNames::InterfaceComponentRequired = "InterfaceComponentRequired";
const std::string mtsManagerComponentBase::InterfaceNames::InterfaceSystemLoggerProvided = "InterfaceSystemLoggerProvided";
const std::string mtsManagerComponentBase::InterfaceNames::InterfaceSystemLoggerRequired = "InterfaceSystemLoggerRequired";
const std::string mtsManagerComponentBase::InterfaceNames::InterfaceExecIn = "ExecIn";
const std::string mtsManagerComponentBase::InterfaceNames::InterfaceExecOut = "ExecOut";
// Names of commands
const std::string mtsManagerComponentBase::CommandNames::ComponentCreate  = "ComponentCreate";
const std::string mtsManagerComponentBase::CommandNames::ComponentAdd  = "ComponentAdd";
const std::string mtsManagerComponentBase::CommandNames::ComponentRemove  = "ComponentRemove";
const std::string mtsManagerComponentBase::CommandNames::ComponentGet  = "ComponentGet";
const std::string mtsManagerComponentBase::CommandNames::ComponentConfigure  = "ComponentConfigure";
const std::string mtsManagerComponentBase::CommandNames::ComponentConnect = "Connect";
const std::string mtsManagerComponentBase::CommandNames::ComponentDisconnect = "Disconnect";
const std::string mtsManagerComponentBase::CommandNames::ComponentStart   = "ComponentStart";
const std::string mtsManagerComponentBase::CommandNames::ComponentStop    = "ComponentStop";
const std::string mtsManagerComponentBase::CommandNames::ComponentResume  = "ComponentResume";
const std::string mtsManagerComponentBase::CommandNames::ComponentGetState = "ComponentGetState";
const std::string mtsManagerComponentBase::CommandNames::GetNamesOfProcesses  = "GetNamesOfProcesses";
const std::string mtsManagerComponentBase::CommandNames::GetNamesOfComponents = "GetNamesOfComponents";
const std::string mtsManagerComponentBase::CommandNames::GetDescriptionsOfComponents = "GetDescriptionsOfComponents";
const std::string mtsManagerComponentBase::CommandNames::GetNamesOfInterfaces = "GetNamesOfInterfaces";
const std::string mtsManagerComponentBase::CommandNames::GetDescriptionsOfInterfaces = "GetDescriptionsOfInterfaces";
const std::string mtsManagerComponentBase::CommandNames::GetListOfConnections = "GetListOfConnections";
const std::string mtsManagerComponentBase::CommandNames::GetListOfComponentClasses = "GetListOfComponentClasses";
const std::string mtsManagerComponentBase::CommandNames::GetInterfaceProvidedDescription = "GetInterfaceProvidedDescription";
const std::string mtsManagerComponentBase::CommandNames::GetInterfaceRequiredDescription = "GetInterfaceRequiredDescription";
const std::string mtsManagerComponentBase::CommandNames::GetEndUserInterface = "GetEndUserInterface";
const std::string mtsManagerComponentBase::CommandNames::AddObserverList = "AddObserverList";
const std::string mtsManagerComponentBase::CommandNames::RemoveEndUserInterface = "RemoveEndUserInterface";
const std::string mtsManagerComponentBase::CommandNames::RemoveObserverList = "RemoveObserverList";
const std::string mtsManagerComponentBase::CommandNames::LoadLibrary = "LoadLibrary";
const std::string mtsManagerComponentBase::CommandNames::PrintLog = "PrintLog";
const std::string mtsManagerComponentBase::CommandNames::GetAbsoluteTimeInSeconds = "GetAbsoluteTimeInSeconds";

// Names of events
const std::string mtsManagerComponentBase::EventNames::AddComponent  = "AddComponentEvent";
const std::string mtsManagerComponentBase::EventNames::AddConnection = "AddConnectionEvent";
const std::string mtsManagerComponentBase::EventNames::RemoveConnection = "RemoveConnectionEvent";
const std::string mtsManagerComponentBase::EventNames::ChangeState   = "ChangeState";
const std::string mtsManagerComponentBase::EventNames::PrintLog      = "PrintLog";

CMN_IMPLEMENT_SERVICES_DERIVED(mtsManagerComponentBase, mtsTaskFromSignal);

mtsManagerComponentBase::mtsManagerComponentBase(const std::string & componentName)
    : mtsTaskFromSignal(componentName, 50)
{
}

mtsManagerComponentBase::~mtsManagerComponentBase()
{
}

void mtsManagerComponentBase::Run(void)
{
    ProcessQueuedCommands();
    ProcessQueuedEvents();
}

void mtsManagerComponentBase::Cleanup(void)
{
}

bool mtsManagerComponentBase::IsManagerComponent(const std::string & componentName)
{
    return ((componentName == ComponentNames::ManagerComponent) ||
            (componentName == ComponentNames::ManagerLocal));
}

bool mtsManagerComponentBase::IsNameOfInterfaceComponentRequired(const std::string & interfaceName)
{
    const std::string prefix = GetNameOfInterfaceComponentRequiredFor("");

    return (interfaceName.substr(0, prefix.size()) == prefix);
}

bool mtsManagerComponentBase::IsNameOfInterfaceComponentProvided(const std::string & interfaceName)
{
    return (interfaceName.substr(0, mtsManagerComponentBase::InterfaceNames::InterfaceComponentProvided.size())
            == GetNameOfInterfaceComponentProvided());
}

bool mtsManagerComponentBase::IsNameOfInterfaceInternalRequired(const std::string & interfaceName)
{
    return (interfaceName == GetNameOfInterfaceInternalRequired());
}

bool mtsManagerComponentBase::IsNameOfInterfaceInternalProvided(const std::string & interfaceName)
{
    return (interfaceName.substr(0, mtsManagerComponentBase::InterfaceNames::InterfaceInternalProvided.size())
            == GetNameOfInterfaceInternalProvided());
}

const std::string mtsManagerComponentBase::GetNameOfInterfaceComponentRequiredFor(const std::string & componentName)
{
    std::string interfaceName = InterfaceNames::InterfaceComponentRequired;
    interfaceName += "For";
    interfaceName += componentName;

    return interfaceName;
}

const std::string mtsManagerComponentBase::GetNameOfInterfaceComponentProvided(void)
{
    return InterfaceNames::InterfaceComponentProvided;
}

const std::string mtsManagerComponentBase::GetNameOfInterfaceInternalRequired(void)
{
    return InterfaceNames::InterfaceInternalRequired;
}

const std::string mtsManagerComponentBase::GetNameOfInterfaceInternalProvided(void)
{
    return InterfaceNames::InterfaceInternalProvided;
}

bool mtsManagerComponentBase::IsNameOfInternalInterface(const std::string & interfaceName)
{
    if (IsNameOfInterfaceComponentRequired(interfaceName)) return true;
    if (IsNameOfInterfaceComponentProvided(interfaceName)) return true;
    if (IsNameOfInterfaceInternalRequired(interfaceName)) return true;
    if (IsNameOfInterfaceInternalProvided(interfaceName)) return true;

    return false;
}