44#include <boost/function_types/function_arity.hpp>
45#include <boost/function_types/function_type.hpp>
46#include <boost/function_types/parameter_types.hpp>
48#include <smacc2_msgs/msg/smacc_status.hpp>
54template <
typename TOrthogonal>
68 "Orthogonal %s resource is being required from some state, client or component. Found "
79 ss <<
"The existing orthogonals are the following: " << std::endl;
92template <
typename TOrthogonal>
102 auto ret = std::make_shared<TOrthogonal>();
105 ret->setStateMachine(
this);
112 getLogger(),
"There were already one existing orthogonal of type "
113 <<
orthogonalkey.c_str() <<
". Skipping creation orthogonal request. ");
114 std::stringstream
ss;
115 ss <<
"The existing orthogonals are the following: " << std::endl;
126template <
typename SmaccComponentType>
136 for (
auto & client :
ortho.second->clients_)
147 getLogger(),
"component %s is required but it was not found in any orthogonal",
151 throw std::runtime_error(
"component is required but it was not found in any orthogonal");
177template <
typename EventType>
182#define eventtypename demangleSymbol<EventType>().c_str()
193 "[ISmaccStateMachine] CURRENT STATE SCOPED EVENT DISCARDED, state is exiting/transitioning "
215template <
typename EventType>
218 auto evname = smacc2::introspection::demangleSymbol<EventType>();
229 bool success =
false;
244 ret = boost::any_cast<T>(
v.second);
248 catch (boost::bad_any_cast &
ex)
269 std::stringstream
ss;
280template <
typename StateField,
typename BehaviorType>
287 behaviorType.c_str());
306 template <
typename TSmaccSignal,
typename TMemberFunctionPrototype,
typename TSmaccObjectType>
315 template <
typename TSmaccSignal,
typename TMemberFunctionPrototype,
typename TSmaccObjectType>
320 return signal.connect(
340 template <
typename TSmaccSignal,
typename TMemberFunctionPrototype,
typename TSmaccObjectType>
345 return signal.connect(
364 template <
typename TSmaccSignal,
typename TMemberFunctionPrototype,
typename TSmaccObjectType>
369 return signal.connect(
370 [=](
auto a1,
auto a2)
388 template <
typename TSmaccSignal,
typename TMemberFunctionPrototype,
typename TSmaccObjectType>
393 return signal.connect(
394 [=](
auto a1,
auto a2,
auto a3)
411template <
typename TSmaccSignal,
typename TMemberFunctionPrototype,
typename TSmaccObjectType>
418 std::is_base_of<ISmaccState, TSmaccObjectType>::value ||
419 std::is_base_of<ISmaccClient, TSmaccObjectType>::value ||
420 std::is_base_of<ISmaccClientBehavior, TSmaccObjectType>::value ||
421 std::is_base_of<StateReactor, TSmaccObjectType>::value ||
422 std::is_base_of<ISmaccComponent, TSmaccObjectType>::value,
423 "Only are accepted smacc types as subscribers for smacc signals");
427 boost::signals2::connection connection;
431 std::is_base_of<ISmaccComponent, TSmaccObjectType>::value ||
432 std::is_base_of<ISmaccClient, TSmaccObjectType>::value ||
433 std::is_base_of<ISmaccOrthogonal, TSmaccObjectType>::value ||
434 std::is_base_of<ISmaccStateMachine, TSmaccObjectType>::value)
438 "[StateMachine] long life-time smacc signal subscription created. Subscriber is %s. Callback "
446 std::is_base_of<ISmaccState, TSmaccObjectType>::value ||
447 std::is_base_of<StateReactor, TSmaccObjectType>::value ||
448 std::is_base_of<ISmaccClientBehavior, TSmaccObjectType>::value)
452 "[StateMachine] life-time constrained smacc signal subscription created. Subscriber is %s",
474 "[StateMachine] connecting signal to an unknown object with life-time unknown "
475 "behavior. It might provoke "
476 "an exception if the object is destroyed during the execution.");
484template <
typename StateType>
491 "[State Machne] Initializating a new state '%s' and updating current state. Getting state "
492 "meta-information. number of orthogonals: %ld",
500template <
typename StateType>
504 getLogger(),
"[%s] State OnEntry code finished",
516 catch (
const std::exception &
e)
520 "[Orthogonal %s] Exception on Entry - continuing with next orthogonal. Exception info: %s",
521 pair.second->getName().c_str(),
e.what());
525 for (
auto &
sr : currentState->getStateReactors())
533 catch (
const std::exception &
e)
537 "[State Reactor %s] Exception on Entry - continuing with next state reactor. Exception "
543 for (
auto &
eg : currentState->getEventGenerators())
551 catch (
const std::exception &
e)
555 "[Event generator %s] Exception on Entry - continuing with next state reactor. Exception "
568template <
typename StateType>
587template <
typename StateType>
593template <
typename StateType>
609 catch (
const std::exception &
e)
613 "[Orthogonal %s] Exception onExit - continuing with next orthogonal. Exception info: %s",
614 pair.second->getName().c_str(),
e.what());
618 for (
auto &
sr :
state->getStateReactors())
626 catch (
const std::exception &
e)
630 "[State Reactor %s] Exception on OnExit - continuing with next state reactor. Exception "
636 for (
auto &
eg :
state->getEventGenerators())
644 catch (
const std::exception &
e)
648 "[State Reactor %s] Exception on OnExit - continuing with next state reactor. Exception "
655template <
typename StateType>
673 catch (
const std::exception &
e)
677 "[Orthogonal %s] Exception onDispose - continuing with next orthogonal. Exception info: %s",
678 pair.second->getName().c_str(),
e.what());
682 for (
auto &
sr :
state->getStateReactors())
690 catch (
const std::exception &
e)
694 "[State Reactor %s] Exception on OnDispose - continuing with next state reactor. Exception "
700 for (
auto &
eg :
state->getEventGenerators())
708 catch (
const std::exception &
e)
712 "[State Reactor %s] Exception on OnDispose - continuing with next state reactor. Exception "
728template <
typename EventType>
733 st->getClassName().c_str());
734 for (
auto &
sb :
st->getStateReactors())
739 auto *
pst =
st->getParentState();
746template <
typename InitialStateType>
std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > orthogonals_
std::vector< ISmaccState * > currentState_
std::recursive_mutex eventQueueMutex_
bool getGlobalSMData(std::string name, T &ret)
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
StateMachineInternalAction stateMachineCurrentAction
std::shared_ptr< SmaccStateInfo > currentStateInfo_
rclcpp::Node::SharedPtr getNode()
std::map< std::string, std::pair< std::function< std::string()>, boost::any > > globalData_
void notifyOnStateExitting(StateType *state)
void setGlobalSMData(std::string name, T value)
TOrthogonal * getOrthogonal()
void buildStateMachineInfo()
void notifyOnRuntimeConfigurationFinished(StateType *state)
std::recursive_mutex m_mutex_
void notifyOnStateExited(StateType *state)
void lockStateMachine(std::string msg)
void notifyOnStateEntryEnd(StateType *state)
void propagateEventToStateReactors(ISmaccState *st, EventType *ev)
void disconnectSmaccSignalObject(void *object)
const SmaccStateMachineInfo & getStateMachineInfo()
void unlockStateMachine(std::string msg)
int64_t getCurrentStateCounter() const
void requiresComponent(SmaccComponentType *&storage, bool throwsExceptionIfNotExist=false)
ISmaccState * getCurrentState() const
void checkStateMachineConsistence()
SignalDetector * signalDetector_
std::map< void *, std::shared_ptr< CallbackCounterSemaphore > > stateCallbackConnections
rclcpp::Logger getLogger()
void notifyOnRuntimeConfigured(StateType *state)
std::shared_ptr< SmaccStateMachineInfo > stateMachineInfo_
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
void updateStatusMessage()
void notifyOnStateEntryStart(StateType *state)
void postEvent(EventType *ev)
void notifyStateExited(ISmaccState *currentState)
void notifyStateConfigured(ISmaccState *currentState)
std::string demangleSymbol()
void TRACEPOINT(spinOnce)
boost::signals2::connection bindaux(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object, std::shared_ptr< CallbackCounterSemaphore > callbackCounter)
boost::signals2::connection bindaux(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object, std::shared_ptr< CallbackCounterSemaphore > callbackCounter)
boost::signals2::connection bindaux(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object, std::shared_ptr< CallbackCounterSemaphore > callbackCounter)
boost::signals2::connection bindaux(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object, std::shared_ptr< CallbackCounterSemaphore > callbackCounter)
boost::signals2::connection bindaux(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object, std::shared_ptr< CallbackCounterSemaphore > callbackCounter)