StateBase.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 ArmarXCore::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 // Statechart Includes
26 #include "StateBase.h"
27 
28 #include "RemoteState.h"
29 #include "StateBaseImpl.h"
30 #include "StateParameter.h"
31 #include "StateUtilFunctions.h"
32 #include "StatechartManager.h"
34 
35 // ArmarX core Includes
37 
38 // boost Includes
39 #include <filesystem>
40 
41 #include <boost/regex.hpp>
42 
43 namespace armarx
44 {
45  using namespace StateUtilFunctions;
46 
50  HiddenTimedMutex* StateBase::Impl::__StateInstancesMutex = new HiddenTimedMutex();
51 
52  StateBase::StateBase() : StateIceBase(), impl(new Impl)
53 
54  {
55  impl->visitCounter = 0;
56  impl->context = nullptr;
57  impl->manager = nullptr;
58 
59  setTag(std::string("Statechart"));
60 
61  initialStateMapping = nullptr;
62 
63  reset();
65  impl->localUniqueId = Impl::__LocalIdCounter++;
66  impl->stateInstancesPtr = Impl::StateInstances;
67  (*impl->stateInstancesPtr)[impl->localUniqueId] = this;
68  }
69 
71  IceUtil::Shared(source),
72  Ice::Object(source),
73  StateIceBase(source),
74  Logging(source),
75  impl(new Impl)
76  {
77  impl->statePhase = source.impl->statePhase;
78  impl->__useRunFunction = true;
79  impl->__parentState = nullptr;
80  impl->visitCounter = 0;
81  impl->context = nullptr;
82  impl->manager = nullptr;
83 
84  setTag(std::string("Statechart"));
85  initialStateMapping = nullptr;
86 
87 
89 
91  impl->localUniqueId = Impl::__LocalIdCounter++;
92  impl->stateInstancesPtr = Impl::StateInstances;
93  (*impl->stateInstancesPtr)[impl->localUniqueId] = this;
94  }
95 
96  StateBase&
98  {
99  assert(0); //this function shouldnt be called, since it is not tested
100  deepCopy(source);
101  return *this;
102  }
103 
105  {
106  // ARMARX_INFO << "~StateBase " << stateClassName << std::endl;
107  for (unsigned int i = 0; i < subStateList.size(); i++)
108  {
109  RemoteStatePtr remoteStatePtr = RemoteStatePtr::dynamicCast(subStateList.at(i));
110 
111  if (remoteStatePtr &&
112  remoteStatePtr
113  ->getArmarXManager()) // if the remotestate was not added with addRemoteState(),
114  // this pointer is NULL
115  // (e.g. in case of creation through ObjectFactories)
116  {
117  try
118  {
119  remoteStatePtr->getArmarXManager()->removeObjectNonBlocking(
120  remoteStatePtr->getName());
121  }
122  // destructor must never throw
123  catch (...)
124  {
125  }
126  }
127  }
128 
129  {
131  impl->stateInstancesPtr->erase(impl->localUniqueId);
132  }
133  }
134 
135  void
136  StateBase::__checkPhase(StateBase::StatePhase allowedType, const char* functionName) const
137  {
138  if (allowedType != getStatePhase())
139  {
140  std::string hint;
141 
142  if (allowedType == eSubstatesDefinitions)
143  {
144  hint = "This function must be called in defineSubstates().";
145  }
146  else if (allowedType == eParametersDefinitions)
147  {
148  hint = "This function must be called in defineParameters().";
149  }
150 
151  else if (allowedType == eStatechartDefinitions)
152  {
153  hint = "This function must be called in defineState().";
154  }
155 
156  else if (allowedType == eEntering)
157  {
158  hint = "This function must be called in onEnter().";
159  }
160 
161  if (!hint.empty())
162  {
163  hint = "\n" + hint;
164  }
165 
166  std::stringstream typeStr;
167  typeStr << (int)getStatePhase() << "/" << int(allowedType);
168  throw LocalException(
169  "It is not allowed to call the function " + std::string(functionName) +
170  " here! (Current Phase/Allowed Phase): " + typeStr.str() + ") " + hint);
171  }
172  }
173 
174  void
175  StateBase::__checkPhase(const std::vector<StateBase::StatePhase>& allowedTypes,
176  const char* functionName) const
177  {
178  if (!std::any_of(allowedTypes.begin(),
179  allowedTypes.end(),
180  [&](StatePhase value) { return value == getStatePhase(); }))
181  {
182  std::string hint;
183 
184  for (auto& allowedType : allowedTypes)
185  {
186  if (!hint.empty())
187  {
188  hint += " or ";
189  }
190 
191  if (allowedType == eSubstatesDefinitions)
192  {
193  hint += "defineSubstates()";
194  }
195  else if (allowedType == eParametersDefinitions)
196  {
197  hint += "defineParameters()";
198  }
199 
200  if (allowedType == eStatechartDefinitions)
201  {
202  hint += "defineState()";
203  }
204 
205  if (allowedType == eEntering)
206  {
207  hint += "onEnter()";
208  }
209 
210  if (allowedType == eEntered)
211  {
212  hint += "onRun()";
213  }
214  }
215 
216  if (!hint.empty())
217  {
218  hint = "\nThis function must be called in " + hint;
219  }
220 
221  std::stringstream typeStr;
222  typeStr << (int)getStatePhase();
223  throw LocalException("It is not allowed to call the function " +
224  std::string(functionName) +
225  " here! (Current Phase: " + typeStr.str() + ") " + hint);
226  }
227  }
228 
229  void
230  StateBase::__checkPhaseMin(StateBase::StatePhase allowedType, const char* functionName) const
231  {
232  if (allowedType > getStatePhase())
233  {
234  std::stringstream typeStr;
235  typeStr << (int)getStatePhase() << "/" << int(allowedType);
236  throw LocalException(
237  "It is not allowed to call the function " + std::string(functionName) +
238  " here! (Current Phase/min. Allowed Phase): " + typeStr.str() + ") ");
239  }
240  }
241 
242  void
244  {
245  // currently deprecated since shared_from_this is a normal pointer
246  // Shared::__setNoDelete(true);
247  // __shared_from_this = NULL;
248  // Shared::__setNoDelete(false);
249  }
250 
251  void
253  {
254  impl->__parentState = parentState;
256  }
257 
258  void
260  {
261  if (impl->__parentState)
262  {
263  if (!impl->__parentState->globalStateIdentifier.empty())
264  {
265  globalStateIdentifier =
266  impl->__parentState->getGlobalHierarchyString() + "->" + stateName;
267  }
268  else
269  {
270  globalStateIdentifier =
271  getLocalHierarchyString(); // generate local hierarchy string
272  }
273  }
274  else
275  {
276  globalStateIdentifier = stateName;
277  }
278  }
279 
280  void
282  {
284 
285  for (unsigned int i = 0; i < subStateList.size(); i++)
286  {
287  StateBasePtr::dynamicCast(subStateList.at(i))->__updateGlobalStateIdRecursive();
288  }
289  }
290 
291  void
293  {
294  ScopedLock lock(impl->initMutex);
295  initialized = enable;
296  impl->initCondition.notify_all();
297  }
298 
299  bool
301  {
302  if (subStateList.size() > 0)
303  {
304  return true;
305  }
306 
307  return false;
308  }
309 
310  bool
312  {
313  boost::recursive_mutex::scoped_lock lock(impl->__processEventMutex);
314 
315  if (activeSubstate._ptr)
316  {
317  return true;
318  }
319 
320  return false;
321  }
322 
323  void
324  StateBase::deepCopy(const StateBase& sourceState, bool reset)
325  {
326  try
327  {
328  if (!sourceState.initialized)
329  {
331  }
332 
333 
334  StateUtilFunctions::copyDictionary(sourceState.inputParameters, inputParameters);
335  StateUtilFunctions::copyDictionary(sourceState.localParameters, localParameters);
336  StateUtilFunctions::copyDictionary(sourceState.outputParameters, outputParameters);
337  initState = nullptr;
338 
339  if (sourceState.initialStateMapping)
340  {
341  initialStateMapping = PMPtr::dynamicCast(sourceState.initialStateMapping)->clone();
342  }
343 
344  impl->__useRunFunction = sourceState.impl->__useRunFunction;
345 
346  impl->statePhase = sourceState.impl->statePhase;
347  impl->__parentState = nullptr;
348  activeSubstate = nullptr;
349  impl->context = sourceState.getContext(false);
350  impl->manager = sourceState.impl->manager;
351  impl->cancelEnteringSubstates = sourceState.impl->cancelEnteringSubstates;
352  // __eventBufferedDueToUnbreakableState = sourceState.__eventBufferedDueToUnbreakableState;
353  impl->triggeredEndstateEvent = sourceState.impl->triggeredEndstateEvent;
354 
355  if (sourceState.subStateList.size() > 0)
356  {
357  for (unsigned int i = 0; i < sourceState.subStateList.size(); i++)
358  {
359  StateBasePtr curSubstate =
360  StateBasePtr::dynamicCast(sourceState.subStateList.at(i))->clone();
361  subStateList.at(i) = curSubstate;
362 
363  if (!curSubstate._ptr)
364  {
365  throw LocalException(
366  "StatePtrePtr::dynamicCast failed in deepCopy() in file " +
367  std::string(__FILE__));
368  }
369 
370  curSubstate->impl->__parentState = this;
371 
372  if (sourceState.initState._ptr == sourceState.subStateList.at(i)._ptr)
373  {
374  initState = curSubstate;
375  }
376 
377  if (sourceState.activeSubstate._ptr == sourceState.subStateList.at(i)._ptr)
378  {
379  activeSubstate = curSubstate;
380  }
381 
382  // recreate transitionTable
383 
384  for (unsigned int j = 0; j < sourceState.transitions.size(); j++)
385  {
386  if (sourceState.transitions[j].mappingToNextStatesInput)
387  {
388  transitions[j].mappingToNextStatesInput =
389  PMPtr::dynamicCast(
390  sourceState.transitions[j].mappingToNextStatesInput)
391  ->clone();
392  }
393 
394  if (sourceState.transitions[j].mappingToParentStatesLocal)
395  {
396  transitions[j].mappingToParentStatesLocal =
397  PMPtr::dynamicCast(
398  sourceState.transitions[j].mappingToParentStatesLocal)
399  ->clone();
400  }
401 
402  if (sourceState.transitions[j].mappingToParentStatesOutput)
403  {
404  transitions[j].mappingToParentStatesOutput =
405  PMPtr::dynamicCast(
406  sourceState.transitions[j].mappingToParentStatesOutput)
407  ->clone();
408  }
409 
410  if (sourceState.transitions[j].sourceState._ptr ==
411  sourceState.subStateList.at(i)._ptr)
412  {
413  transitions[j].sourceState = curSubstate;
414  }
415 
416  if (sourceState.transitions[j].destinationState._ptr ==
417  sourceState.subStateList.at(i)._ptr)
418  {
419  transitions[j].destinationState = curSubstate;
420  }
421  }
422  }
423 
424  if (reset)
425  {
426  activeSubstate = nullptr;
427  }
428  }
429  else
430  {
431  initState = nullptr;
432  }
433  }
434  catch (...)
435  {
437  }
438  }
439 
440  bool
442  {
443  if (!context)
444  {
445  ARMARX_WARNING << "The StatechartContext should not be null" << std::endl;
446  }
447 
448  if (!manager)
449  {
450  ARMARX_WARNING << "The StatechartManager should not be null" << std::endl;
451  }
452 
453  this->impl->manager = manager;
454  this->impl->context = context;
455 
456 
458  defineState();
459  setTag("State: " + stateName);
463  defineSubstates();
467 
468 
470 
471  if (subStateList.size() > 0)
472  {
473  // // perform some logic checks
474  // if (subStateList.size() == 1)
475  // {
476  // throw exceptions::local::eStatechartLogicError("A state must contain atleast 2 substates if it has any.");
477  // }
478 
479  // bool foundFinalState = false;
480  // for(unsigned int i= 0; i < subStateList.size(); i++)
481  // if(dynamic_cast<FinalStateBase<SuccessState>*>(subStateList.at(i)._ptr) != NULL
482  // ||dynamic_cast<FinalStateBase<FailureState>*>(subStateList.at(i)._ptr) != NULL )
483  // foundFinalState = true;
484  // if(!foundFinalState)
485  // throw exceptions::local::eLogicError("A state with substates must contain a state of type FinalStateBase!");
486  if (!initState._ptr)
487  {
488  throw exceptions::local::eNullPointerException("The initial state of state '" +
489  stateName + "' was not set!");
490  }
491  }
492 
493  activeSubstate = nullptr;
494  setInitialized(true);
495  return true;
496  }
497 
499  StateBase::getContext(bool checkNULL) const
500  {
501  if (!impl->context && checkNULL)
502  {
503  throw exceptions::local::eNullPointerException("Statechart Context is NULL");
504  }
505 
506  return impl->context;
507  }
508 
509  void
511  {
512  onExit(); //if OnBreak is not overridden, class-standard OnExit() is called
513  }
514 
515  void
517  {
518  }
519 
520  void
522  {
523  impl->__useRunFunction =
524  false; // if not implemented, this function does not need to be called, so disable it after first run
525  }
526 
527  void
529  {
530  }
531 
532  void
534  {
535  this->impl->context = context;
536  }
537 
540  {
541  return outputParameters;
542  }
543 
544  std::string
546  {
547  return stateName;
548  }
549 
550  Ice::Int
552  {
553  return impl->localUniqueId;
554  }
555 
556  const std::string&
558  {
559  return stateClassName;
560  }
561 
562  std::string
564  {
565  StateIceBase* curParent = impl->__parentState;
566  std::string result;
567 
568  while (curParent)
569  {
570  result = curParent->stateName + "->" + result;
571  curParent = StateBasePtr::dynamicCast(curParent)->impl->__parentState;
572  }
573 
574  result += stateName;
575 
576  return result;
577  }
578 
579  std::string
581  {
582  return globalStateIdentifier;
583  }
584 
585  bool
586  StateBase::waitForInitialization(int timeoutMS) const
587  {
588  ScopedLock lock(impl->initMutex);
589  while (!initialized)
590  {
591  if (timeoutMS >= 0)
592  {
593  if (!impl->initCondition.timed_wait(lock,
594  boost::posix_time::milliseconds(timeoutMS)))
595  {
596  return false;
597  }
598  }
599  else
600  {
601  impl->initCondition.wait(lock);
602  }
603  }
604  return true;
605  }
606 
607  bool
609  {
610  ScopedLock lock(impl->initMutex);
611  return initialized;
612  }
613 
614  bool
616  const std::string& key,
617  VariantTypeId type,
618  bool optional,
619  VariantPtr defaultValue) const
620  {
621 
622  Variant variant;
623  variant.setType(type);
624  VariantContainerBasePtr variantContainer =
625  new SingleVariant(static_cast<const Variant&>(variant));
626  VariantContainerBasePtr defaultContainer;
627 
628  if (defaultValue)
629  {
630  const auto& data = *defaultValue;
631  defaultContainer = new SingleVariant(data);
632  }
633 
634  return addParameterContainer(
635  paramMap, key, *variantContainer->getContainerType(), optional, defaultContainer);
636  }
637 
638  bool
640  const std::string& key,
641  const ContainerType& containerType,
642  bool optional,
643  VariantContainerBasePtr defaultValue) const
644  {
645  if (key.empty())
646  {
647  throw LocalException("The key-string of a parameter must not be empty.");
648  }
649 
650  const boost::regex e("^([a-zA-Z0-9_\\.]+)$");
651 
652  if (!boost::regex_match(key, e))
653  {
654  throw LocalException("Invalid character in new key '" + key +
655  "'. Only a-zA-Z0-9_ are allowed.");
656  }
657 
658 
660  // std::string containerStrId = containerType.typeId;
661 
662  // Ice::ObjectFactoryPtr objFac = getContext()->getIceManager()->getCommunicator()->findObjectFactory(containerStrId);
663  // if(objFac)
664  // {
665  // param->value = VariantContainerBasePtr::dynamicCast(objFac->create(containerStrId));
666 
667 
668  // }
669  if (containerType.subType)
670  {
671  // it has a complex container type. the type will be set afterwards
672  param->value = new ContainerDummy();
673  }
674  else
675  {
676  Variant var = Variant();
677  var.setType(Variant::hashTypeName(containerType.typeId));
678  param->value = new SingleVariant(static_cast<const Variant&>(var));
679  }
680 
681  // else
682  // throw exceptions::local::eNullPointerException("Could not find ObjectFactory for string '"+containerStrId+"' and could not identiy VariantTypeId") << ;
683 
684  param->value->setContainerType(containerType.clone());
685 
686  if (defaultValue)
687  {
688  param->defaultValue = defaultValue->cloneContainer();
689  }
690 
691  param->optionalParam = optional;
692  param->set = false;
693 
694  if (paramMap.find(key) != paramMap.end())
695  {
696  return false;
697  }
698 
699  paramMap[key] = param;
700  return true;
701  }
702 
703  void
705  const std::string& key,
706  const Variant& variant)
707  {
708  StateParameterMap::iterator it = paramMap.find(/*stateName + ".out." + */ key);
709 
710  if (it == paramMap.end())
711  {
712  __throwUnknownParameter(paramMap, key);
713  }
714 
715  // if(it->second->value->getContainerType() != eVariantParam)
716  // throw exceptions::local::eLogicError("Cannot assign a VariantParameter to another type of a Parameter");
717  if ((it->second->value->getContainerType()->typeId !=
718  Variant::typeToString(variant.getType())))
720  "Cannot assign the parameter '" + key + "' with type '" +
721  Variant::typeToString(variant.getType()) + "' to another type of a Variant (" +
722  it->second->value->getContainerType()->typeId + ")!");
723 
724  it->second->value = new SingleVariant(variant);
725  it->second->set = true;
726  }
727 
728  void
730  const std::string& key,
731  const VariantContainerBasePtr& valueContainer)
732  {
733  setParameterContainer(paramMap, key, *valueContainer);
734  }
735 
736  void
738  const std::string& key,
739  const VariantContainerBase& valueContainer)
740  {
741  StateParameterMap::iterator it = paramMap.find(/*stateName + ".out." + */ key);
742 
743  if (it == paramMap.end())
744  {
745  __throwUnknownParameter(paramMap, key);
746  }
747 
748  if (valueContainer.getSize() > 0 &&
749  VariantContainerType::allTypesToString(it->second->value->getContainerType())
750  .find(::armarx::InvalidVariantData::ice_staticId()) == std::string::npos)
751  {
752  if (!VariantContainerType::compare(it->second->value->getContainerType(),
753  valueContainer.getContainerType()))
755  "Cannot assign the parameter container '" + key + "' with type '" +
756  VariantContainerType::allTypesToString(valueContainer.getContainerType()) +
757  "' to another type of container (" +
758  VariantContainerType::allTypesToString(it->second->value->getContainerType()) +
759  ")!");
760  }
761  auto type = it->second->value->getContainerType();
762  it->second->value = valueContainer.cloneContainer();
763  it->second->value->setContainerType(type);
764  it->second->set = true;
765  }
766 
767  void
769  const std::string& key,
770  VariantContainerBasePtr& valueContainer) const
771  {
772  StateParameterMap::const_iterator it = paramMap.find(key);
773 
774  if (it == paramMap.end())
775  {
776  __throwUnknownParameter(paramMap, key);
777  }
778 
779  if (!it->second->set)
780  {
781  throw LocalException("Requested parameter '" + key + "' was not set in state " +
782  stateName);
783  }
784 
785  valueContainer = it->second->value;
786  }
787 
788  bool
789  StateBase::isParameterSet(const StateParameterMap& paramMap, const std::string& key) const
790  {
791  StateParameterMap::const_iterator it = paramMap.find(key);
792 
793  if (it == paramMap.end())
794  {
795  throw LocalException("Requested parameter '" + key + "' not found in state " +
796  stateName);
797  }
798 
799  return it->second->set;
800  }
801 
802  void
804  const std::string& key) const
805  {
806  std::string parameters;
807 
808  for (StateParameterMap::const_iterator it = paramMap.begin(); it != paramMap.end();
809  it++, parameters += ",\n")
810  {
811  parameters +=
812  it->first + "(" +
813  VariantContainerType::allTypesToString(it->second->value->getContainerType()) + ")";
814  }
815 
817  stateName, key, "Available parameters:\n" + parameters);
818  }
819 
820  void
822  {
823  for (size_t i = 0; i < impl->inputInheritance.size(); i++)
824  {
825  StateBasePtr state = findSubstateByName(impl->inputInheritance.at(i));
826 
827  if (state)
828  {
829  StateParameterMap substateInput = state->getInputParameters();
830 
831  for (StateParameterMap::iterator it = substateInput.begin();
832  it != substateInput.end();
833  it++)
834  {
835  StateParameterIceBasePtr param = it->second;
836  addParameterContainer(inputParameters,
837  impl->inputInheritance.at(i) + "." + it->first,
838  *param->value->getContainerType(),
839  param->optionalParam);
840  }
841  }
842  }
843  }
844 
845  void
847  {
848  for (StateParameterMap::iterator i = inputParameters.begin(); i != inputParameters.end();
849  i++)
850  {
851  StateParameterIceBasePtr p = i->second;
852 
853  if (p->defaultValue)
854  {
855  p->value = p->defaultValue->cloneContainer();
856  p->set = true;
857  }
858  }
859  }
860 
862  StateBase::findSubstateByName(const std::string& substateName)
863  {
864  for (unsigned int i = 0; i < subStateList.size(); i++)
865  {
866  if (StateBasePtr::dynamicCast(subStateList.at(i))->stateName == substateName)
867  {
868  return StateBasePtr::dynamicCast(subStateList.at(i));
869  }
870  }
871 
872  return nullptr;
873  }
874 
875  void
877  const std::string& key,
878  VariantPtr& value) const
879  {
880  StateParameterMap::const_iterator it = paramMap.find(/*stateName + ".in." +*/ key);
881 
882  if (it == paramMap.end())
883  {
884  __throwUnknownParameter(paramMap, key);
885  }
886 
887  if (!it->second->set)
888  {
889  throw LocalException("Requested parameter '" + key + "' was not set in state " +
890  stateName);
891  }
892 
893  SingleVariantPtr sVar = SingleVariantPtr::dynamicCast(it->second->value);
894  if (!sVar)
895  {
896  throw InvalidTypeException("Parameter '" + key + "' is not a single variant!");
897  }
898 
899  value = sVar->get();
900  }
901 
902  void
903  StateBase::setStateClassName(std::string className)
904  {
905  // __checkPhase(eStatechartDefinitions, __PRETTY_FUNCTION__);
906  stateClassName = className;
907  }
908 
909  void
911  {
912  for (auto s : subStateList)
913  {
914  StateBasePtr state = StateBasePtr::dynamicCast(s);
915  state->refetchSubstates();
916  }
917  }
918 
919  EventPtr
921  {
922  return impl->triggeredEndstateEvent;
923  }
924 
927  {
928  ScopedLock lock(impl->statePhaseMutex);
929  return impl->statePhase;
930  }
931 
932  void
934  {
935  ScopedLock lock(impl->statePhaseMutex);
936  impl->statePhase = newPhase;
937  }
938 
939  StringVariantContainerBaseMap
941  {
942  StringVariantContainerBaseMap result = StateUtilFunctions::getSetValues(localParameters);
943  StringVariantContainerBaseMap inputSetValues =
944  StateUtilFunctions::getSetValues(inputParameters);
945  result.insert(inputSetValues.begin(), inputSetValues.end());
946  return result;
947  }
948 
949  std::vector<StateBasePtr>
951  {
952  if (!toplevelState)
953  {
954  throw LocalException("The toplevelState must not be NULL");
955  }
956 
957  std::vector<StateBasePtr> activeStates;
958  StateBasePtr activeState = toplevelState;
959  boost::recursive_mutex::scoped_lock lock(toplevelState->impl->__processEventMutex);
960 
961  while (activeState->activeSubstate)
962  {
963  activeState = StateBasePtr::dynamicCast(activeState->activeSubstate);
964  }
965 
966  activeStates.push_back(activeState);
967  return activeStates;
968  }
969 
970  void
972  {
973  impl->cancelEnteringSubstates = false;
974  stateName = "";
975  initialized = false;
976  unbreakable = false;
977  eventsDelayed = false;
978  greedyInputDictionary = false;
979  // __eventBufferedDueToUnbreakableState = false;
980  inputParameters.clear();
981  localParameters.clear();
982  outputParameters.clear();
983  subStateList.clear();
984  transitions.clear();
985  initialStateMapping = nullptr;
986  initState = nullptr;
987  activeSubstate = nullptr;
988  impl->__parentState = nullptr;
989  impl->triggeredEndstateEvent = nullptr;
990  // __unbreakableBuffer = queue<EventPtr>();
991  // __eventBuffer = vector< pair<StateBasePtr, EventPtr> >();
992  }
993 
994 } // namespace armarx
995 
996 //void armarx::StateBase::__decRef()
997 //{
998 // ARMARX_DEBUG << "DecRef of " << stateName << " of class " << stateClassName;
999 // GCShared::__decRef();
1000 //}
armarx::StateBase::getOutputParameters
virtual StateParameterMap & getOutputParameters()
Definition: StateBase.cpp:539
armarx::StateBase::eEntered
@ eEntered
Definition: StateBase.h:303
armarx::StateBase::getParameterContainer
void getParameterContainer(const StateParameterMap &paramMap, const std::string &key, VariantContainerBasePtr &valueContainer) const
Definition: StateBase.cpp:768
armarx::StateBase::getGlobalHierarchyString
std::string getGlobalHierarchyString() const
Definition: StateBase.cpp:580
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::StateBase::getContext
ContextType * getContext() const
Definition: StateBase.h:71
armarx::StateBase::eEntering
@ eEntering
Definition: StateBase.h:302
armarx::StateBase::defineParameters
virtual void defineParameters()
Virtual function, in which input/local/output parameters can be specified.
Definition: StateBase.h:186
armarx::StateBase::deepCopy
virtual void deepCopy(const StateBase &sourceState, bool reset=true)
Function to copy the states with all it substates and transitions.
Definition: StateBase.cpp:324
armarx::StateBase::setStatePhase
void setStatePhase(StatePhase newPhase)
Definition: StateBase.cpp:933
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:940
armarx::StateBase::waitForInitialization
virtual bool waitForInitialization(int timeoutMS=-1) const
Definition: StateBase.cpp:586
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:528
armarx::exceptions::local::eNotInitialized
Definition: Exception.h:72
armarx::Variant::getType
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
Return the Variant's internal type.
Definition: Variant.cpp:679
armarx::StateBase::eStatechartDefinitions
@ eStatechartDefinitions
Definition: StateBase.h:298
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:510
armarx::exceptions::local::eUnknownParameter
Definition: Exception.h:98
armarx::StateBase::operator=
StateBase & operator=(const StateBase &source)
Definition: StateBase.cpp:97
armarx::StateBase::StatePhase
StatePhase
enum that specifies the phase in which the state is currently in used to control the usage of state-f...
Definition: StateBase.h:295
armarx::StateBase::defineState
virtual void defineState()
Virtual function, in which this state can be configured.
Definition: StateBase.h:168
armarx::StateBase::__checkPhaseMin
void __checkPhaseMin(StatePhase allowedType, const char *functionName) const
Definition: StateBase.cpp:230
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:608
armarx::StateBase::setInitialized
void setInitialized(bool enable)
Definition: StateBase.cpp:292
armarx::StateBase::getStateName
std::string getStateName() const
getStateName
Definition: StateBase.cpp:545
armarx::StatechartContextInterface
Definition: StatechartContextInterface.h:45
armarx::StateBase::GetActiveStateLeafs
static std::vector< StateBasePtr > GetActiveStateLeafs(StateBasePtr toplevelState)
Definition: StateBase.cpp:950
armarx::StateBase::getLocalUniqueId
Ice::Int getLocalUniqueId() const
Definition: StateBase.cpp:551
armarx::exceptions::local::eNullPointerException
Definition: Exception.h:49
armarx::StateBase::StateBase
StateBase()
Definition: StateBase.cpp:52
StateUtilFunctions.h
armarx::StateBase::clearSelfPointer
void clearSelfPointer()
Definition: StateBase.cpp:243
armarx::ScopedLock
Mutex::scoped_lock ScopedLock
Definition: Synchronization.h:150
IceUtil
Definition: Instance.h:21
StateParameter.h
armarx::exceptions::local::eStatechartLogicError
Definition: Exception.h:30
armarx::StateBase::eDefined
@ eDefined
Definition: StateBase.h:301
armarx::StateBase::Impl::StateInstanceMap
std::map< int, StateBase * > StateInstanceMap
Definition: StateBaseImpl.h:56
armarx::StateBase::__updateGlobalStateId
void __updateGlobalStateId()
Definition: StateBase.cpp:259
armarx::StateBase::__updateGlobalStateIdRecursive
virtual void __updateGlobalStateIdRecursive()
Definition: StateBase.cpp:281
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::StateBase::Impl::StateInstances
static StateInstanceMapPtr StateInstances
Static map that contains all the states that are alive in this process.
Definition: StateBaseImpl.h:59
armarx::StateBase::setParameterContainer
void setParameterContainer(StateParameterMap &paramMap, const std::string &key, const VariantContainerBasePtr &valueContainer)
Definition: StateBase.cpp:729
armarx::StateBase::setStateClassName
void setStateClassName(std::string className)
setStateClassName() sets the string, that contains a stringrepresentation of this class....
Definition: StateBase.cpp:903
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::StateBase::reset
void reset()
Function to reset the state: clear name, clear substatesList, clear transition etc.
Definition: StateBase.cpp:971
armarx::SingleVariant
The SingleVariant class is required to store single Variant instances in VariantContainer subclasses.
Definition: VariantContainer.h:107
armarx::StateBase::Impl::__LocalIdCounter
static int __LocalIdCounter
Unique Identifier counter for this process for identifing states.
Definition: StateBaseImpl.h:37
armarx::StateBase::__copyDefaultValuesToInput
void __copyDefaultValuesToInput()
Definition: StateBase.cpp:846
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::VariantContainerType::compare
static bool compare(const ContainerTypePtr &type1, const ContainerTypePtr &secondType)
Definition: VariantContainer.cpp:219
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
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:197
RemoteState.h
armarx::StateBase::~StateBase
~StateBase() override
Definition: StateBase.cpp:104
armarx::Variant::typeToString
static std::string typeToString(VariantTypeId typeId)
Return the name of the registered type typeId.
Definition: Variant.cpp:848
armarx::StateBase::inheritInputParameters
void inheritInputParameters()
Definition: StateBase.cpp:821
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:43
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:661
armarx::StateBase::addParameter
bool addParameter(StateParameterMap &paramMap, const std::string &key, VariantTypeId type, bool optional, VariantPtr defaultValue=VariantPtr()) const
Definition: StateBase.cpp:615
armarx::StateBase::run
virtual void run()
Virtual function, that can be reimplemented to calculate complex operations.
Definition: StateBase.cpp:521
armarx::StateBase
Definition: StateBase.h:59
armarx::StateBase::__throwUnknownParameter
void __throwUnknownParameter(const StateParameterMap &paramMap, const std::string &key) const
Definition: StateBase.cpp:803
armarx::StateBase::defineSubstates
virtual void defineSubstates()
Virtual function, in which substates, transition and mappings can be added.
Definition: StateBase.h:177
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:563
armarx::StateBase::eSubstatesDefinitions
@ eSubstatesDefinitions
Definition: StateBase.h:299
armarx::StateBase::Impl::StateInstanceMapPtr
std::shared_ptr< StateInstanceMap > StateInstanceMapPtr
Definition: StateBaseImpl.h:57
StatechartManager.h
Ice
Definition: DBTypes.cpp:63
StateBase.h
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:239
armarx::StateBase::setParameter
void setParameter(StateParameterMap &paramMap, const std::string &key, const Variant &variant)
Definition: StateBase.cpp:704
armarx::StateBase::setContext
void setContext(StatechartContextInterface *context)
Definition: StateBase.cpp:533
armarx::StateBase::refetchSubstates
virtual void refetchSubstates()
This functions updates the substates.
Definition: StateBase.cpp:910
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:516
armarx::Variant::setType
void setType(VariantTypeId typeId, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's type to typeId.
Definition: Variant.cpp:343
armarx::StateBase::__setParentState
void __setParentState(StateBase *parentState)
Definition: StateBase.cpp:252
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:917
armarx::StateBase::addParameterContainer
bool addParameterContainer(StateParameterMap &paramMap, const std::string &key, const ContainerType &containerType, bool optional, VariantContainerBasePtr defaultValue=VariantContainerBasePtr()) const
Definition: StateBase.cpp:639
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:311
armarx::Variant::hashTypeName
static int hashTypeName(const std::string &typeName)
Compute and return a hash value for a given type name.
Definition: Variant.cpp:813
armarx::StateParameter::create
static StateParameterPtr create()
Definition: StateParameter.cpp:59
armarx::StateBase::getStateClassName
const std::string & getStateClassName() const
Definition: StateBase.cpp:557
armarx::StateBase::getContext
StatechartContextInterface * getContext(bool checkNULL=true) const
Definition: StateBase.cpp:499
armarx::StateBase::isParameterSet
bool isParameterSet(const StateParameterMap &paramMap, const std::string &key) const
Definition: StateBase.cpp:789
armarx::Logging::setTag
void setTag(const LogTag &tag)
Definition: Logging.cpp:54
armarx::StateBase::getStatePhase
StatePhase getStatePhase() const
Definition: StateBase.cpp:926
armarx::handleExceptions
void handleExceptions()
Definition: Exception.cpp:157
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::StateBase::eParametersDefinitions
@ eParametersDefinitions
Definition: StateBase.h:300
armarx::HiddenTimedMutex::ScopedLock
boost::unique_lock< HiddenTimedMutex > ScopedLock
Definition: Synchronization.h:139
armarx::StateBase::getTriggeredEndstateEvent
EventPtr getTriggeredEndstateEvent() const
This function returns the event that was triggered by entering an endstate.
Definition: StateBase.cpp:920
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:300
armarx::StateUtilFunctions::getSetValues
StringVariantContainerBaseMap getSetValues(const StateParameterMap &paramMap)
Definition: StateUtilFunctions.cpp:56
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:136
armarx::StateBase::impl
std::unique_ptr< Impl > impl
Definition: StateBase.h:288
armarx::ContainerDummy
Definition: VariantContainer.h:162
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::StateBase::findSubstateByName
StateBasePtr findSubstateByName(const std::string &substateName)
Utility function to find a substate of this state by the name.
Definition: StateBase.cpp:862
armarx::StateBase::Impl
Definition: StateBaseImpl.h:10
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::StatechartManager
Definition: StatechartManager.h:40
Application.h
armarx::StateBase::getParameter
void getParameter(const StateParameterMap &paramMap, const std::string &key, VariantPtr &value) const
Definition: StateBase.cpp:876
armarx::VariantContainerType::allTypesToString
static std::string allTypesToString(const ContainerTypePtr &type)
Definition: VariantContainer.cpp:250
armarx::StateBase::Impl::__StateInstancesMutex
static HiddenTimedMutex * __StateInstancesMutex
Definition: StateBaseImpl.h:38
FinalState.h
armarx::StateBase::init
bool init(StatechartContextInterface *context, StatechartManager *manager)
Function to initialize this state. Must be called in the highest level of the hierarchy - and only th...
Definition: StateBase.cpp:441