StateController.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX::statechart
19 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
20 * @date 2012
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #include "StateController.h"
26 #include "StateControllerImpl.h"
27 #include "StateBaseImpl.h"
28 #include "RemoteState.h"
29 #include "StatechartManager.h"
31 
32 #include <IceUtil/Time.h>
33 
38 #include <ArmarXCore/core/services/profiler/Profiler.h> // for ProfilerPtr
39 
41 
42 using namespace armarx;
43 using namespace StateUtilFunctions;
44 
45 
46 #define MAX_USER_CODE_DURATION 100 //milliseconds
47 
48 
49 
51  : cimpl(new Impl)
52 {
53 }
54 
56  IceUtil::Shared(source),
57  Ice::Object(source),
58  StateIceBase(source),
59  Logging(source),
61  cimpl(new Impl)
62 {
63  cimpl->transitionFunctions = source.cimpl->transitionFunctions;
64  cimpl->localProfilers = source.cimpl->localProfilers;
65  cimpl->profilersDisabled = source.cimpl->profilersDisabled;
66 }
67 
69 {
70  // ARMARX_INFO << "~StateController "<< stateClassName << " " << tag.tagName << " " << (long)this /*<< "\n" << LogSender::createBackTrace() */<< std::endl;
71  if (cimpl->__runningTask)
72  {
73  cimpl->__runningTask->stop();
74  }
75 
76  {
77  std::unique_lock lock(cimpl->__finishedMutex);
78  cimpl->__finished = true;
79  }
80 
81  cimpl->__finishedCondition.notify_all();
82 }
83 
85 {
86  std::unique_lock lock(cimpl->__finishedMutex);
87  return cimpl->__finished;
88 }
89 
90 
91 void StateController::waitForStateToFinish(int timeoutMs) const
92 {
94  ARMARX_INFO << "Waiting for state to finish";
95  std::unique_lock lock(cimpl->__finishedMutex);
96 
97  if (__getParentState())
98  {
99  throw LocalException("You can only wait for toplevel states to finish!");
100  }
101 
102  while (!cimpl->__finished)
103  {
104  if (timeoutMs == -1)
105  {
106  cimpl->__finishedCondition.wait(lock);
107  }
108  else
109  {
110  if (cimpl->__finishedCondition.wait_for(lock, std::chrono::milliseconds(timeoutMs)) == std::cv_status::timeout)
111  {
112  throw LocalException("Statechart did not finish in time");
113  }
114  }
115  }
116 }
117 
118 
119 
120 void
121 StateController::enter(const StringVariantContainerBaseMap& tempInputParameters)
122 {
123  ARMARX_TRACE;
124  __checkPhase(eDefined, __PRETTY_FUNCTION__);
125 
126  if (!isInitialized())
127  {
129  }
130 
131  if (__hasSubstates() && !initState._ptr)
132  {
133  throw exceptions::local::eNullPointerException("initState was not set!");
134  }
135 
136  for (auto& state : subStateList)
137  {
138  RemoteStatePtr remote = RemoteStatePtr::dynamicCast(state);
139  if (remote)
140  {
141  ArmarXObjectSchedulerPtr objectScheduler = remote->getObjectScheduler();
142  if (remote->getState() < eManagedIceObjectStarted)
143  {
144  ARMARX_INFO << "Waiting for remote state " << remote->getGlobalHierarchyString();
145  objectScheduler->waitForDependencies();
146  }
147  }
148  }
149  ARMARX_VERBOSE << "starting state " << stateName << " with parameters:\n" << StateUtilFunctions::getDictionaryString(tempInputParameters) << flush;
150 
151  ARMARX_TRACE;
152  //fill the inputDictionary of the entry state
153  if (tempInputParameters.size() > 0)
154  {
155  createMapping()
156  ->mapFromOutput("*", "*")
157  ->_addSourceDictionary(eOutput, tempInputParameters)
158  ->setTargetDictToGreedy(greedyInputDictionary)
159  ->_applyMapping(inputParameters);
160  }
161 
162  _baseOnEnter();
163 }
164 
165 
166 void
168 {
169  ARMARX_TRACE;
170  activeSubstate = nullptr; // line needed or not?! Pro: Finalstate will be broken on leaving of parentstate - Contra: baseOnExit() of finalstate wont be called.
171  impl->triggeredEndstateEvent = ev;
172  ARMARX_DEBUG << "Substate finished with event " << ev->eventName;
173  if (__getParentState() && StateControllerPtr::dynamicCast(__getParentState()))
174  {
175  __finalize(ev);
176  }
177  else
178  {
180  _baseOnExit();
181  STATEINFO << "Statemachine finished with event '" << ev->eventName << "' in state '" << getGlobalHierarchyString() << "'\n"
182  << "The resulting output dictionary:\n" << StateUtilFunctions::getDictionaryString(getOutputParameters()) << flush ;
183  }
184 }
185 
186 
187 // in function, so that it can be overridden in remoteStateWrapper
189 {
190  ARMARX_TRACE;
191  __enqueueEvent(event);
192 }
193 
194 
196 {
197  ARMARX_TRACE;
198  if (__getParentState())
199  {
200  ARMARX_TRACE;
201  impl->manager->addEvent(event, __getParentState());
202  }
203 }
204 
205 
206 
207 
208 
209 
210 
211 bool StateController::__applyMappings(const StateControllerPtr& srcState, const TransitionIceBase& t, const EventPtr& event, TransitionError& error)
212 {
213  ARMARX_TRACE;
214  srcState->setStatePhase(eDefined);
215 
216  // get source dictionaries and apply the mapping
217  const StringVariantContainerBaseMap parentSetInputParams = __getSetInputAndLocalParameters();
218  ARMARX_DEBUG << "Set parameters of parent " << stateName << " during transition: " << StateUtilFunctions::getDictionaryString(parentSetInputParams);
219  StringVariantContainerBaseMap srcSetOutputParams;
220 
221  if (srcState)
222  {
223  srcSetOutputParams = StateUtilFunctions::getSetValues(srcState->getOutputParameters());
224  }
225 
226  auto applyMapping = [&](const ParameterMappingIceBasePtr & icepm, StateParameterMap & targetMap, bool greedy)
227  {
228  ARMARX_TRACE;
229  PMPtr pm = PMPtr::dynamicCast(icepm);
230 
231  if (pm)
232  {
233  pm->setTargetDictToGreedy(greedy);
234 
235  // ARMARX_DEBUG_S << "The following output parameters of source state " << srcState->getStateName() << " are available: " << StateUtilFunctions::getDictionaryString(srcSetOutputParams);
236  pm->_addSourceDictionary(eParent, parentSetInputParams)
237  ->_addSourceDictionary(eOutput, srcSetOutputParams)
238  ->_addSourceDictionary(eEvent, event->properties)
239  ->_applyMapping(targetMap);
240  }
241  };
242  applyMapping(t.mappingToParentStatesLocal, localParameters, false);
243  applyMapping(t.mappingToParentStatesOutput, outputParameters, false);
244  applyMapping(t.mappingToNextStatesInput, StateBasePtr::dynamicCast(t.destinationState)->inputParameters, StateBasePtr::dynamicCast(t.destinationState)->greedyInputDictionary);
245  // ARMARX_DEBUG << "The following input parameters from parent state " << getStateName() << " are available: " << StateUtilFunctions::getDictionaryString(inputParameters);
246  std::string paramCheckOutput;
247 
248  auto transitionId = getTransitionID(t);
249  auto it = cimpl->transitionFunctions.find(transitionId);
250  if (it != cimpl->transitionFunctions.end())
251  {
252  ARMARX_TRACE;
253  transitionFunction& f = it->second;
254  f(this, StateIceBasePtr::dynamicCast(t.destinationState), StateIceBasePtr::dynamicCast(t.sourceState));
255  }
256 
257  if (!checkForCompleteParameters(StateBasePtr::dynamicCast(t.destinationState)->inputParameters, &paramCheckOutput))
258  {
259  ARMARX_TRACE;
261  error.infos.push_back(StateBasePtr::dynamicCast(t.destinationState)->stateName);
262  error.infos.push_back(paramCheckOutput);
263  __printTransitionError(error, event);
264  return false;
265  }
266 
267 
268  return true;
269 }
270 
271 void StateController::__printTransitionError(const TransitionError& transitionError, const EventPtr& event) const
272 {
273  ARMARX_TRACE;
274  switch (transitionError.errorType)
275  {
277  {
278  ARMARX_WARNING << "Could not execute transition!\nReturned reason: " + StateUtilFunctions::transitionErrorToString(transitionError.errorType) + "\nExplanations:\n"
279  << "\t- The input parameters of the destination state were not fully set.\n\tDestination state: '" << transitionError.infos.at(0) << "'\n" <<
280  transitionError.infos.at(1);
281  }
282  break;
283 
285  {
286  ARMARX_WARNING << "Could not execute transition!\nReturned reason: " + StateUtilFunctions::transitionErrorToString(transitionError.errorType) + "\nExplanations:\n"
287  << "\t- The state '" << stateName << "' does not expect the event '" << event->eventName << "' while in substate '" << StateBasePtr::dynamicCast(activeSubstate)->stateName << "'.\n" << flush;
288  }
289  break;
290 
291  default:
292  {
293  ARMARX_WARNING << "Could not execute transition!\nReturned reason: " + StateUtilFunctions::transitionErrorToString(transitionError.errorType) << flush;
294  }
295  }
296 }
297 
298 
299 void StateController::__processEvent(const EventPtr event, bool buffered)
300 {
301  ARMARX_TRACE;
302  STATEINFO << "TRANSITION due to Event '" << event->eventName << "' (EventReceiver: '" << event->eventReceiverName << "')..." << flush;
303  boost::recursive_mutex::scoped_lock lock(impl->__processEventMutex);
304 
305  if (!isInitialized())
306  {
308  }
309 
310  //check if the current state is breakable and if any parent state has events to process
311  if (!buffered
312  && __hasActiveSubstate() && !StateIceBasePtr::dynamicCast(activeSubstate)->unbreakable
314  {
315  ARMARX_WARNING << "a parent state has events to process. this event will be skipped" << flush;
316  return;
317  }
318  ARMARX_TRACE;
319 
320  TransitionError transitionError;
321  transitionError.errorType = eTransitionErrorUndefined;
322 
323  TransitionIceBase t;
324 
325  if (__findValidTransition(event, StateIceBasePtr::dynamicCast(activeSubstate), t, transitionError))
326  {
327  ARMARX_TRACE;
328  StateControllerPtr src = StateControllerPtr::dynamicCast(activeSubstate);
329 
330  if (src && src->__hasSubstates() && src->__hasActiveSubstate())
331  {
332  ARMARX_INFO << "<<<< Trying to break substates of " << src->stateName << flush;
333 
334  // Check if the active substate is unbreakable
335  if (src->__breakActiveSubstate(event))
336  {
337  src->_baseOnExit();
338  }
339  else // substate of src unbreakable
340  {
341  HiddenTimedMutex::ScopedLock lock(impl->__eventUnbreakableBufferMutex);
342  cimpl->__unbreakableBuffer.push(event);
344 
345  ARMARX_INFO << "got event while in unbreakable substate: parent stateName:" << stateName << flush;
346  return;
347  }
348  }
349  else if (src)
350  {
351  src->_baseOnExit();
352  }
353 
354  if (t.fromAll)
355  {
356  // required by StatechartLogger
357  // source state is empty if event is received as fromAll
358  t.sourceState = activeSubstate;
359  }
360 
361  // set to NULL in case mapping could not be applied, so onExit wont be called twice
362  activeSubstate = nullptr;
363  bool destinationStateInitialized = StateBasePtr::dynamicCast(t.destinationState)->waitForInitialization();
364  ARMARX_CHECK_EXPRESSION(destinationStateInitialized) << StateBasePtr::dynamicCast(t.destinationState)->stateName;
365 
366  if (__applyMappings(src, t, event, transitionError))
367  {
368  ARMARX_TRACE;
369  activeSubstate = t.destinationState;
370  if (t.sourceState && activeSubstate && !cimpl->profilersDisabled)
371  {
372  for (const Profiler::ProfilerPtr& localProfiler : cimpl->localProfilers)
373  {
374  localProfiler->logStatechartTransition(getGlobalHierarchyString(), StateIceBasePtr::dynamicCast(t.sourceState), StateIceBasePtr::dynamicCast(t.destinationState), t.evt->eventName);
375  localProfiler->logStatechartTransitionWithParameters(t);
376  }
377  }
378 
379 
380  StateControllerPtr::dynamicCast(t.destinationState)->_baseOnEnter();
381 
382  //check if unbreakable state has caused a lock
383  if (src && src->unbreakable && src->eventsDelayed)
384  {
385  ARMARX_TRACE;
387  {
388  // check if next state is unbreakable as well
389  if (StateIceBasePtr::dynamicCast(t.destinationState)->unbreakable)
390  {
391  StateIceBasePtr::dynamicCast(t.destinationState)->eventsDelayed = true;
392  }
393  else
394  {
395  __getParentState()->__processBufferedEvents();
396  }
397  }
398  }
399 
400 
401 
402  // Transition done
403  return;
404  }
405  }
406  ARMARX_TRACE;
407 
408  //no fitting transition found->throw
409  if (activeSubstate)
410  {
411  __printTransitionError(transitionError, event);
412  //throw eUnexpectedEvent(event, activeSubstate);
413  }
414  else
415  {
416  ARMARX_WARNING << "The state '" << stateName << "' does not have an activeSubstate and therefore cannot process any events." << flush;
417  }
418 }
419 
420 bool StateController::__findValidTransition(const EventPtr& event, const StateIceBasePtr& sourceState, TransitionIceBase& resultTransition, TransitionError& error) const
421 {
422  ARMARX_TRACE;
423  // loop through transition table to find the correct transition fitting to the event, activeState and DestinationState
424 
426 
427  // first check if there is a transition fitting to the input
428 
429  int selectedTransitionIndex = -1;
430 
431  for (unsigned int i = 0; i < transitions.size(); i++)
432  {
433  ARMARX_TRACE;
434  const TransitionIceBase& transition = transitions.at(i);
435 
436  if (
437  (transition.sourceState == sourceState || transition.fromAll) // correct source state
438  && transition.evt->eventName == event->eventName // correct event
439  && (sourceState->stateName == event->eventReceiverName || event->eventReceiverName == EVENTTOALL) // correct eventreceiver
440  )
441  {
442  selectedTransitionIndex = i;
443  break;
444  }
445  }
446  ARMARX_TRACE;
447 
448  if (selectedTransitionIndex == -1)
449  {
451  return false;
452  }
453 
454  const TransitionIceBase& transition = transitions.at(selectedTransitionIndex);
455 
456  resultTransition = transition;
458  return true;
459 }
460 
461 TransitionError StateController::__validateTransition(const TransitionIceBase& transition, const EventPtr event, const StateIceBasePtr& sourceState, const StateIceBasePtr& destinationState) const
462 {
463  ARMARX_TRACE;
464  TransitionError error;
465 
466  if (
467  (transition.sourceState != sourceState && !transition.fromAll) // wrong source state
468  || transition.evt->eventName != event->eventName // wrong event
469  || (sourceState && sourceState->stateName != event->eventReceiverName && event->eventReceiverName != EVENTTOALL) // wrong eventreceiver
470  )
471  {
473  return error;
474  }
475 
476 
477  if (transition.sourceState && transition.fromAll) // this should never happen
478  {
480  return error;
481  }
482 
483 
484  // get source dictionaries and apply the mapping
485  PMPtr transitionMapping = PMPtr::dynamicCast(transition.mappingToNextStatesInput);
486 
487  ARMARX_TRACE;
488  if (transitionMapping && sourceState)
489  {
490  ARMARX_TRACE;
491  const StringVariantContainerBaseMap parentSetInputParams = __getSetInputAndLocalParameters();
492  const StringVariantContainerBaseMap srcSetOutputParams = StateUtilFunctions::getSetValues(sourceState->outputParameters);
493  transitionMapping->setTargetDictToGreedy(StateBasePtr::dynamicCast(transition.destinationState)->greedyInputDictionary);
494  StateParameterMap inputCopy;
495  StateUtilFunctions::copyDictionary(destinationState->inputParameters, inputCopy);
496  transitionMapping->_addSourceDictionary(eParent, parentSetInputParams)
497  ->_addSourceDictionary(eOutput, srcSetOutputParams)
498  ->_addSourceDictionary(eEvent, event->properties)
499  ->_applyMapping(inputCopy);
500  std::string paramCheckOutput;
501 
502  if (!checkForCompleteParameters(inputCopy, &paramCheckOutput))
503  {
505  error.infos.push_back(destinationState->stateName + ": " + paramCheckOutput);
506  return error;
507  }
508  }
509 
511  return error;
512 }
513 
515 {
516  return cimpl->__unbreakableBuffer.size();
517 }
518 
520 {
521  ARMARX_TRACE;
522  cimpl->__eventBufferedDueToUnbreakableState = eventBuffered;
523 
524  for (unsigned int i = 0; i < subStateList.size(); ++i)
525  {
526  ARMARX_TRACE;
527  StateControllerPtr state = StateControllerPtr::dynamicCast(subStateList.at(i));
528 
529  if (state->__getUnbreakableBufferSize() > 0) // check if an event in this state is buffered. if it is, the eventBuffered must be set to true, otherwise dont change it
530  {
531  eventBuffered = true;
532  }
533 
534  StateControllerPtr::dynamicCast(subStateList.at(i))->__notifyEventBufferedDueToUnbreakableState(eventBuffered);
535  }
536 }
537 
538 
539 
541 {
542  ARMARX_TRACE;
543  StateControllerPtr ptr = StateControllerPtr::dynamicCast(impl->__parentState);
544 
545  if (!ptr && impl->__parentState)
546  {
547  // We can try to call the factory
548  auto newParentAsController = IceGeneratedState::createInstance();
549  armarx::StateIceBase* base = newParentAsController.get();
550  *base = *impl->__parentState;
551  ARMARX_WARNING << "Had to call factory manually for StateIceBase in "
552  << impl->__parentState->globalStateIdentifier;
553  return newParentAsController;
554  }
555 
556  return ptr;
557 }
558 
560 {
561  ARMARX_TRACE;
562  bool result = true;
563  boost::recursive_mutex::scoped_lock lock(impl->__processEventMutex);
564 
565  if (__hasActiveSubstate())
566  {
567  result = StateControllerPtr::dynamicCast(activeSubstate)->_baseOnBreak(event);
568 
569  if (result) //active substate is broken -> set to NULL
570  {
571  activeSubstate = nullptr;
572  }
573  }
574 
575  return result;
576 }
577 
578 
579 
580 
581 void
583 {
584  ARMARX_TRACE;
585  while (__getUnbreakableBufferSize() > 0)
586  {
587  ARMARX_VERBOSE << "processing " << cimpl->__unbreakableBuffer.front()->eventName << " in unbreakableBuffer - eventprocessorstate:" << stateName << " - activeState: " << StateBasePtr::dynamicCast(activeSubstate)->stateName << flush;
588  impl->__eventUnbreakableBufferMutex.lock();
589  EventPtr event = cimpl->__unbreakableBuffer.front();
590  cimpl->__unbreakableBuffer.pop();
591  impl->__eventUnbreakableBufferMutex.unlock();
592  __processEvent(event, true);
593 
594  if (__getUnbreakableBufferSize() == 0)
595  {
596  ARMARX_TRACE;
598  }
599  }
600 
601  if (__getParentState())
602  {
603  StateControllerPtr::dynamicCast(__getParentState())->__processBufferedEvents();
604  }
605 }
606 
607 
609 {
610  ARMARX_TRACE;
611  for (unsigned int i = 0; i < subStateList.size(); ++i)
612  {
613  RemoteStatePtr remoteStatePtr = RemoteStatePtr::dynamicCast(subStateList.at(i));
614 
615  if (remoteStatePtr)
616  {
617  ARMARX_TRACE;
618  ARMARX_INFO << "Waiting for RemoteState " << remoteStatePtr->getName();
619 
620  while (!(remoteStatePtr->getState() >= eManagedIceObjectStarted))
621  {
622  usleep(10);
623  }
624 
625  ARMARX_INFO << "RemoteState " << remoteStatePtr->getName() << "started.";
626  break;
627  }
628  }
629 }
630 
631 bool StateController::__checkExistenceOfTransition(const TransitionIceBase& transition)
632 {
633  for (unsigned int i = 0; i < transitions.size(); ++i)
634  {
635  ARMARX_TRACE;
636  if (transitions[i].evt->eventName == transition.evt->eventName
637  && (transition.fromAll || transitions[i].sourceState == transition.sourceState)
638  && transitions[i].destinationState == transition.destinationState
639  )
640  {
641  return true;
642  }
643  }
644 
645  return false;
646 }
647 
648 void
650 {
651  ARMARX_TRACE;
652  if (!isInitialized())
653  {
655  }
656 
657  {
658  HiddenTimedMutex::ScopedLock lock(impl->__stateMutex);
659 
660  if (cimpl->__runningTask)
661  {
662  ARMARX_TRACE;
663  try
664  {
665  if (cimpl->__runningTask->isRunning())
666  {
667  ARMARX_VERBOSE << "Waiting for running task of " << stateName << " to finish";
668  }
669 
670  cimpl->__runningTask->stop(); // this blocks until the thread has finished
671  }
672  catch (IceUtil::ThreadSyscallException& e)
673  {
674 
675  }
676  }
677 
678  eventsDelayed = false;
679 
680  //reset local & output parameters, so that they are NOT set in case we have been in this state before
681  ARMARX_DEBUG << "Resetting local and output parameters of state " << stateName;
682  StateUtilFunctions::unsetParameters(localParameters);
683  StateUtilFunctions::unsetParameters(outputParameters);
684 
685  // std::ARMARX_INFO << StateUtil::getDictionaryString(inputParameters);
686  std::string paramCheckOutput;
687 
688  if (!checkForCompleteParameters(inputParameters, &paramCheckOutput))
689  {
690  throw LocalException("Not all required inputparameters of the state '" + stateName + "' are set:\n" + paramCheckOutput);
691  }
692 
693  // overwrite status of last visit
694  impl->cancelEnteringSubstates = false;
695 
696  impl->triggeredEndstateEvent = nullptr;
697 
698  impl->visitCounter++;
699 
700  STATEINFO << "Entering State '" << getLocalHierarchyString() << "' (id: " << impl->localUniqueId << ")" << flush;
701  IceUtil::Time executionStart = IceUtil::Time::now();
702 
703  try
704  {
705  ARMARX_TRACE;
707  if (!cimpl->profilersDisabled)
708  {
709  for (const Profiler::ProfilerPtr& localProfiler : cimpl->localProfilers)
710  {
711  localProfiler->logEvent(Profiler::Profiler::EventType::eFunctionStart, getGlobalHierarchyString(), getStateName());
712  localProfiler->logStatechartInputParameters(getGlobalHierarchyString(), inputParameters);
713  }
714  }
715  onEnter();
716  }
718  {
719  }
720  catch (...)
721  {
722  ARMARX_ERROR << "onEnter() of State " << globalStateIdentifier << " of class " << stateClassName << " failed. Ignoring substates and sending Failure.\n" << GetHandledExceptionString();
723 
724  lock.unlock();
726  __enqueueEvent(new Failure(stateName));
727  return;
728 
729  }
730 
732  if (!cimpl->profilersDisabled)
733  {
734  for (const Profiler::ProfilerPtr& localProfiler : cimpl->localProfilers)
735  {
736  localProfiler->logStatechartLocalParameters(getGlobalHierarchyString(), localParameters);
737  }
738  }
739 
740  IceUtil::Time duration = IceUtil::Time::now() - executionStart;
741 
742  if (duration.toMilliSeconds() > MAX_USER_CODE_DURATION)
743  {
744  ARMARX_WARNING << "onEnter() of state '" + stateName + "' took more than " << MAX_USER_CODE_DURATION << " ms (In fact: " << duration.toMilliSeconds() << " ms). The onEnter() method should not calculate complex operations." << flush;
745  }
746  }
747 
748  {
749  ARMARX_TRACE;
750  HiddenTimedMutex::ScopedLock lock(impl->__stateMutex);
751 
752  if (!impl->cancelEnteringSubstates)
753  {
754  if (__hasSubstates())
755  {
756  impl->cancelEnteringSubstates = false;
757 
758  if (!initState)
759  {
760  ARMARX_WARNING << "No initial substate set in '" << stateName << "'" << flush;
761  }
762  else
763  {
764  StringVariantContainerBaseMap combinedMap = __getSetInputAndLocalParameters();
765  ARMARX_DEBUG << "Source for initial state: " << StateUtilFunctions::getDictionaryString(combinedMap);
766 
767  if (initialStateMapping)
768  {
769  PMPtr mapping = ParameterMappingPtr::dynamicCast(initialStateMapping);
770  mapping->_addSourceDictionary(eParent, combinedMap)
771  ->setTargetDictToGreedy(StateBasePtr::dynamicCast(initState)->greedyInputDictionary)
772  ->_applyMapping(StateBasePtr::dynamicCast(initState)->inputParameters);
773  }
774 
775  activeSubstate = initState;
776  lock.unlock();
777  if (!cimpl->profilersDisabled && activeSubstate)
778  {
779  for (const Profiler::ProfilerPtr& localProfiler : cimpl->localProfilers)
780  {
781  localProfiler->logStatechartTransition(getGlobalHierarchyString(), nullptr, StateIceBasePtr::dynamicCast(activeSubstate), "InitialTransition");
782 
783  TransitionIceBase t;
784  t.sourceState = nullptr;
785  t.destinationState = activeSubstate;
786  EventBasePtr e(new EventBase());
787  e->eventName = "InitialTransition";
788  t.evt = e;
789  localProfiler->logStatechartTransitionWithParameters(t);
790  }
791  }
792  StateControllerPtr::dynamicCast(initState)->_baseOnEnter();
793 
794  }
795  }
796  }
797  else
798  {
799  STATEINFO << "Entering substates of " << stateName << " has been canceled";
800  }
801  }
802 
803  // triggers to run the run()-Function in a separate thread
804  _startRun();
805 }
806 
807 void
809 {
810  ARMARX_TRACE;
811  HiddenTimedMutex::ScopedLock lock(impl->__stateMutex);
812 
813  if (!impl->__useRunFunction)
814  {
815  return;
816  }
817 
818  // only execute if still active state and not changed to another state in onEnter()
819  if (!impl->__parentState || impl->__parentState->activeSubstate.get() == this)
820  {
821  cimpl->__runningTask = new RunningTask<StateController>(this, &StateController::_baseRun, stateClassName + "RunningTask");
822  cimpl->__runningTask->start();
823  }
824 }
825 
826 void
828 {
829  ARMARX_TRACE;
830  try
831  {
832  run();
833  }
835  {
836  }
837  catch (...)
838  {
840  if (getStatePhase() == eEntered)
841  {
842  ARMARX_ERROR_S << "run() of State " << globalStateIdentifier << " of class " << stateClassName << " failed for unhandled reason. Ignoring substates and sending Failure\n" << GetHandledExceptionString();
843 
844  __enqueueEvent(new Failure(stateName));
845  }
846 
847  return;
848  }
849 }
850 
851 void
853 {
854  ARMARX_TRACE;
855  HiddenTimedMutex::ScopedLock lock(impl->__stateMutex);
856 
857  // substates must not be entered if onexit has already been called
858  impl->cancelEnteringSubstates = true;
859 
860  if (cimpl->__runningTask)
861  {
862  cimpl->__runningTask->stop(false);
863  //runningTask = NULL;
864  }
865 
866  if (!isInitialized())
867  {
869  }
870 
871  if (__hasActiveSubstate())
872  {
873  throw exceptions::local::eStatechartLogicError("baseOnExit was called before substates were finished - baseOnBreak must be called instead. ActiveSubstate: " + StateBasePtr::dynamicCast(activeSubstate)->stateName);
874  }
875 
876 
877  STATEINFO << "Leaving State '" << getLocalHierarchyString() << "' (id: " << impl->localUniqueId << ")" << flush;
878 
879  IceUtil::Time executionStart = IceUtil::Time::now();
880 
881  try
882  {
883  ARMARX_TRACE;
885  onExit();
886  if (!cimpl->profilersDisabled)
887  {
888  for (const Profiler::ProfilerPtr& localProfiler : cimpl->localProfilers)
889  {
890  localProfiler->logEvent(Profiler::Profiler::EventType::eFunctionReturn, getGlobalHierarchyString(), getStateName());
891  localProfiler->logStatechartLocalParameters(getGlobalHierarchyString(), localParameters);
892  localProfiler->logStatechartOutputParameters(getGlobalHierarchyString(), outputParameters);
893  }
894  }
895  }
896  catch (...)
897  {
898  ARMARX_ERROR << "onExit() of State " << globalStateIdentifier << " of class " << stateClassName << " failed\n" << GetHandledExceptionString();
899  }
900 
901  IceUtil::Time duration = IceUtil::Time::now() - executionStart;
903 
904 
906 
907 
908 
909  if (duration.toMilliSeconds() > MAX_USER_CODE_DURATION)
910  {
911  ARMARX_WARNING << "onExit() of state '" + stateName + "' took more than " << MAX_USER_CODE_DURATION << " ms (In fact: " << duration.toMilliSeconds() << " ms). The onEnter() method should not calculate complex operations." << flush;
912  }
913 
914  std::string paramCheckOutput;
915 
916  if (!checkForCompleteParameters(getOutputParameters(), &paramCheckOutput))
917  {
918  throw LocalException("Not all required Outputparameters of state '" + stateName + "' are set:\n" + paramCheckOutput);
919  }
920 
921  //reset input parameters, so that they are NOT set when we reenter this state
922  StateUtilFunctions::unsetParameters(inputParameters);
924 
925  {
926  std::unique_lock lock(cimpl->__finishedMutex);
927  cimpl->__finished = true;
928  cimpl->__finishedCondition.notify_all();
929  }
930 }
931 
932 
933 bool
935 {
936  ARMARX_TRACE;
937  HiddenTimedMutex::ScopedLock lock(impl->__stateMutex);
938 
939  if (cimpl->__runningTask)
940  {
941  cimpl->__runningTask->stop(false);
942  //runningTask = NULL;
943  }
944 
945  if (!isInitialized())
946  {
948  }
949 
950 
951 
952  bool result = true;
953 
954  if (unbreakable)
955  {
956  eventsDelayed = true;
957  result = false;
958  }
959  else if (subStateList.size() > 0 && __hasActiveSubstate())
960  {
961  // Check if the active substate is unbreakable
962  if (StateBasePtr::dynamicCast(activeSubstate)->unbreakable)
963  {
964  // signal to upper states that this state cannot be broken
965  StateBasePtr::dynamicCast(activeSubstate)->eventsDelayed = true;
966  result = false;
967  }
968  else
969  {
970  result = __breakActiveSubstate(evt);
971  }
972  }
973 
974  if (result)
975  {
976  ARMARX_TRACE;
977  STATEINFO << "Breaking State '" << getLocalHierarchyString() << "' (id: " << impl->localUniqueId << ")" << flush;
978 
979  if (cimpl->__runningTask)
980  {
981  cimpl->__runningTask->stop(false);
982  //runningTask = NULL;
983  }
984 
985  IceUtil::Time executionStart = IceUtil::Time::now();
986 
987  try
988  {
990  onBreak();
991  if (!cimpl->profilersDisabled)
992  for (const Profiler::ProfilerPtr& localProfiler : cimpl->localProfilers)
993  {
994  localProfiler->logEvent(Profiler::Profiler::EventType::eFunctionBreak, getGlobalHierarchyString(), getStateName());
995  localProfiler->logStatechartLocalParameters(getGlobalHierarchyString(), localParameters);
996  localProfiler->logStatechartOutputParameters(getGlobalHierarchyString(), outputParameters);
997  }
999  }
1000  catch (...)
1001  {
1002  ARMARX_ERROR << "onBreak() of State " << globalStateIdentifier << " of class " << stateClassName << " failed. Ignoring substates and sending Failure.\n" << GetHandledExceptionString();
1003 
1004  }
1005 
1007 
1008  IceUtil::Time duration = IceUtil::Time::now() - executionStart;
1009 
1010  if (duration.toMilliSeconds() > MAX_USER_CODE_DURATION)
1011  {
1012  ARMARX_WARNING << "onEnter() of state '" + stateName + "' took more than " << MAX_USER_CODE_DURATION << " ms (In fact: " << duration.toMilliSeconds() << " ms). The onEnter() method should not calculate complex operations." << flush;
1013  }
1014  }
1015 
1016  if (result)
1017  {
1018  //reset input parameters, so that they are NOT set when we reenter this state
1019  StateUtilFunctions::unsetParameters(inputParameters);
1021  }
1022 
1023  {
1024  std::unique_lock lock(cimpl->__finishedMutex);
1025  cimpl->__finished = true;
1026  cimpl->__finishedCondition.notify_all();
1027  }
1028 
1029  return result;
1030 }
1031 
1032 
1034 {
1035  ARMARX_TRACE;
1036  cimpl->localProfilers.insert(profiler);
1037  if (recursiveLevels < 0)
1038  {
1039  // fall through: the value -1 means that all substates should be profiled
1040  }
1041  else if (recursiveLevels == 0)
1042  {
1043  return;
1044  }
1045  else if (recursiveLevels > 0)
1046  {
1047  recursiveLevels--;
1048  }
1049 
1050  for (AbstractStateIceBasePtr state : subStateList)
1051  {
1052  StateControllerPtr stateController = StateControllerPtr::dynamicCast(state);
1053 
1054  if (stateController)
1055  {
1056  stateController->addProfilerRecursive(profiler, recursiveLevels);
1057  }
1058  }
1059 }
1060 
1062 {
1063  ARMARX_TRACE;
1064  cimpl->localProfilers.erase(profiler);
1065  if (recursiveLevels < 0)
1066  {
1067  // fall through: the value -1 means that all substates should be profiled
1068  }
1069  else if (recursiveLevels == 0)
1070  {
1071  return;
1072  }
1073  else if (recursiveLevels > 0)
1074  {
1075  recursiveLevels--;
1076  }
1077 
1078  for (AbstractStateIceBasePtr state : subStateList)
1079  {
1080  StateControllerPtr stateController = StateControllerPtr::dynamicCast(state);
1081 
1082  if (stateController)
1083  {
1084  stateController->addProfilerRecursive(profiler, recursiveLevels);
1085  }
1086  }
1087 }
1088 
1089 
1090 
1092 {
1093  ARMARX_TRACE;
1094  if (!cimpl->__runningTask)
1095  {
1096  return true;
1097  }
1098 
1099  return cimpl->__runningTask->isStopped();
1100 }
1101 
1103 {
1104  if (!cimpl->__runningTask)
1105  {
1106  return true;
1107  }
1108  return cimpl->__runningTask->isFinished();
1109 }
1110 
1112 {
1113  ARMARX_TRACE;
1114  if (cimpl->__runningTask)
1115  {
1116  cimpl->__runningTask->join();
1117  }
1118 }
1119 
1121 {
1122  cimpl->profilersDisabled = disable;
1123 }
1124 
1126 {
1127  ARMARX_INFO << "Regstering transition code for " << t.evt->eventName;
1128  cimpl->transitionFunctions[getTransitionID(t)] = function;
1129 }
1130 
1131 std::string StateController::getTransitionID(const TransitionIceBase& t) const
1132 {
1133  ARMARX_CHECK_EXPRESSION(t.evt);
1134  return getTransitionID(t.evt->eventName, (t.sourceState ? StateBasePtr::dynamicCast(t.sourceState)->stateName : std::string("")));
1135 }
1136 
1137 std::string StateController::getTransitionID(const std::string& eventName, const std::string sourceStateName) const
1138 {
1139  return sourceStateName + ":" + eventName;
1140 }
1141 
1142 bool StateController::findTransition(const std::string& eventName, const std::string sourceStateName, TransitionIceBase& transition)
1143 {
1144  ARMARX_TRACE;
1145  for (const TransitionIceBase& t : transitions)
1146  {
1147  if (t.evt->eventName == eventName && StateBasePtr::dynamicCast(t.sourceState)->stateName == sourceStateName)
1148  {
1149  transition = t;
1150  return true;
1151  }
1152  }
1153  ARMARX_INFO << "Could not find transition in " << transitions.size() << " transitions";
1154  return false;
1155 }
1156 
1157 
1158 bool
1160 {
1161  ARMARX_TRACE;
1162  // commented due to performance issues
1163  // const StateBase * curParentState = this;
1164  // while(curParentState)
1165  // {
1166  // if(curParentState->__getUnbreakableBufferSize() > 0){
1167  // return false;
1168  // }
1169  // curParentState = curParentState->__parentState;
1170  // }
1171  // return true;
1172  return !cimpl->__eventBufferedDueToUnbreakableState;
1173 }
1174 
1175 
1177 {
1178  ARMARX_TRACE;
1179  for (unsigned int i = 0; i < subStateList.size(); i++)
1180  {
1181  StateControllerPtr::dynamicCast(subStateList[i])->disableRunFunction();
1182  }
1183 
1184  HiddenTimedMutex::ScopedLock lock(impl->__stateMutex);
1185  impl->__useRunFunction = false;
1186 
1187  if (cimpl->__runningTask && cimpl->__runningTask->isRunning())
1188  {
1189  ARMARX_VERBOSE << "State with name '" << stateName << "' is waiting for the RunFunction";
1190  cimpl->__runningTask->stop();
1191  }
1192 
1193  cimpl->__runningTask = nullptr;
1194 }
1195 
armarx::StateBase::getOutputParameters
virtual StateParameterMap & getOutputParameters()
Definition: StateBase.cpp:518
MAX_USER_CODE_DURATION
#define MAX_USER_CODE_DURATION
Definition: StateController.cpp:46
armarx::StateBase::eEntered
@ eEntered
Definition: StateBase.h:273
armarx::exceptions::local::eStateAlreadyLeft
Definition: Exception.h:64
armarx::StateController::__validateTransition
TransitionError __validateTransition(const TransitionIceBase &transition, const EventPtr event, const StateIceBasePtr &sourceState, const StateIceBasePtr &destinationState) const
Definition: StateController.cpp:461
armarx::StateController::__processEvent
virtual void __processEvent(const EventPtr event, bool buffered=false)
Main function to control the statemachine/state.
Definition: StateController.cpp:299
armarx::StateBase::getGlobalHierarchyString
std::string getGlobalHierarchyString() const
Definition: StateBase.cpp:554
armarx::StateController::__getParentState
StateControllerPtr __getParentState() const
Getter function that automatically casts the parentState member of StateBase into StateControllerPtr.
Definition: StateController.cpp:540
armarx::StateBase::eEntering
@ eEntering
Definition: StateBase.h:272
armarx::StateController::findTransition
bool findTransition(const std::string &eventName, const std::string sourceStateName, TransitionIceBase &transition)
Definition: StateController.cpp:1142
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::StateController::__enqueueEvent
virtual void __enqueueEvent(const EventPtr event)
Definition: StateController.cpp:195
armarx::StateBase::setStatePhase
void setStatePhase(StatePhase newPhase)
Definition: StateBase.cpp:850
armarx::StateBase::__getSetInputAndLocalParameters
StringVariantContainerBaseMap __getSetInputAndLocalParameters() const
Combines both maps to one map and returns a new map of only the set parameters.
Definition: StateBase.cpp:856
armarx::StateController::transitionFunction
std::function< void(StateController *state, const StateIceBasePtr &nextState, const StateIceBasePtr &previousState)> transitionFunction
Definition: StateController.h:59
armarx::StateBase::onExit
virtual void onExit()
Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden,...
Definition: StateBase.cpp:506
armarx::StateController
Definition: StateController.h:55
armarx::exceptions::local::eNotInitialized
Definition: Exception.h:55
StateBaseImpl.h
armarx::StateBase::onBreak
virtual void onBreak()
Virtual function, in which the behaviour of state is defined, when it is abnormally exited....
Definition: StateBase.cpp:489
armarx::eTransitionNoError
@ eTransitionNoError
Definition: StateUtilFunctions.h:55
armarx::StateController::disableStateReporting
void disableStateReporting(bool disable=true)
Disables the reporting to profilers for this states during state visits.
Definition: StateController.cpp:1120
trace.h
armarx::StateController::isRunningTaskFinished
bool isRunningTaskFinished() const
Checks whether the run() function has already finished.
Definition: StateController.cpp:1102
armarx::StateController::_baseOnBreak
virtual bool _baseOnBreak(const EventPtr evt)
Called by StateControllerprocessEvent()-function or parentstate. Must NOT be called by user.
Definition: StateController.cpp:934
armarx::StateBase::isInitialized
virtual bool isInitialized() const
Returns the status of this state. Only if a state is initialized, it can be used.
Definition: StateBase.cpp:579
armarx::StateBase::getStateName
std::string getStateName() const
getStateName
Definition: StateBase.cpp:523
armarx::StateController::_baseOnExit
virtual void _baseOnExit()
Called by StateController::processEvent()-function or parentstate. Must NOT be called by user.
Definition: StateController.cpp:852
armarx::createMapping
ParameterMappingPtr createMapping()
Returns a new and empty instance of ParameterMapping.
Definition: ParameterMapping.cpp:235
armarx::exceptions::local::eNullPointerException
Definition: Exception.h:42
armarx::eTransitionErrorInput
@ eTransitionErrorInput
Definition: StateUtilFunctions.h:54
armarx::StateBase::clearSelfPointer
void clearSelfPointer()
Definition: StateBase.cpp:240
armarx::TransitionError::errorType
TransitionErrorType errorType
Definition: StateUtilFunctions.h:60
RunningTask.h
IceUtil
Definition: Instance.h:21
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
armarx::exceptions::local::eStatechartLogicError
Definition: Exception.h:30
armarx::StateController::__printTransitionError
void __printTransitionError(const TransitionError &transitionError, const EventPtr &event) const
Definition: StateController.cpp:271
armarx::StateBase::eDefined
@ eDefined
Definition: StateBase.h:271
StatechartObjectFactories.h
armarx::StateController::__checkExistenceOfTransition
bool __checkExistenceOfTransition(const TransitionIceBase &transition)
Definition: StateController.cpp:631
IceInternal::Handle
Definition: forward_declarations.h:8
StateController.h
armarx::GetHandledExceptionString
std::string GetHandledExceptionString()
Definition: Exception.cpp:147
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::StateController::disableRunFunction
void disableRunFunction()
disableRunFunction sets useRunFunction to false and waits (blocking) for the current StateBase::run()...
Definition: StateController.cpp:1176
armarx::eTransitionErrorUndefined
@ eTransitionErrorUndefined
Definition: StateUtilFunctions.h:52
armarx::StateController::__substatesFinished
virtual void __substatesFinished(const EventPtr ev)
Function that gets called, when a state enters a FinalSubstate. Virtual function, so that RemoteState...
Definition: StateController.cpp:167
armarx::StateController::getTransitionID
std::string getTransitionID(const TransitionIceBase &t) const
Definition: StateController.cpp:1131
armarx::StateController::__breakActiveSubstate
virtual bool __breakActiveSubstate(const EventPtr event)
Definition: StateController.cpp:559
armarx::StateBase::__copyDefaultValuesToInput
void __copyDefaultValuesToInput()
Definition: StateBase.cpp:774
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::StateController::_baseRun
virtual void _baseRun()
Definition: StateController.cpp:827
armarx::StateController::Impl
Definition: StateControllerImpl.h:12
armarx::StateController::isRunningTaskStopped
bool isRunningTaskStopped() const
isRunningTaskStopped checks whether the RunningTask, that executes run() is requested to stop.
Definition: StateController.cpp:1091
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:209
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::StateController::__waitForRemoteStates
void __waitForRemoteStates() const
Definition: StateController.cpp:608
armarx::StateUtilFunctions::copyDictionary
void copyDictionary(const StringVariantContainerBaseMap &source, StringVariantContainerBaseMap &destination)
Clears the destination map and copies the parameters of the source in it.
Definition: StateUtilFunctions.cpp:184
STATEINFO
#define STATEINFO
Definition: StateBase.h:43
RemoteState.h
armarx::StateController::addTransitionFunction
void addTransitionFunction(const TransitionIceBase &t, transitionFunction function)
Definition: StateController.cpp:1125
armarx::StateController::removeProfilerRecursive
void removeProfilerRecursive(Profiler::ProfilerPtr profiler, int recursiveLevels=0)
Definition: StateController.cpp:1061
armarx::StateController::_startRun
virtual void _startRun()
Definition: StateController.cpp:808
armarx::StateController::__findValidTransition
bool __findValidTransition(const EventPtr &event, const StateIceBasePtr &sourceState, TransitionIceBase &resultTransition, TransitionError &error) const
Definition: StateController.cpp:420
armarx::StateBase::eExited
@ eExited
Definition: StateBase.h:276
armarx::StateUtilFunctions::transitionErrorToString
std::string transitionErrorToString(TransitionErrorType type)
Definition: StateUtilFunctions.cpp:36
ArmarXObjectScheduler.h
armarx::StateController::__applyMappings
bool __applyMappings(const StateControllerPtr &srcState, const TransitionIceBase &t, const EventPtr &event, TransitionError &error)
Apply the mappings during a transitions.
Definition: StateController.cpp:211
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::StateController::~StateController
~StateController() override
Definition: StateController.cpp:68
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
armarx::StateController::cimpl
std::unique_ptr< Impl > cimpl
Definition: StateController.h:173
armarx::StateBase::run
virtual void run()
Virtual function, that can be reimplemented to calculate complex operations.
Definition: StateBase.cpp:500
armarx::StateController::__getUnbreakableBufferStati
virtual bool __getUnbreakableBufferStati() const
Before:Function to get the unbreakable-buffer status of all parent state - recursively.
Definition: StateController.cpp:1159
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::StateController::isFinished
bool isFinished() const
Definition: StateController.cpp:84
armarx::StateBase
Definition: StateBase.h:61
ExpressionException.h
armarx::StateController::__processBufferedEvents
virtual void __processBufferedEvents()
Processes buffered events, that could not be processed immediately due to unbreakable substates.
Definition: StateController.cpp:582
armarx::TransitionError
Definition: StateUtilFunctions.h:58
armarx::StateBase::getLocalHierarchyString
std::string getLocalHierarchyString() const
Function to get a string that contains als parent states and this state. (e.g. "Robot->Functional->Id...
Definition: StateBase.cpp:538
armarx::StateController::__finalize
virtual void __finalize(const EventPtr event)
Function that gets called, when a state enters a FinalSubstate. Virtual function, so that RemoteState...
Definition: StateController.cpp:188
armarx::StateUtilFunctions::getDictionaryString
std::string getDictionaryString(const StringVariantContainerBaseMap &mymap)
Converts the map into a string-representation.
Definition: StateUtilFunctions.cpp:232
StatechartManager.h
Ice
Definition: DBTypes.cpp:64
Profiler.h
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:232
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::StateController::_removeInstalledConditions
virtual void _removeInstalledConditions()
This function is implemented in StateUtil and removes all conditions that have been installed in onEn...
Definition: StateController.h:201
StateControllerImpl.h
armarx::StateController::enter
void enter(const StringVariantContainerBaseMap &tempInputParameters=StringVariantContainerBaseMap())
Function to set the statemachine in the first state and call OnEnter().
Definition: StateController.cpp:121
armarx::StateUtilFunctions::unsetParameters
void unsetParameters(StateParameterMap &paramMap)
Sets all entries of the given dictionary to the stored default values.
Definition: StateUtilFunctions.cpp:450
armarx::eTransitionErrorUnexpectedEvent
@ eTransitionErrorUnexpectedEvent
Definition: StateUtilFunctions.h:53
armarx::StateBase::onEnter
virtual void onEnter()
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
Definition: StateBase.cpp:496
IceUtil::Handle< ArmarXObjectScheduler >
armarx::StateController::StateController
StateController()
Definition: StateController.cpp:50
armarx::Profiler::ProfilerPtr
std::shared_ptr< Profiler > ProfilerPtr
Definition: ManagedIceObject.h:75
armarx::TransitionError::infos
std::vector< std::string > infos
vector to store info data in
Definition: StateUtilFunctions.h:62
armarx::StateBase::__hasActiveSubstate
virtual bool __hasActiveSubstate()
Virtual function to indicate wheter a state has an active substate or not. To be overridden by Remote...
Definition: StateBase.cpp:300
armarx::StateController::waitForRunningTaskToFinish
void waitForRunningTaskToFinish() const
Waits until the run-function has finished.
Definition: StateController.cpp:1111
armarx::StateController::addProfilerRecursive
void addProfilerRecursive(Profiler::ProfilerPtr profiler, int recursiveLevels=0)
addProfilerRecursive recursively adds a new armarx::Profiler::Profiler object as armarx::StateControl...
Definition: StateController.cpp:1033
armarx::StateBase::getStatePhase
StatePhase getStatePhase() const
Definition: StateBase.cpp:844
armarx::StateTemplate< IceGeneratedState >::createInstance
static IceInternal::Handle< StateType > createInstance(std::string stateName="")
Creates a new state instance of the type of the template parameter.
Definition: StateTemplate.h:95
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::StateBase::eBreaking
@ eBreaking
Definition: StateBase.h:274
armarx::StateController::__getUnbreakableBufferSize
virtual unsigned int __getUnbreakableBufferSize() const
Definition: StateController.cpp:514
armarx::HiddenTimedMutex::ScopedLock
boost::unique_lock< HiddenTimedMutex > ScopedLock
Definition: Synchronization.h:122
armarx::StateBase::eExiting
@ eExiting
Definition: StateBase.h:275
armarx::StateBase::__hasSubstates
virtual bool __hasSubstates()
Virtual function to indicate wheter a state has substates or not. To be overridden by RemoteState to ...
Definition: StateBase.cpp:290
armarx::StateUtilFunctions::getSetValues
StringVariantContainerBaseMap getSetValues(const StateParameterMap &paramMap)
Definition: StateUtilFunctions.cpp:54
armarx::StateController::__notifyEventBufferedDueToUnbreakableState
virtual void __notifyEventBufferedDueToUnbreakableState(bool eventBuffered=true)
Definition: StateController.cpp:519
armarx::StateBase::__checkPhase
void __checkPhase(StatePhase allowedType, const char *functionName) const
Helper function for checking if a function was called in valid position of the statechart.
Definition: StateBase.cpp:134
armarx::StateBase::impl
std::unique_ptr< Impl > impl
Definition: StateBase.h:258
armarx::StateUtilFunctions::checkForCompleteParameters
bool checkForCompleteParameters(const StateParameterMap &paramMap, std::string *logOutput=nullptr)
Definition: StateUtilFunctions.cpp:354
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::StateController::_baseOnEnter
virtual void _baseOnEnter()
Called by StateControllerprocessEvent()-function or parentstate.
Definition: StateController.cpp:649
EVENTTOALL
#define EVENTTOALL
Definition: StateBase.h:42
FinalState.h
armarx::StateController::waitForStateToFinish
void waitForStateToFinish(int timeoutMs=-1) const
waitForStateToFinish waits until this thread has finished (i.e.
Definition: StateController.cpp:91