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();