DemoStateManager.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXGui::DemoStateManager
17 * @author Leonie Leven
18 * @date 2024
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "DemoStateManager.h"
24
25namespace armarx
26{
27 void
29 {
30
31 this->defaultStartUp = getProperty<std::string>("DefaultStateStartUp").getValue();
32 this->defaultStateValues = getProperty<std::string>("DefaultStates").getValue();
33 std::size_t pos = defaultStartUp.find(":");
34 std::string message = "";
35 int i = 0;
36 if (pos != std::string::npos)
37 {
38 message = defaultStartUp.substr(0, pos);
39 i = std::stoi(defaultStartUp.substr(pos + 1));
40 }
41 this->currentSeverity = static_cast<severity::SeverityEnum>(i);
42 this->currentState = message;
43
44 std::vector<std::pair<std::string, int>> result;
45 std::vector<std::string> pairs;
46
47 boost::split(pairs, this->defaultStateValues, boost::is_any_of(";"));
48
49 for (auto& pair : pairs)
50 {
51 std::vector<std::string> keyValue;
52 boost::split(keyValue, pair, boost::is_any_of(":"));
53
54 if (keyValue.size() == 2)
55 {
56 boost::trim(keyValue[0]);
57 boost::trim(keyValue[1]);
58 try
59 {
60 StateAndSeverity newState{
61 .state = keyValue[0],
62 .severity = static_cast<severity::SeverityEnum>(std::stoi(keyValue[1]))};
63 this->allStates.push_back(newState);
64 }
65 catch (const std::exception& e)
66 {
67 ARMARX_ERROR << "Invalid Severity";
68 }
69 }
70 }
71 }
72
73 void
77
78 void
82
83 void
87
90 {
92 new ::armarx::ComponentPropertyDefinitions(getConfigIdentifier());
93 def->optional(properties.defaultStates,
94 "DefaultStates",
95 "Initial predefined states to be loaded at startup. These can be copied from "
96 "the operator view. Syntax: message:severity;message:severity;");
97 def->optional(properties.defaultStateStartUp,
98 "DefaultStateStartUp",
99 "Predefined state that will be shown in the presenter view. Syntax: "
100 "message:severity");
101 return def;
102 }
103
104 void
105 DemoStateManager::setState(const std::string& state,
106 armarx::severity::SeverityEnum severity,
107 const Ice::Current&)
108 {
109 this->currentSeverity = severity;
110 this->currentState = state;
111 }
112
113 void
114 DemoStateManager::insertState(const std::string& state,
115 armarx::severity::SeverityEnum severity,
116 const Ice::Current&)
117 {
118 StateAndSeverity newState{.state = state, .severity = severity};
119 this->allStates.push_back(newState);
120 }
121
122 void
123 DemoStateManager::deleteState(const std::string& state,
124 armarx::severity::SeverityEnum severity,
125 const Ice::Current&)
126 {
127 StateAndSeverity delState{.state = state, .severity = severity};
128
129 auto it =
130 std::find_if(allStates.begin(),
131 allStates.end(),
132 [&](const StateAndSeverity& s)
133 { return s.state == delState.state && s.severity == delState.severity; });
134
135 if (it != allStates.end())
136 {
137 allStates.erase(it);
138 }
139 }
140
141 StateAndSeverity
143 {
144 return {this->currentState, this->currentSeverity};
145 }
146
147 std::vector<StateAndSeverity>
149 {
150 return this->allStates;
151 }
152
153} // namespace armarx
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
StateAndSeverity getStateAndSeverity(const ::Ice::Current &=::Ice::Current()) override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
void deleteState(const std::string &state, armarx::severity::SeverityEnum severity, const Ice::Current &=::Ice::Current()) override
std::vector< StateAndSeverity > getCurrentStates(const ::Ice::Current &=::Ice::Current()) override
void setState(const std::string &state, armarx::severity::SeverityEnum severity, const Ice::Current &=::Ice::Current()) override
void insertState(const std::string &state, armarx::severity::SeverityEnum severity, const Ice::Current &=::Ice::Current()) override
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.