18 CreateRemoteStateInstanceOutput
20 const CreateRemoteStateInstanceInput& input,
23 CreateRemoteStateInstanceOutput result;
30 std::stringstream msg;
31 msg <<
"Could not find (public) state: " << input.stateClassName;
34 for (
const auto& entry : (*
impl->stateInstancesPtr))
40 msg <<
"- but found a state instance with same name - maybe you forgot to make "
46 throw LocalException(msg.str());
50 result.inputParameters = statePtr->inputParameters;
52 result.outputParameters = statePtr->outputParameters;
58 StatePtr newState = StatePtr::dynamicCast(statePtr->clone());
62 "Could not cast from StateBasePtr to StatePtr");
65 if (!input.instanceName.empty())
67 newState->setStateName(input.instanceName);
76 remoteStateData.
id = newState->getLocalUniqueId();
82 newWrappedState->globalStateIdentifier = input.parentStateItentifierStr;
83 newState->__setParentState(newWrappedState._ptr);
85 result.remoteStateId = remoteStateData.
id;
90 state->refetchSubstates();
91 result.statechartInstance = state;
100 const RemoteStateIceBasePrx& remoteStatePrx,
101 const std::string& parentStateItentifierStr,
102 const std::string& instanceName,
103 const Ice::Current& )
112 std::stringstream msg;
113 msg <<
"Could not find (public) state: " << stateName;
116 for (
const auto& entry : (*
impl->stateInstancesPtr))
122 msg <<
"- but found a state instance with same name - maybe you forgot to make "
128 throw LocalException(msg.str());
133 ARMARX_DEBUG <<
"entering createRemoteStateInstance() with " << parentStateItentifierStr
134 <<
" stateclass: " << statePtr->stateClassName
135 <<
" statename: " << statePtr->stateName <<
flush;
136 StatePtr newState = StatePtr::dynamicCast(statePtr->clone());
141 "Could not cast from StateBasePtr to StatePtr");
144 if (!instanceName.empty())
146 newState->setStateName(instanceName);
149 ARMARX_DEBUG <<
"RemoteStateInstanceName: " << newState->getStateName()
150 <<
" instanceName=" << instanceName;
156 remoteStateData.
id = newState->getLocalUniqueId();
162 newWrappedState->globalStateIdentifier = parentStateItentifierStr;
163 newState->__setParentState(newWrappedState._ptr);
166 return remoteStateData.
id;
171 const std::string& parentId,
172 const Ice::Current& context)
176 StatePtr state = wrapper->realState;
179 state->__getParentState()->globalStateIdentifier = parentId;
180 state->__updateGlobalStateIdRecursive();
186 const StringVariantContainerBaseMap& properties,
187 const Ice::Current& context)
191 if (state->getStatePhase() >=
eExited)
196 state->enter(properties);
207 const EventBasePtr& evt,
208 const Ice::Current& context)
220 catch (
const LocalException&)
222 ARMARX_ERROR <<
"Could not find state with id " << stateId <<
" - thus cannot break it"
238 const EventBasePtr& evt,
239 const Ice::Current& context)
242 EventPtr::dynamicCast(evt));
249 const Ice::Current& context)
254 statePtr->__notifyEventBufferedDueToUnbreakableState(eventBuffered);
262 std::scoped_lock lock(wrapper->mutex);
263 StatePtr state = wrapper->realState;
264 state->refetchSubstates();
265 return new StateIceBase(*state);
270 const Ice::Current& context)
273 return statePtr->inputParameters;
278 const Ice::Current& context)
281 return statePtr->outputParameters;
299 const Ice::Current& context)
const
303 if (statePtr->subStateList.size() > 0)
320 Ice::StringSeq result;
322 for (
unsigned int i = 0; i < subStateList.size(); ++i)
324 result.push_back(StateBasePtr::dynamicCast(subStateList.at(i))->stateName);
333 StateIdNameMap result;
335 typename std::map<int, RemoteStateData>::iterator it =
stateInstanceList.begin();
339 result[it->second.remoteWrappedState->realState->getLocalUniqueId()] =
340 it->second.remoteWrappedState->realState->getGlobalHierarchyString();
358 state->refetchSubstates();
366 StateIceBasePtr result;
370 typename std::map<int, RemoteStateData>::iterator it =
stateInstanceList.begin();
375 StateBasePtr::dynamicCast(it->second.remoteWrappedState->realState);
377 if (curState->globalStateIdentifier == globalStateIdStr)
391 globalStateIdStr, curState, stateCount);
398 ARMARX_WARNING <<
"Found more than one state with globalStateIdStr '"
399 << globalStateIdStr <<
"'. Returning first found occurence." <<
flush;
405 state->refetchSubstates();
409 ARMARX_WARNING <<
"Could not find state instance with id str '" << globalStateIdStr
420 std::queue<StateBasePtr> stateList;
424 stateList.push(instancePair.second.remoteWrappedState->realState);
429 if (stateList.size() > 0)
431 statePtr = stateList.front();
436 ARMARX_DEBUG <<
"Checking " << statePtr->getGlobalHierarchyString();
438 RemoteStatePtr remoteState = RemoteStatePtr::dynamicCast(statePtr);
440 if (statePtr && !remoteState)
442 for (
unsigned int i = 0; i < statePtr->subStateList.size(); i++)
444 stateList.push(StateBasePtr::dynamicCast(statePtr->subStateList.at(i)));
447 if (statePtr && statePtr->getGlobalHierarchyString() == globalStateIdStr)
451 }
while (stateList.size() > 0);
470 catch (LocalException& e)
473 <<
". Hence, it could not be removed.\n"
480 const EventBasePtr& event,
483 ARMARX_VERBOSE <<
"received external event '" <<
event->eventName <<
"' for state '"
484 <<
event->eventReceiverName <<
"'" <<
flush;
485 ARMARX_VERBOSE <<
"Event Dict Size: " <<
event->properties.size() <<
"\n"
494 impl->manager->addEvent(EventPtr::dynamicCast(event), statePtr);
497 catch (LocalException& local)
501 catch (
const IceUtil::Exception& exception)
504 ARMARX_ERROR <<
"caught ice exception: " << exception.what()
505 <<
"\nBacktrace: " << exception.ice_stackTrace() <<
flush;
511 const EventBasePtr& evt,
517 ->getLocalUniqueId();
520 catch (Ice::Exception& e)
522 ARMARX_ERROR <<
"Caught Ice::exception: " << e.what() << std::endl
523 << e.ice_stackTrace();
529 std::string proxyName,
530 std::string instanceName)
533 "You cannot add remoteStates directly to the RemoteStateOfferer. You can only add them "
541 "You cannot add dynamicRemoteStates directly to the RemoteStateOfferer. You can only "
542 "add them to substates.");
549 typename std::map<int, RemoteStateData>::iterator it =
stateInstanceList.find(stateId);
553 std::stringstream
str;
554 str <<
"Could not find state with id '" << stateId <<
"'\n";
555 str <<
"Known states:\n";
560 str <<
"\t" <<
data.remoteWrappedState->stateName
561 <<
" id: " <<
data.remoteWrappedState->getLocalUniqueId() <<
flush;
564 throw LocalException(
str.str());
574 typename std::map<int, StateBase*>::iterator it =
impl->stateInstancesPtr->find(globalId);
576 if (it !=
impl->stateInstancesPtr->end())
581 std::stringstream
str;
582 str <<
"Could not find state with id '" << globalId <<
"'";
583 throw LocalException(
str.str());
594 for (
unsigned int i = 0; i < subStateList.size(); i++)
597 StateBasePtr state = StateBasePtr::dynamicCast(subStateList.at(i));
599 if (state->stateName == stateName)
616 std::map<int, StateBasePtr>
620 std::map<int, StateBasePtr> stateList;
621 std::map<int, StateBasePtr> result;
626 for (
unsigned int i = 0; i < statePtr->subStateList.size(); i++)
628 stateList.insert(std::pair<int, StateBasePtr>(
629 StateBasePtr::dynamicCast(statePtr->subStateList.at(i))->getLocalUniqueId(),
630 StateBasePtr::dynamicCast(statePtr->subStateList.at(i))));
633 if (parentId != statePtr->getLocalUniqueId())
635 if (StateBasePtr::dynamicCast(statePtr)->stateName == stateName)
638 std::pair<int, StateBasePtr>(statePtr->getLocalUniqueId(), statePtr));
641 stateList.erase(statePtr->getLocalUniqueId());
644 if (stateList.size() > 0)
646 statePtr = stateList.begin()->second;
648 }
while (stateList.size() > 0);
655 const std::string& globalStateIdStr,
659 StateIceBasePtr result;
660 StateList::iterator it = state->subStateList.begin();
662 for (; it != state->subStateList.end(); ++it)
666 if (curState->globalStateIdentifier == globalStateIdStr)
670 if (stateCounter == 1)
676 if (stateCounter == 0)
679 globalStateIdStr, curState, stateCounter);
698 for (
size_t i = 0; i < subStateList.size(); i++)
704 c->disableRunFunction();
708 subStateList.clear();
713 StateControllerPtr::dynamicCast(e.second.remoteWrappedState->realState);
717 c->disableRunFunction();
This class is the implementation of the Slice Definition of a state.
std::unique_ptr< Impl > impl
std::string getStateName() const
getStateName
friend class RemoteStateWrapper
bool init(StatechartContextInterface *context, StatechartManager *manager)
Function to initialize this state. Must be called in the highest level of the hierarchy - and only th...
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#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_VERBOSE
The logging level for verbose information.
boost::unique_lock< HiddenTimedMutex > ScopedLock
std::string getDictionaryString(const StringVariantContainerBaseMap &mymap)
Converts the map into a string-representation.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< RemoteState > RemoteStatePtr
IceInternal::Handle< RemoteStateWrapper > RemoteStateWrapperPtr
IceInternal::Handle< State > StatePtr
const LogSender::manipulator flush
IceInternal::Handle< StateBase > StateBasePtr
IceInternal::Handle< StateController > StateControllerPtr
A struct that holds meta data for a remoteaccessable state instances.
RemoteStateWrapperPtr remoteWrappedState
Pointer to a Pseudo parent state, that contains the real state instance.
int id
Local id of this RemoteStateOfferer, that identifies the state instance in the stateInstanceList.
std::string callerIceName
Not used yet.
RemoteStateIceBasePrx callerStatePrx
Proxy to the state, that called this state.
CreateRemoteStateInstanceOutput createRemoteStateInstanceNew(CreateRemoteStateInstanceInput const &input, Ice::Current const &context) override
bool isRemoteStateFinished(int stateId, const ::Ice::Current &context=Ice::emptyCurrent) override
RemoteStateData getInstance(int stateId)
int createRemoteStateInstance(const std::string &stateName, const RemoteStateIceBasePrx &remoteStatePrx, const std::string &parentStateItentifierStr, const std::string &instanceName, const Ice::Current &context=Ice::emptyCurrent) override
StateIceBasePtr getStatechartInstanceByGlobalIdStr(const std::string &globalStateIdStr, const Ice::Current &=Ice::emptyCurrent) override
void removeInstance(int stateId, const Ice::Current &=Ice::emptyCurrent) override
void notifyEventBufferedDueToUnbreakableStateRemote(int stateId, bool eventBuffered, const ::Ice::Current &context=Ice::emptyCurrent) override
virtual void onConnectRemoteStateOfferer()
Virtual function, in which the user can fetch some proxies.
StateIceBasePtr refetchRemoteSubstates(int stateId, const ::Ice::Current &context=Ice::emptyCurrent) override
bool hasSubstatesRemote(const std::string &stateName, const ::Ice::Current &context=Ice::emptyCurrent) const override
void initState(State &state)
HiddenTimedMutex stateInstanceListMutex
void issueEventWithGlobalIdStr(const std::string &globalStateIdStr, const EventBasePtr &evt, const Ice::Current &=Ice::emptyCurrent) override
void exitRemoteState(int stateId, const ::Ice::Current &context=Ice::emptyCurrent) override
Ice::StringSeq getAvailableStates(const ::Ice::Current &context=Ice::emptyCurrent) override
StateParameterMap getRemoteInputParametersById(int stateId, const ::Ice::Current &context=Ice::emptyCurrent) override
void updateGlobalStateIdRecursive(int stateId, const std::string &parentId, const Ice::Current &context=Ice::emptyCurrent) override
RemoteStatePtr addDynamicRemoteState(std::string instanceName) override
Overridden so that the user cannot use it.
void issueEvent(int receivingStateId, const EventBasePtr &evt, const Ice::Current &=Ice::emptyCurrent) override
std::map< int, RemoteStateData > stateInstanceList
Holds the instances that where requested from remotely located states.
void onExitStatechartImpl()
StateIdNameMap getAvailableStateInstances(const ::Ice::Current &context=Ice::emptyCurrent) override
virtual void waitUntilComponentStarted()=0
void onConnectStatechartImpl()
bool breakRemoteState(int stateId, const EventBasePtr &evt, const ::Ice::Current &context=Ice::emptyCurrent) override
virtual void onExitRemoteStateOfferer()
Virtual function, in which the user can implement some clean up.
StateBasePtr getGlobalInstancePtr(int globalId) const
RemoteStatePtr addRemoteState(std::string stateName, std::string proxyName, std::string instanceName) override
Overridden so that the user cannot use it.
std::map< int, StateBasePtr > getChildStatesByName(int parentId, std::string stateName)
void callRemoteState(int stateId, const StringVariantContainerBaseMap &properties, const Ice::Current &context=Ice::emptyCurrent) override
bool breakActiveSubstateRemotely(int stateId, const EventBasePtr &evt, const ::Ice::Current &context=Ice::emptyCurrent) override
StateParameterMap getRemoteInputParameters(const std::string &stateName, const ::Ice::Current &context=Ice::emptyCurrent) override
StateIceBasePtr getStatechartInstanceByGlobalIdStrRecursive(const std::string &globalStateIdStr, StateBasePtr state, int &stateCounter)
StateParameterMap getRemoteOutputParameters(const std::string &stateName, const ::Ice::Current &context=Ice::emptyCurrent) override
StateIceBasePtr getStatechartInstance(int stateId, const Ice::Current &=Ice::emptyCurrent) override
bool isHostOfStateByGlobalIdStr(const std::string &globalStateIdStr, const Ice::Current &=Ice::emptyCurrent) override
void run() override
Virtual function, that can be reimplemented to calculate complex operations.
StateIceBasePtr getStatechart(const std::string &stateName, const ::Ice::Current &context=Ice::emptyCurrent) override
bool hasActiveSubstateRemote(int stateId, const ::Ice::Current &context=Ice::emptyCurrent) override
virtual StateBasePtr getStatePtr(const std::string &stateName) const
StateParameterMap getRemoteOutputParametersById(int stateId, const ::Ice::Current &context=Ice::emptyCurrent) override
static HiddenTimedMutex * __StateInstancesMutex