30#include <SimoxUtility/algorithm/string/string_tools.h>
64 return "NoUserCodeState";
73VariantContainerBasePtr
77 std::string defaultValueJsonString)
79 VariantContainerBasePtr result;
80 std::map<std::string, std::string> defaultValueMap;
83 if (defaultValueNode.has_attribute(
"profile"))
85 defaultValueMap.insert(std::make_pair(defaultValueNode.attribute_value(
"profile"),
86 defaultValueNode.attribute_value(
"value")));
90 defaultValueJsonString = defaultValueNode.attribute_value(
"value");
98 if (defaultValueMap.find(profile->getName()) != defaultValueMap.end())
100 defaultValueJsonString = defaultValueMap.at(profile->getName());
104 profile = profile->getParent();
109 if (!defaultValueJsonString.empty())
113 json->fromString(defaultValueJsonString);
114 result = VariantContainerBasePtr::dynamicCast(json->deserializeIceObject());
118 ARMARX_WARNING_S <<
"Could not deserialize param: " << defaultValueJsonString;
121 catch (JSONException& e)
124 << defaultValueJsonString;
169VariantContainerBasePtr
191 setXMLStateData(stateData);
204 if (!privateStateData->stateReader && privateStateData->xmlFilepath.empty())
206 throw LocalException(
"Either a xml node or a filepath must be given.");
208 else if (!privateStateData->stateReader)
210 privateStateData->stateNode =
215 privateStateData->stateNode = privateStateData->stateReader->getRoot(
"State");
216 privateStateData->xmlFilepath.clear();
227 return privateStateData->selectedProfile;
234 if (!privateStateData->stateNode.is_valid())
239 if (!privateStateData->ic && context && context->
getIceManager()->getCommunicator())
241 privateStateData->ic = context->
getIceManager()->getCommunicator();
244 this->StateBase::inputParameters =
245 getParameters(privateStateData->stateNode.first_node(
"InputParameters"));
246 this->StateBase::outputParameters =
247 getParameters(privateStateData->stateNode.first_node(
"OutputParameters"));
248 this->StateBase::localParameters =
249 getParameters(privateStateData->stateNode.first_node(
"LocalParameters"));
255 StateParameterMap result;
266 curParameterNode, privateStateData->ic, privateStateData->selectedProfile);
281 <<
"' is unknown, Parameter '" << deserialization.
getName()
293 if (!privateStateData->stateNode.is_valid())
300 const std::string stateName = privateStateData->stateNode.attribute_value(
"name");
302 addXMLSubstates(privateStateData->stateNode.first_node(
"Substates"), stateName);
304 addTransitions(privateStateData->stateNode.first_node(
"Transitions"));
306 setStartState(privateStateData->stateNode.first_node(
"StartState"));
319 curSubstateNode = curSubstateNode.next_sibling())
330 const std::string stateType = stateNode.
name();
335 std::string stateTypeL = simox::alg::to_lower(stateType);
337 if (stateTypeL ==
"localstate")
342 auto it = privateStateData->uuidToXMLMap->find(refuuid);
344 if (it == privateStateData->uuidToXMLMap->end())
346 throw LocalException(
"Could not find local state with UUID ") << refuuid;
350 const std::string stateName = substateReader->getRoot(
"State").attribute_value(
"name");
356 privateStateData->selectedProfile,
357 privateStateData->uuidToXMLMap,
358 privateStateData->ic)));
359 state = StateBasePtr::dynamicCast(xmlStateInstance);
363 ARMARX_DEBUG <<
"Using state with no code for " << stateName <<
" refuuid: " << refuuid
364 <<
" instanceName: " << instanceName;
368 privateStateData->selectedProfile,
369 privateStateData->uuidToXMLMap,
370 privateStateData->ic)));
375 state->stateName = instanceName;
376 state =
addState(StatePtr::dynamicCast(state));
377 ARMARX_DEBUG <<
"Added " << stateName <<
" with instanceName " << instanceName;
379 else if (stateTypeL ==
"remotestate")
383 const std::string proxyName = ((!privateStateData->selectedProfile->isRoot())
384 ? privateStateData->selectedProfile->getName()
387 ARMARX_DEBUG <<
"Adding remote state with refuuid " << refuuid
388 <<
" and instance name: " << instanceName;
392 else if (stateTypeL ==
"dynamicremotestate")
395 ARMARX_DEBUG <<
"Adding dynamic remote state with instance name: " << instanceName;
398 else if (stateTypeL ==
"endstate")
401 ARMARX_DEBUG <<
"Adding end state with event " << eventName;
409 throw LocalException(
"Unknown state type in XML - found state type: ") << stateType;
425 "There exists already a substate with name '" + state->StateBase::stateName +
426 "' in this hierarchy level. In one hierarchy level (aka one substatelist) the names "
430 if (state->stateName.empty())
436 state->__setParentState(
this);
437 this->StateBase::subStateList.push_back(state);
456 curTransitionNode = curTransitionNode.next_sibling(
"Transition"))
458 const std::string eventName = curTransitionNode.attribute_value(
"eventName");
460 const std::string sourceStateName = curTransitionNode.attribute_value(
"from");
462 if (!curTransitionNode.has_attribute(
"to"))
464 ARMARX_INFO <<
"Skipping detached transition " << eventName;
468 const std::string destinationStateName = curTransitionNode.attribute_value(
"to");
476 throw LocalException(
"Could not find source state with name :") << sourceStateName;
481 throw LocalException(
"Could not find source state with name :") << destinationStateName;
484 if (eventName.empty())
486 throw LocalException(
"Event name must not bet empty");
490 ARMARX_DEBUG <<
"Adding Transition on event " << eventName;
492 getMapping(curTransitionNode.first_node(
"ParameterMappings"));
494 getMapping(curTransitionNode.first_node(
"ParameterMappingsToParentsLocal"));
496 getMapping(curTransitionNode.first_node(
"ParameterMappingsToParentsOutput"));
501 mappingToNextStateInput,
502 mappingsToParentsLocal,
503 mappingsToParentsOutput);
530 for (RapidXmlReaderNode curMappingNode = mappingNode.
first_node(
"ParameterMapping");
532 curMappingNode = curMappingNode.next_sibling(
"ParameterMapping"))
534 MappingSource sourceType =
536 const std::string fromParamName = curMappingNode.attribute_value(
"from");
537 const std::string targetParamName = curMappingNode.attribute_value(
"to");
539 mapping->addMappingEntry(sourceType,
543 privateStateData->selectedProfile,
544 privateStateData->ic));
static SharedPointerType fromName(const std::string &name, XMLStateConstructorParams params)
static StatePtr createState(const EventPtr &event)
createState creates a finalstate instance with the specified event type.
The JSONObject class is used to represent and (de)serialize JSON objects.
IceManagerPtr getIceManager() const
Returns the IceManager.
static ParameterMappingPtr createMapping()
Creates a new instance of a ParameterMapping. Since the constructors are private, this method must be...
static MappingSource StringToMappingSource(const std::string &mappingSourceString)
RapidXmlReaderNode first_node(const char *name=nullptr) const
std::vector< RapidXmlReaderNode > nodes(const char *name=nullptr) const
static RapidXmlReaderNode NullNode()
std::string attribute_value(const char *attrName) const
std::string attribute_value_or_default(const char *attrName, const std::string &defaultValue) const
static RapidXmlReaderPtr FromFile(const std::string &path)
StateBasePtr findSubstateByName(const std::string &substateName)
Utility function to find a substate of this state by the name.
void __checkPhase(StatePhase allowedType, const char *functionName) const
Helper function for checking if a function was called in valid position of the statechart.
bool addParameterContainer(StateParameterMap ¶mMap, const std::string &key, const ContainerType &containerType, bool optional, VariantContainerBasePtr defaultValue=VariantContainerBasePtr()) const
std::unique_ptr< Impl > impl
ContextType * getContext() const
std::string getStateName() const
getStateName
VariantContainerBasePtr container
ContainerTypePtr getTypePtr()
VariantContainerBasePtr getContainer()
StateParameterDeserialization(RapidXmlReaderNode const ¶meterNode, Ice::CommunicatorPtr ic, StatechartProfilePtr selectedProfile)
EventPtr createEvent()
Utility function to create a new Event.
StateBasePtr setInitState(StateBasePtr initState, ParameterMappingPtr initialStateMapping=ParameterMappingPtr())
Sets the initial substate of this state.
TransitionIceBase & addTransition(EventPtr event, StateIceBasePtr sourceState, StateIceBasePtr destinationState, ParameterMappingIceBasePtr mappingToNextStatesInput=nullptr, ParameterMappingIceBasePtr mappingToParentStatesLocal=nullptr, ParameterMappingIceBasePtr mappingToParentStatesOutput=nullptr)
virtual RemoteStatePtr addDynamicRemoteState(std::string instanceName)
Function to add a new dynamic remote substate to this state.
virtual RemoteStatePtr addRemoteState(std::string stateName, std::string proxyName, std::string instanceName="")
Function to add a new remote substate to this state.
This class contains a statechart and provides the interfaces to distributed components.
static ContainerTypePtr FromString(const std::string &typeStr)
void defineParameters() override
Virtual function, in which input/local/output parameters can be specified.
StateParameterMap getParameters(RapidXmlReaderNode parametersNode)
StatePtr addState(StatePtr state)
void addXMLSubstates(RapidXmlReaderNode substatesNode, const std::string &parentStateName)
void defineSubstates() override
Virtual function, in which substates, transition and mappings can be added.
StateBasePtr addXMLSubstate(RapidXmlReaderNode stateNode, const std::string &parentStateName)
StatechartProfilePtr getSelectedProfile() const
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
VariantContainerBasePtr GetSelectedProfileValue(RapidXmlReaderNode parameterNode, StatechartProfilePtr selectedProfile, Ice::CommunicatorPtr ic, std::string defaultValueJsonString="")
std::shared_ptr< StringXMLNodeMap > StringXMLNodeMapPtr
std::shared_ptr< RapidXmlReader > RapidXmlReaderPtr
IceInternal::Handle< State > StatePtr
ParameterMappingPtr PMPtr
std::shared_ptr< class StatechartProfile > StatechartProfilePtr
IceInternal::Handle< JSONObject > JSONObjectPtr
IceInternal::Handle< Event > EventPtr
Typedef of EventPtr as IceInternal::Handle<Event> for convenience.
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
IceInternal::Handle< StateBase > StateBasePtr
IceInternal::Handle< ParameterMapping > ParameterMappingPtr
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
This file contains rapidxml parser and DOM implementation.
StateBasePtr clone() const override
Pure virtual function to clone of the derived class type.
static SubClassRegistry Registry
static std::string GetName()
NoUserCodeState(XMLStateConstructorParams stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
RapidXmlReaderPtr stateReader
StatechartProfilePtr selectedProfile
StringXMLNodeMapPtr uuidToXMLMap
std::filesystem::path xmlFilepath
RapidXmlReaderNode stateNode
XMLStateConstructorParams(const std::string &xmlFilepath, RapidXmlReaderPtr reader, StatechartProfilePtr selectedProfile, StringXMLNodeMapPtr uuidToXMLMap, Ice::CommunicatorPtr ic)
StatechartProfilePtr selectedProfile
StringXMLNodeMapPtr uuidToXMLMap