41 struct XMLStateOffererFactoryBase;
45 virtual public AbstractFactoryMethod<XMLStateOffererFactoryBase, StatechartGroupXmlReaderPtr, XMLStateOffererFactoryBasePtr >
50 template <
typename ContextType = State
chartContext>
65 return statechartGroupName;
72 void onInitRemoteStateOfferer()
override;
73 void onConnectRemoteStateOfferer()
override;
74 void onExitRemoteStateOfferer()
override;
76 bool loadLib(std::string libPath);
78 StateBasePtr getStatePtr(
const std::string& stateName)
const override;
81 std::map<std::string, DynamicLibraryPtr> libraries;
82 std::string statechartGroupName;
83 std::map<std::string, StatePtr> uuidStateMap;
90 template <
typename ContextType>
96 statechartGroupName = reader->getGroupName();
97 ManagedIceObject::setName(reader->getGroupName() +
"StateOfferer");
104 Logging::setTag(
"XMLRemoteStateOfferer");
107 template <
typename ContextType>
111 statechartGroupName = reader->getGroupName();
112 Ice::StringSeq xmlStateFileList = reader->getStateFilepaths();
114 std::map<std::string, StatechartGroupXmlReader::StateVisibility> visibilities;
116 for (
unsigned int i = 0; i < xmlStateFileList.size(); i++)
118 std::string& filepath = xmlStateFileList.at(i);
121 if (!ArmarXDataPath::getAbsolutePath(filepath, filepath))
123 ARMARX_ERROR <<
"Could not find xml state file: " << filepath;
127 std::string xmlString = RapidXmlReader::ReadFileContents(filepath);
129 auto uuid = reader->getRoot(
"State").attribute_value(
"uuid");
130 uuidXMLMap->insert(std::make_pair(uuid, reader));
131 visibilities[uuid] = this->reader->getStateVisibility(filepath);
134 for (StringXMLNodeMap::iterator it = uuidXMLMap->begin(); it != uuidXMLMap->end(); it++)
140 if (visibilities[it->first] == StatechartGroupXmlReader::ePublic)
145 catch (exceptions::local::ExpressionException& e)
147 ARMARX_ERROR <<
"The loading of the xml state failed due to an invalid xml file '" << it->first <<
"'.\nError hint: " << e.what();
149 catch (std::exception& e)
151 ARMARX_ERROR <<
"The loading of the xml state failed due to an invalid xml file '" << it->first <<
"'.\nError hint: " << e.what();
156 onInitXMLRemoteStateOfferer();
159 template <
typename ContextType>
160 void XMLRemoteStateOfferer<ContextType>::onConnectRemoteStateOfferer()
162 onConnectXMLRemoteStateOfferer();
165 template <
typename ContextType>
166 void XMLRemoteStateOfferer<ContextType>::onExitRemoteStateOfferer()
168 onExitXMLRemoteStateOfferer();
171 template <
typename ContextType>
172 StateBasePtr XMLRemoteStateOfferer<ContextType>::getStatePtr(
const std::string& stateName)
const
174 for (
const auto& substate : StateBase::subStateList)
176 if (StateBasePtr::dynamicCast(substate)->stateName == stateName)
178 return StateBasePtr::dynamicCast(substate);
182 auto it = uuidStateMap.find(stateName);
184 if (it != uuidStateMap.end())
192 ARMARX_ERROR <<
"State with id '" << stateName <<
"' has NULL ptr in map!";
196 ARMARX_ERROR <<
"Could not find state with name '" << stateName <<
"'";
202 template <
typename ContextType>
205 RapidXmlReaderNode node = reader->getRoot(
"State");
206 std::string stateName = node.attribute_value(
"name");
207 std::string uuid = node.attribute_value(
"uuid");
210 StatePtr state = StatePtr::dynamicCast(xmlStateInstance);
214 state = StatePtr::dynamicCast(NoUserCodeState::CreateInstance(XMLStateConstructorParams(
"", reader, this->reader->getSelectedProfile(), uuidXMLMap, StatechartContext::getIceManager()->getCommunicator())));
223 state->stateName = stateName;
224 state->stateClassName = stateName;
226 uuidStateMap[uuid] = state;
234 template <
typename ContextType>
242 if (State::findSubstateByName(state->getStateName()))
244 throw exceptions::local::eStatechartLogicError(
"There exists already a substate with name '" + state->getStateName() +
"' in this hierarchy level. In one hierarchy level (aka one substatelist) the names must be unique.");
247 if (state->getStateName().empty())
249 throw exceptions::local::eStatechartLogicError(
"The statename must not be empty");
252 state->__setParentState(
this);
253 this->StateBase::subStateList.push_back(state);
254 this->initState(*state);
258 template <
typename ContextType>
261 return statechartGroupName;
264 template <
typename ContextType>
267 statechartGroupName =
value;