29#define STATE_NAME (demangleSymbol(typeid(MostDerived).name()).c_str())
37 class MostDerived,
class Context,
class InnerInitial = mpl::list<>,
38 sc::history_mode historyMode = sc::has_deep_history>
39class SmaccState :
public sc::simple_state<MostDerived, Context, InnerInitial, historyMode>,
42 typedef sc::simple_state<MostDerived, Context, InnerInitial, historyMode>
base_type;
68 std::is_base_of<ISmaccState, Context>::value ||
69 std::is_base_of<ISmaccStateMachine, Context>::value,
70 "The context class must be a SmaccState or a SmaccStateMachine");
72 !std::is_same<MostDerived, Context>::value,
73 "The context must be a different state or state machine "
74 "than the current state");
76 logger_.reset(
new rclcpp::Logger(
87 auto & ps = this->
template context<Context>();
98 auto key =
typeid(MostDerived).name();
99 if (smInfo.states.count(key))
101 return smInfo.
states[key].get();
125 auto * derivedThis =
static_cast<MostDerived *
>(
this);
128 std::lock_guard<std::recursive_mutex> lock(this->
getStateMachine().getMutex());
157 template <
typename T>
160 return base_type::outermost_context().getGlobalSMData(name, ret);
164 template <
typename T>
167 base_type::outermost_context().setGlobalSMData(name, value);
170 template <
typename SmaccComponentType>
173 base_type::outermost_context().requiresComponent(storage);
178 template <
typename TOrthogonal,
typename TBehavior>
180 std::function<
void(TBehavior & bh, MostDerived &)> initializationFunction)
182 configure_orthogonal_internal<TOrthogonal, TBehavior>([=](
ISmaccState * state) {
184 auto bh = state->
configure<TOrthogonal, TBehavior>();
185 initializationFunction(*bh, *(
static_cast<MostDerived *
>(state)));
189 template <
typename TOrthogonal,
typename TBehavior>
191 std::function<
void(TBehavior & bh)> initializationFunction)
193 configure_orthogonal_internal<TOrthogonal, TBehavior>([=](
ISmaccState * state) {
195 auto bh = state->
configure<TOrthogonal, TBehavior>();
196 initializationFunction(*bh);
200 template <
typename TOrthogonal,
typename TBehavior,
typename... Args>
203 configure_orthogonal_internal<TOrthogonal, TBehavior>([=](
ISmaccState * state) {
210 typename TStateReactor,
typename TOutputEvent,
typename TInputEventList,
typename... TArgs>
214 auto srh = std::make_shared<smacc2::introspection::StateReactorHandler>(
globalNh_);
215 auto srinfo = std::make_shared<SmaccStateReactorInfo>();
217 srinfo->stateReactorType = TypeInfo::getTypeInfoFromType<TStateReactor>();
218 srinfo->outputEventType = TypeInfo::getTypeInfoFromType<TOutputEvent>();
220 if (srinfo->outputEventType->templateParameters.size() == 2)
222 srinfo->objectTagType = srinfo->outputEventType->templateParameters[1];
224 else if (srinfo->outputEventType->templateParameters.size() == 1)
226 srinfo->objectTagType = TypeInfo::getTypeInfoFromType<state_reactors::EmptyObjectTag>();
232 "state reactor output events should have one or two parameters (SourceType, ObjectTag)");
236 using boost::mpl::_1;
239 boost::mpl::for_each<wrappedList>(op);
242 srh->srInfo_ = srinfo;
244 const std::type_info * tindex = &(
typeid(MostDerived));
248 std::vector<std::shared_ptr<SmaccStateReactorInfo>>();
252 state->createStateReactor<TStateReactor, TOutputEvent, TInputEventList, TArgs...>(
args...);
253 srh->configureStateReactor(sr);
254 sr->initialize(state);
263 template <
typename TEventGenerator,
typename... TUArgs>
267 auto egh = std::make_shared<smacc2::introspection::EventGeneratorHandler>();
268 auto eginfo = std::make_shared<SmaccEventGeneratorInfo>();
269 eginfo->eventGeneratorType = TypeInfo::getTypeInfoFromType<TEventGenerator>();
272 egh->egInfo_ = eginfo;
274 const std::type_info * tindex = &(
typeid(MostDerived));
278 std::vector<std::shared_ptr<SmaccEventGeneratorInfo>>();
281 auto eg = state->createEventGenerator<TEventGenerator>(
args...);
282 egh->configureEventGenerator(eg);
283 eg->initialize(state);
284 eg->template onStateAllocation<MostDerived, TEventGenerator>();
292 template <
typename TStateReactor,
typename... TUArgs>
296 auto srh = std::make_shared<smacc2::introspection::StateReactorHandler>(
globalNh_);
297 auto srinfo = std::make_shared<SmaccStateReactorInfo>();
299 srinfo->stateReactorType = TypeInfo::getTypeInfoFromType<TStateReactor>();
301 srh->srInfo_ = srinfo;
303 const std::type_info * tindex = &(
typeid(MostDerived));
307 std::vector<std::shared_ptr<SmaccStateReactorInfo>>();
310 auto sr = state->createStateReactor<TStateReactor>(
args...);
311 srh->configureStateReactor(sr);
312 sr->initialize(state);
323 auto * thisobject =
static_cast<MostDerived *
>(
this);
324 auto condition = boost::bind(conditionFn, thisobject);
325 bool conditionResult = condition();
330 this->postEvent<EvLoopContinue<MostDerived>>();
334 this->postEvent<EvLoopEnd<MostDerived>>();
361 base_type::template deep_construct_inner<inner_initial_list>(
362 pInnerContext, outermostContextBase);
369 auto state =
new MostDerived(
374 state->entryStateInternal();
377 outermostContextBase.add(pInnerContext);
378 return pInnerContext;
382 template <
typename TOrthogonal,
typename TBehavior>
384 std::function<
void(
ISmaccState * state)> initializationFunction)
392 const std::type_info * tindex = &(
typeid(MostDerived));
398 rclcpp::get_logger(
"static"),
"[states walking] State "
400 <<
"client behavior count: "
413 <<
"] creating ros subnode");
424 for (
auto & srinfo : stateReactorsVector.second)
432 const std::type_info * tindex = &(
typeid(MostDerived));
438 getLogger(),
"finding static client behaviors. State Database: "
442 for (
auto & bhinfo : staticDefinedBehaviors)
447 bhinfo.factoryFunction(
this);
450 for (
auto & sr : staticDefinedStateReactors)
454 sr->stateReactorType->getFullName().c_str());
455 sr->factoryFunction(
this);
458 for (
auto & eg : staticDefinedEventGenerators)
462 eg->eventGeneratorType->getFullName().c_str());
463 eg->factoryFunction(
this);
471 auto * derivedthis =
static_cast<MostDerived *
>(
this);
485 static_cast<MostDerived *
>(
this)->
onEntry();
rclcpp::Node::SharedPtr getNode()
void notifyOnStateExitting(StateType *state)
void disposeStateAndDisconnectSignals()
void notifyOnRuntimeConfigurationFinished(StateType *state)
void notifyOnStateExited(StateType *state)
void notifyOnStateEntryEnd(StateType *state)
const SmaccStateMachineInfo & getStateMachineInfo()
void notifyOnRuntimeConfigured(StateType *state)
void notifyOnStateEntryStart(StateType *state)
std::shared_ptr< rclcpp::Logger > logger_
rclcpp::Logger getLogger()
std::shared_ptr< TBehavior > configure(Args &&... args)
rclcpp::Node::SharedPtr node_
ISmaccState * parentState_
const smacc2::introspection::SmaccStateInfo * stateInfo_
sc::simple_state< MostDerived, Context, InnerInitial, historyMode > base_type
static inner_context_ptr_type shallow_construct(const context_ptr_type &pContext, outermost_context_base_type &outermostContextBase)
static std::shared_ptr< smacc2::introspection::StateReactorHandler > static_createStateReactor(TArgs... args)
base_type::context_ptr_type context_ptr_type
static void initial_deep_construct(outermost_context_base_type &outermostContextBase)
InnerInitial * smacc_inner_type
base_type::inner_context_ptr_type inner_context_ptr_type
void checkWhileLoopConditionAndThrowEvent(bool(MostDerived::*conditionFn)())
static void configure_orthogonal_internal(std::function< void(ISmaccState *state)> initializationFunction)
base_type::inner_initial_list inner_initial_list
static std::shared_ptr< smacc2::introspection::EventGeneratorHandler > static_createEventGenerator(TUArgs... args)
virtual ISmaccStateMachine & getStateMachine()
static std::shared_ptr< smacc2::introspection::StateReactorHandler > static_createStateReactor_aux(TUArgs... args)
const smacc2::introspection::SmaccStateInfo * getStateInfo()
bool getGlobalSMData(std::string name, T &ret)
std::string getFullName()
static void deep_construct(const context_ptr_type &pContext, outermost_context_base_type &outermostContextBase)
base_type::outermost_context_base_type outermost_context_base_type
InnerInitial LastDeepState
virtual ISmaccState * getParentState()
SmaccState(my_context ctx)
context_type::state_iterator state_iterator
std::string getName() override
void setGlobalSMData(std::string name, T value)
Context::inner_context_type context_type
static void configure_orthogonal_runtime(std::function< void(TBehavior &bh)> initializationFunction)
void throwSequenceFinishedEvent()
void requiresComponent(SmaccComponentType *&storage)
std::string getShortName()
static void configure_orthogonal_runtime(std::function< void(TBehavior &bh, MostDerived &)> initializationFunction)
static void configure_orthogonal(Args &&... args)
void entryStateInternal()
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccStateReactorInfo > > > stateReactorsInfo
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccEventGeneratorInfo > > > eventGeneratorsInfo
static std::map< const std::type_info *, std::vector< ClientBehaviorInfoEntry > > staticBehaviorInfo
std::map< std::string, std::shared_ptr< SmaccStateInfo > > states
rclcpp::Node::SharedPtr globalNh_
std::string demangleSymbol(const std::string &name)
std::string cleanShortTypeName(const std::type_info &tinfo)
void standardOnExit(TState &st, std::true_type)
void TRACEPOINT(spinOnce)
my_context(typename base_type::context_ptr_type pContext)
base_type::context_ptr_type pContext_
const std::type_info * behaviorType
const std::type_info * orthogonalType
std::function< void(smacc2::ISmaccState *)> factoryFunction
smacc2_state_onRuntimeConfigure_start
smacc2_state_onRuntimeConfigure_end
smacc2_state_onEntry_start
smacc2_state_onExit_start