17 const CreateRemoteStateInstanceInput&
input,
20 CreateRemoteStateInstanceOutput result;
27 std::stringstream msg;
28 msg <<
"Could not find (public) state: " <<
input.stateClassName;
31 for (
const auto& entry : (*
impl->stateInstancesPtr))
37 msg <<
"- but found a state instance with same name - maybe you forgot to make the state public?";
42 throw LocalException(msg.str());
46 result.inputParameters = statePtr->inputParameters;
48 result.outputParameters = statePtr->outputParameters;
54 StatePtr newState = StatePtr::dynamicCast(statePtr->clone());
60 if (!
input.instanceName.empty())
62 newState->setStateName(
input.instanceName);
70 remoteStateData.
id = newState->getLocalUniqueId();
76 newWrappedState->globalStateIdentifier =
input.parentStateItentifierStr;
77 newState->__setParentState(newWrappedState._ptr);
79 result.remoteStateId = remoteStateData.
id;
84 state->refetchSubstates();
85 result.statechartInstance = state;
93 const std::string& stateName,
94 const RemoteStateIceBasePrx& remoteStatePrx,
95 const std::string& parentStateItentifierStr,
96 const std::string& instanceName,
106 std::stringstream msg;
107 msg <<
"Could not find (public) state: " << stateName;
110 for (
const auto& entry : (*
impl->stateInstancesPtr))
116 msg <<
"- but found a state instance with same name - maybe you forgot to make the state public?";
121 throw LocalException(msg.str());
126 ARMARX_DEBUG <<
"entering createRemoteStateInstance() with " << parentStateItentifierStr <<
" stateclass: " << statePtr->stateClassName <<
" statename: " << statePtr->stateName <<
flush;
127 StatePtr newState = StatePtr::dynamicCast(statePtr->clone());
134 if (!instanceName.empty())
136 newState->setStateName(instanceName);
139 ARMARX_DEBUG <<
"RemoteStateInstanceName: " << newState->getStateName() <<
" instanceName=" << instanceName;
145 remoteStateData.
id = newState->getLocalUniqueId();
151 newWrappedState->globalStateIdentifier = parentStateItentifierStr;
152 newState->__setParentState(newWrappedState._ptr);
155 return remoteStateData.
id;
162 StatePtr state = wrapper->realState;
165 state->__getParentState()->globalStateIdentifier = parentId;
166 state->__updateGlobalStateIdRecursive();
174 if (state->getStatePhase() >=
eExited)
179 state->enter(properties);
196 result = stateData.
remoteWrappedState->realState->_baseOnBreak(EventPtr::dynamicCast(evt));
198 catch (
const LocalException&)
200 ARMARX_ERROR <<
"Could not find state with id " << stateId <<
" - thus cannot break it" <<
flush;
221 statePtr->__notifyEventBufferedDueToUnbreakableState(eventBuffered);
228 std::scoped_lock lock(wrapper->mutex);
229 StatePtr state = wrapper->realState;
230 state->refetchSubstates();
231 return new StateIceBase(*state);
237 return statePtr->inputParameters;
243 return statePtr->outputParameters;
261 if (statePtr->subStateList.size() > 0)
276 Ice::StringSeq result;
278 for (
unsigned int i = 0; i < subStateList.size(); ++i)
280 result.push_back(StateBasePtr::dynamicCast(subStateList.at(i))->stateName);
288 StateIdNameMap result;
290 typename std::map<int, RemoteStateData>::iterator it =
stateInstanceList.begin();
294 result[it->second.remoteWrappedState->realState->getLocalUniqueId()] = it->second.remoteWrappedState->realState->getGlobalHierarchyString();
310 state->refetchSubstates();
316 StateIceBasePtr result;
320 typename std::map<int, RemoteStateData>::iterator it =
stateInstanceList.begin();
324 StateBasePtr curState = StateBasePtr::dynamicCast(it->second.remoteWrappedState->realState);
326 if (curState->globalStateIdentifier == globalStateIdStr)
346 ARMARX_WARNING <<
"Found more than one state with globalStateIdStr '" << globalStateIdStr <<
"'. Returning first found occurence." <<
flush;
352 state->refetchSubstates();
356 ARMARX_WARNING <<
"Could not find state instance with id str '" << globalStateIdStr <<
"'";
364 std::queue<StateBasePtr> stateList;
368 stateList.push(instancePair.second.remoteWrappedState->realState);
373 if (stateList.size() > 0)
375 statePtr = stateList.front();
380 ARMARX_DEBUG <<
"Checking " << statePtr->getGlobalHierarchyString();
382 RemoteStatePtr remoteState = RemoteStatePtr::dynamicCast(statePtr);
384 if (statePtr && !remoteState)
386 for (
unsigned int i = 0; i < statePtr->subStateList.size(); i++)
388 stateList.push(StateBasePtr::dynamicCast(statePtr->subStateList.at(i)));
391 if (statePtr && statePtr->getGlobalHierarchyString() == globalStateIdStr)
396 while (stateList.size() > 0);
412 catch (LocalException& e)
414 ARMARX_WARNING <<
"Couldn't find state with id " << stateId <<
". Hence, it could not be removed.\n" <<
flush;
420 ARMARX_VERBOSE <<
"received external event '" <<
event->eventName <<
"' for state '" <<
event->eventReceiverName <<
"'" <<
flush;
428 impl->manager->addEvent(EventPtr::dynamicCast(event), statePtr);
431 catch (LocalException& local)
435 catch (
const IceUtil::Exception& exception)
439 <<
"caught ice exception: " << exception.what()
440 <<
"\nBacktrace: " << exception.ice_stackTrace()
452 catch (Ice::Exception& e)
454 ARMARX_ERROR <<
"Caught Ice::exception: " << e.what() << std::endl << e.ice_stackTrace();
471 typename std::map<int, RemoteStateData>::iterator it =
stateInstanceList.find(stateId);
475 std::stringstream
str;
476 str <<
"Could not find state with id '" << stateId <<
"'\n";
477 str <<
"Known states:\n";
482 str <<
"\t" <<
data.remoteWrappedState->stateName <<
" id: " <<
data.remoteWrappedState->getLocalUniqueId() <<
flush;
485 throw LocalException(
str.str());
494 typename std::map<int, StateBase*>::iterator it =
impl->stateInstancesPtr->find(globalId);
496 if (it !=
impl->stateInstancesPtr->end())
501 std::stringstream
str;
502 str <<
"Could not find state with id '" << globalId <<
"'";
503 throw LocalException(
str.str());
513 for (
unsigned int i = 0; i < subStateList.size(); i++)
516 StateBasePtr state = StateBasePtr::dynamicCast(subStateList.at(i));
518 if (state->stateName == stateName)
538 std::map<int, StateBasePtr> stateList;
539 std::map<int, StateBasePtr> result;
544 for (
unsigned int i = 0; i < statePtr->subStateList.size(); i++)
546 stateList.insert(std::pair<int, StateBasePtr> (StateBasePtr::dynamicCast(statePtr->subStateList.at(i))->getLocalUniqueId(), StateBasePtr::dynamicCast(statePtr->subStateList.at(i))));
549 if (parentId != statePtr->getLocalUniqueId())
551 if (StateBasePtr::dynamicCast(statePtr)->stateName == stateName)
553 result.insert(std::pair<int, StateBasePtr> (statePtr->getLocalUniqueId(), statePtr));
556 stateList.erase(statePtr->getLocalUniqueId());
559 if (stateList.size() > 0)
561 statePtr = stateList.begin()->second;
564 while (stateList.size() > 0);
571 StateIceBasePtr result;
572 StateList::iterator it = state->subStateList.begin();
574 for (; it != state->subStateList.end(); ++it)
578 if (curState->globalStateIdentifier == globalStateIdStr)
582 if (stateCounter == 1)
588 if (stateCounter == 0)
607 for (
size_t i = 0; i < subStateList.size(); i++)
613 c->disableRunFunction();
617 subStateList.clear();
621 StateControllerPtr c = StateControllerPtr::dynamicCast(e.second.remoteWrappedState->realState);
625 c->disableRunFunction();