Go to the documentation of this file.
35 #include <IceUtil/UUID.h>
37 #include <SimoxUtility/algorithm/string/string_tools.h>
44 std::string
joinStrings(std::vector<std::string>
const&
input, std::string
const& seperator)
46 return simox::alg::join(
input, seperator);
98 return globalStateIdentifier;
103 return StateBasePtr::dynamicCast(initState);
113 return outputParameters;
119 StatePtr State::operator [](std::string
const& stateName)
121 for (
size_t i = 0; i < subStateList.size(); ++i)
123 if (stateName == StateBasePtr::dynamicCast(subStateList[i])->stateName
124 || stateName == StateBasePtr::dynamicCast(subStateList[i])->globalStateIdentifier)
126 return StatePtr::dynamicCast(subStateList[i]);
140 throw exceptions::local::eStatechartLogicError(
"There exists already a substate with name '" + stateName +
"' in this hierarchy level. In one hierarchy level (aka one substatelist) the names must be unique.");
143 pNewState->__setParentState(
this);
144 subStateList.push_back(pNewState);
155 if (instanceName.empty())
157 instanceName = stateName;
162 throw LocalException(
"There exists already a substate with name '" + instanceName +
"' in this hierarchy level. In one hierarchy level aka one substatelist the names must be unique.");
166 pNewState->setStateName(instanceName);
167 pNewState->setStateClassName(stateName);
168 pNewState->__setParentState(
this);
169 pNewState->setProxyName(proxyName);
171 subStateList.push_back(pNewState);
176 if (!ManagedIceObjectPtr::dynamicCast(pNewState))
188 context->
getArmarXManager()->addObject(ManagedIceObjectPtr::dynamicCast(pNewState),
false);
206 throw LocalException(
"There exists already a substate with name '" + stateName +
"' in this hierarchy level. In one hierarchy level aka one substatelist the names must be unique.");
211 pNewState->__setParentState(
this);
212 pNewState->setStateName(instanceName);
213 subStateList.push_back(pNewState);
221 context->
getArmarXManager()->addObject(ManagedIceObjectPtr::dynamicCast(pNewState),
false, pNewState->getName() + IceUtil::generateUUID());
223 ARMARX_DEBUG <<
"Waiting for RemoteState " << pNewState->getName();
225 pNewState->getObjectScheduler()->waitForObjectStateMinimum(eManagedIceObjectStarted);
227 ARMARX_DEBUG <<
"RemoteState " << pNewState->getName() <<
"started.";
232 TransitionIceBase&
State::addTransition(
EventPtr event, StateIceBasePtr sourceState, StateIceBasePtr destinationState, ParameterMappingIceBasePtr mappingToNextStatesInput, ParameterMappingIceBasePtr mappingToParentStatesLocal, ParameterMappingIceBasePtr mappingToParentStatesOutput)
237 assert(sourceState._ptr);
238 assert(destinationState._ptr);
239 t.sourceState = sourceState;
240 t.evt =
createEvent(event->eventName, event->properties);
241 t.destinationState = destinationState;
243 if (mappingToNextStatesInput)
245 t.mappingToNextStatesInput = PMPtr::dynamicCast(mappingToNextStatesInput)->clone();
248 if (mappingToParentStatesLocal)
250 t.mappingToParentStatesLocal = PMPtr::dynamicCast(mappingToParentStatesLocal)->clone();
253 if (mappingToParentStatesOutput)
255 t.mappingToParentStatesOutput = PMPtr::dynamicCast(mappingToParentStatesOutput)->clone();
260 +
"' from '" + sourceState->stateName +
"' to '" + destinationState->stateName +
"'");
262 transitions.push_back(t);
263 return *transitions.rbegin();
277 return addParameter(inputParameters, key, type, optional);
280 bool State::addToInput(
const std::string& key,
const ContainerType& type,
bool optional, VariantContainerBasePtr defaultValue)
290 return addParameter(outputParameters, key, type, optional);
299 bool State::addToLocal(
const std::string& key,
const ContainerType& type, VariantContainerBasePtr defaultValue)
302 std::unique_lock lock(simpl->localParameterMutex);
310 std::unique_lock lock(simpl->localParameterMutex);
312 return addParameter(localParameters, key, type,
true, defaultValue);
323 if (initialStateMapping)
325 this->initialStateMapping = initialStateMapping->clone();
328 if (!StateIceBasePtr::dynamicCast(initState))
330 throw LocalException(
"Couldnt cast initstate");
333 this->initState = initState;
362 std::string className = simox::alg::replace_all(typeName,
":",
"_");
369 std::unique_lock lock(simpl->inputParameterMutex);
377 std::unique_lock lock(simpl->inputParameterMutex);
387 return localParameters;
393 std::unique_lock lock(simpl->inputParameterMutex);
397 throw LocalException(
"Input parameter '" + key +
"' in state '" + stateName +
"'' is already set and cannot be changed.");
406 std::unique_lock lock(simpl->inputParameterMutex);
410 throw LocalException(
"Input parameter '" + key +
"' in state '" + stateName +
"'' is already set and cannot be changed.");
420 std::unique_lock lock(simpl->localParameterMutex);
428 std::unique_lock lock(simpl->localParameterMutex);
437 std::unique_lock lock(simpl->outputParameterMutex);
445 std::unique_lock lock(simpl->outputParameterMutex);
478 VariantContainerBasePtr
482 std::unique_lock lock(simpl->localParameterMutex);
484 VariantContainerBasePtr varList;
486 return VariantContainerBasePtr::dynamicCast(varList);
506 State::addState<State>(std::string
const& stateName)
512 throw exceptions::local::eStatechartLogicError(
"There already exists a substate with name '" + stateName +
"' in this hierarchy level. In one hierarchy level (aka one substatelist) the names must be unique.");
515 if (stateName.empty())
521 pNewState->stateName = stateName;
522 pNewState->__setParentState(
this);
523 subStateList.push_back(pNewState);
bool isOutputParameterSet(const std::string &key) const
void getParameterContainer(const StateParameterMap ¶mMap, const std::string &key, VariantContainerBasePtr &valueContainer) const
std::mutex localParameterMutex
The Variant class is described here: Variants.
StateParameterMap & getOutputParameters() override
getter function to get the map of output parameters
bool isUnbreakable() const
void setOutput(std::string const &key, const Variant &value)
setOuput() sets an output parameter of this state.
void setUseRunFunction(bool useRunFuntion)
setUseRunFunction can be used to configurate whether the thread with the async.
StateBase & operator=(const StateBase &source)
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > getInput(const std::string &key) const
getInput can be used to access a specific input parameter.
void __checkPhaseMin(StatePhase allowedType, const char *functionName) const
std::mutex inputParameterMutex
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
bool init(StatechartContextInterface *context, StatechartManager *manager)
Function to initialize this state. Must be called in the highest level of the hierarchy - and only th...
void setLocal(std::string const &key, const Variant &value)
setLocal() sets a local parameter.
void setStateName(const std::string &newName)
bool isInputParameterSet(const std::string &key) const
Checks whether a given input parameter is set or not.
StateBasePtr addState(StateBasePtr pNewState)
std::string getGlobalIdString() const
Getter for the global state identifier string.
StateBasePtr createEmptyCopy() const override
Generates a new copy of this state with the same overidden functions. stateName, substates,...
bool __checkExistenceOfTransition(const TransitionIceBase &transition)
void setParameterContainer(StateParameterMap ¶mMap, const std::string &key, const VariantContainerBasePtr &valueContainer)
void cancelSubstates()
Use this function in the onEnter() function, if you want to avoid that the substates (i....
StateBasePtr setInitState(StateBasePtr initState, ParameterMappingPtr initialStateMapping=ParameterMappingPtr())
Sets the initial substate of this state.
void setStateClassName(std::string className)
setStateClassName() sets the string, that contains a stringrepresentation of this class....
std::shared_ptr< Value > value()
bool addToLocal(const std::string &key, VariantTypeId type, VariantPtr defaultValue=VariantPtr())
Adds a key,type-pair to the local parameters.
QMap< QString, StateParameterPtr > StateParameterMap
StateParameterMap & getLocalParameters()
Getter for the local parameter map.
This class contains a statechart and provides the interfaces to distributed components.
ReaderT::InputType & input
void setUnbreakable(bool setUnbreakable=true)
With this function the state can be made unbreakable.
TransitionIceBase & addTransition(EventPtr event, StateIceBasePtr sourceState, StateIceBasePtr destinationState, ParameterMappingIceBasePtr mappingToNextStatesInput=nullptr, ParameterMappingIceBasePtr mappingToParentStatesLocal=nullptr, ParameterMappingIceBasePtr mappingToParentStatesOutput=nullptr)
void copyDictionary(const StringVariantContainerBaseMap &source, StringVariantContainerBaseMap &destination)
Clears the destination map and copies the parameters of the source in it.
bool addToInput(const std::string &key, const ContainerType &type, bool optional, VariantContainerBasePtr defaultValue=VariantContainerBasePtr())
Adds a key,type-pair to the input parameters.
StateBasePtr clone() const override
Generates a new copy of this state with the same statename, substates, transitions,...
VariantContainerBasePtr getLocalContainer(std::string const &key)
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
bool addParameter(StateParameterMap ¶mMap, const std::string &key, VariantTypeId type, bool optional, VariantPtr defaultValue=VariantPtr()) const
void inheritInputFromSubstate(std::string stateName)
Base Class for all Logging classes.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
virtual RemoteStatePtr addDynamicRemoteState(std::string instanceName)
Function to add a new dynamic remote substate to this state.
void setParameter(StateParameterMap ¶mMap, const std::string &key, const Variant &variant)
unsigned int getId() const
Returns an id to this state, that is guaranteed to be unique in this process.
void setStateClassNameFromTypeName(const std::string &typeName)
EventPtr createEvent()
Utility function to create a new Event.
bool addParameterContainer(StateParameterMap ¶mMap, const std::string &key, const ContainerType &containerType, bool optional, VariantContainerBasePtr defaultValue=VariantContainerBasePtr()) const
bool isParameterSet(const StateParameterMap ¶mMap, const std::string &key) const
StatePhase getStatePhase() const
virtual RemoteStatePtr addRemoteState(std::string stateName, std::string proxyName, std::string instanceName="")
Function to add a new remote substate to this state.
bool addToOutput(const std::string &key, VariantTypeId type, bool optional)
Adds a key,type-pair to the output parameters.
StateBasePtr getInitState() const
Getter for the initial state. The initial state is automatically entered, when this state is entered.
State & operator=(const State &source)
StateParameterMap getInputParameters() override
Returns a new copy of the inputparameters-dictionary, so that the caller cannot modify them (const wo...
void setInput(std::string const &key, const Variant &value)
setInput() sets an input parameter.
void __checkPhase(StatePhase allowedType, const char *functionName) const
Helper function for checking if a function was called in valid position of the statechart.
std::unique_ptr< Impl > impl
bool isLocalParameterSet(const std::string &key) const
StateBasePtr findSubstateByName(const std::string &substateName)
Utility function to find a substate of this state by the name.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::mutex outputParameterMutex
void getParameter(const StateParameterMap ¶mMap, const std::string &key, VariantPtr &value) const
friend class DynamicRemoteState
std::string joinStrings(std::vector< std::string > const &input, std::string const &seperator)
bool init(StatechartContextInterface *context, StatechartManager *manager)
Function to initialize this state. Must be called in the highest level of the hierarchy - and only th...