SMACC2
Loading...
Searching...
No Matches
smacc2 Namespace Reference

Namespaces

namespace  anonymous_namespace{smacc_client_async_behavior.cpp}
 
namespace  client_bases
 
namespace  client_behavior_bases
 
namespace  client_behaviors
 
namespace  client_core_components
 
namespace  default_events
 
namespace  default_transition_tags
 
namespace  event_generators
 
namespace  introspection
 
namespace  state_reactors
 
namespace  utils
 

Classes

struct  AddTEventTypeStateReactor
 
struct  AddTEventTypeStateReactorInfo
 
class  CallbackCounterSemaphore
 
class  CbServiceServerCallbackBase
 
class  ClientHandler
 
struct  ComponentKey
 
struct  EvCbFailure
 
struct  EvCbFinished
 
struct  EvCbSuccess
 
class  HasSpecificNamedOnExit
 
class  HasStandardOnExit
 
class  ISmaccClient
 
class  ISmaccClientBehavior
 
class  ISmaccComponent
 
class  ISmaccOrthogonal
 
class  ISmaccState
 
class  ISmaccStateMachine
 
class  ISmaccUpdatable
 
class  Orthogonal
 
class  SignalDetector
 
class  SmaccAsyncClientBehavior
 
class  SmaccClientBehavior
 
class  SmaccEventGenerator
 
class  SmaccSignal
 
class  SmaccState
 
struct  SmaccStateMachineBase
 State Machine. More...
 
class  StateReactor
 
class  Transition
 

Typedefs

template<class T >
using deep_history = sc::deep_history<T>
 
typedef boost::signals2::connection SmaccSignalConnection
 

Enumerations

enum class  SMRunMode { DEBUG , RELEASE }
 
enum class  ComponentRequirement { SOFT , HARD }
 
enum class  ExecutionModel { SINGLE_THREAD_SPINNER , MULTI_THREAD_SPINNER }
 
enum class  EventLifeTime { ABSOLUTE , CURRENT_STATE }
 
enum class  StateMachineInternalAction {
  STATE_CONFIGURING , STATE_ENTERING , STATE_RUNNING , STATE_EXITING ,
  TRANSITIONING , STATE_MACHINE_INITIALIZING
}
 

Functions

template<typename TState , typename TTransitionTagName >
void specificNamedOnExit (TState &st, TTransitionTagName tn, std::true_type)
 
template<typename TState , typename TTransitionTagName >
void specificNamedOnExit (TState &, TTransitionTagName, std::false_type)
 
template<typename TState , typename TTransitionTagName >
void specificNamedOnExit (TState &m, TTransitionTagName tn)
 
template<typename TState >
void standardOnExit (TState &st, std::true_type)
 
template<typename TState >
void standardOnExit (TState &, std::false_type)
 
template<typename TState >
void standardOnExit (TState &m)
 
void onSigQuit (int sig)
 
template<typename StateMachineType >
void run (ExecutionModel executionModel=ExecutionModel::SINGLE_THREAD_SPINNER)
 
template<typename TAddressee >
void postStInitializationFailure (ISmaccStateMachine *stateMachine, const std::string &stateName, const std::string &what)
 
template<typename EventType , typename... Args>
boost::intrusive_ptr< EventType > makeEvent (Args &&... args)
 
static bool sleepUnlessShutdown (rclcpp::Rate &rate)
 
static void logThreadException (const rclcpp::Logger &logger, const std::string &name, const char *thread, const char *what)
 

Typedef Documentation

◆ deep_history

template<class T >
using smacc2::deep_history = sc::deep_history<T>

Definition at line 61 of file common.hpp.

◆ SmaccSignalConnection

typedef boost::signals2::connection smacc2::SmaccSignalConnection

Definition at line 33 of file smacc_signal.hpp.

Enumeration Type Documentation

◆ ComponentRequirement

enum class smacc2::ComponentRequirement
strong
Enumerator
SOFT 
HARD 

Definition at line 81 of file common.hpp.

◆ EventLifeTime

enum class smacc2::EventLifeTime
strong
Enumerator
ABSOLUTE 
CURRENT_STATE 

Definition at line 48 of file smacc_state_machine.hpp.

49{
51 CURRENT_STATE /*events are discarded if we are leaving the state it were created. I is used for client behaviors whose lifetime is associated to state*/
52};

◆ ExecutionModel

enum class smacc2::ExecutionModel
strong
Enumerator
SINGLE_THREAD_SPINNER 
MULTI_THREAD_SPINNER 

Definition at line 30 of file smacc_signal_detector.hpp.

◆ SMRunMode

enum class smacc2::SMRunMode
strong
Enumerator
DEBUG 
RELEASE 

Definition at line 75 of file common.hpp.

◆ StateMachineInternalAction

Enumerator
STATE_CONFIGURING 
STATE_ENTERING 
STATE_RUNNING 
STATE_EXITING 
TRANSITIONING 
STATE_MACHINE_INITIALIZING 

Definition at line 54 of file smacc_state_machine.hpp.

Function Documentation

◆ logThreadException()

static void smacc2::logThreadException ( const rclcpp::Logger & logger,
const std::string & name,
const char * thread,
const char * what )
static

Definition at line 75 of file smacc_client_async_behavior.cpp.

77{
78 if (rclcpp::ok())
79 {
80 RCLCPP_ERROR_STREAM(
81 logger, "[" << name << "] " << thread << " thread ended by exception: " << what);
82 }
83 else
84 {
85 RCLCPP_INFO_STREAM(
86 logger, "[" << name << "] " << thread << " thread ended by exception at shutdown: " << what);
87 }
88}

Referenced by smacc2::SmaccAsyncClientBehavior::dispose(), smacc2::SmaccAsyncClientBehavior::executeOnEntry(), and smacc2::SmaccAsyncClientBehavior::waitFutureIfNotFinished().

Here is the caller graph for this function:

◆ makeEvent()

template<typename EventType , typename... Args>
boost::intrusive_ptr< EventType > smacc2::makeEvent ( Args &&... args)

Definition at line 32 of file smacc_types.hpp.

33{
34 // The one hand-written new for events: they count their own references (MISRA C++:2023 21.6.2 deviation).
35 return boost::intrusive_ptr<EventType>(new EventType(std::forward<Args>(args)...));
36}

Referenced by smacc2::ISmaccState::configure(), cl_generic_sensor::components::CpMessageTimeout< MessageType >::onComponentInitialization(), cl_nav2z::components::CpNav2ActionInterface::onComponentInitialization(), smacc2::client_core_components::CpActionClient< ActionType >::onComponentInitialization(), smacc2::client_core_components::CpServiceClient< ServiceType >::onComponentInitialization(), cl_gcalcli::CpCalendarEventListener::onStateOrthogonalAllocation(), cl_gcalcli::CpCalendarPoller::onStateOrthogonalAllocation(), cl_moveit2z::CbMoveEndEffectorTrajectory::onStateOrthogonalAllocation(), smacc2::client_bases::SmaccActionClientBase< ActionType >::onStateOrthogonalAllocation(), smacc2::client_bases::SmaccSubscriberClient< MessageType >::onStateOrthogonalAllocation(), smacc2::client_core_components::CpTopicSubscriber< MessageType >::onStateOrthogonalAllocation(), smacc2::ISmaccComponent::postEvent(), smacc2::ISmaccStateMachine::postEvent(), cl_keyboard::CbDefaultKeyboardBehavior::postKeyEvent(), smacc2::client_bases::SmaccActionClientBase< ActionType >::postResultEvent(), smacc2::client_core_components::CpActionClient< ActionType >::postResultEvent(), postStInitializationFailure(), cl_generic_sensor::CbDefaultGenericSensorBehavior< ClientType >::propagateMessageEvent(), and smacc2::StateReactor::setOutputEvent().

Here is the caller graph for this function:

◆ onSigQuit()

void smacc2::onSigQuit ( int )

onSigQuit()

Definition at line 533 of file signal_detector.cpp.

534{
535 static const char msg[] = "SMACC: SIGQUIT received, exiting immediately\n";
536 ssize_t unused = ::write(STDERR_FILENO, msg, sizeof(msg) - 1);
537 (void)unused;
538 ::_exit(128 + SIGQUIT);
539}

Referenced by run().

Here is the caller graph for this function:

◆ postStInitializationFailure()

template<typename TAddressee >
void smacc2::postStInitializationFailure ( ISmaccStateMachine * stateMachine,
const std::string & stateName,
const std::string & what )

Definition at line 37 of file smacc_state_base.hpp.

39{
40 auto ev = makeEvent<default_events::EvStInitializationFailure<TAddressee>>();
41 ev->stateName = stateName;
42 ev->what = what;
43 using TContainer = typename TAddressee::context_type;
44 if constexpr (!std::is_base_of<ISmaccStateMachine, TContainer>::value)
45 {
46 ev->escalate = [stateMachine, stateName, what]()
47 { postStInitializationFailure<TContainer>(stateMachine, stateName, what); };
48 }
49 stateMachine->postEvent(ev, EventLifeTime::CURRENT_STATE);
50}
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)

References CURRENT_STATE, makeEvent(), smacc2::ISmaccStateMachine::postEvent(), and postStInitializationFailure().

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::onInitializationFailure(), and postStInitializationFailure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

template<typename StateMachineType >
void smacc2::run ( ExecutionModel executionModel = ExecutionModel::SINGLE_THREAD_SPINNER)

Definition at line 140 of file smacc_signal_detector.hpp.

141{
142 // SIGINT and SIGTERM are left to the handlers rclcpp::init installed. Those only signal a
143 // semaphore; a dedicated rclcpp thread then calls rclcpp::shutdown(), and the on_shutdown
144 // callback registered in SignalDetector::initialize stops the polling loop and
145 // terminates the scheduler. Replacing them here with a handler that called
146 // rclcpp::shutdown() directly ran DDS teardown inside the signal context.
147 ::signal(SIGQUIT, onSigQuit);
148
149 // create the asynchronous state machine scheduler
150 SmaccFifoScheduler scheduler1(true);
151
152 // create the signalDetector component
153 SignalDetector signalDetector(&scheduler1, executionModel);
154
155 // create the asynchronous state machine processor
156 SmaccFifoScheduler::processor_handle sm =
157 scheduler1.create_processor<StateMachineType>(&signalDetector);
158
159 // initialize the asynchronous state machine processor
160 signalDetector.setProcessorHandle(sm);
161
162 scheduler1.initiate_processor(sm);
163
164 //create a thread for the asynchronous state machine processor execution
165 boost::thread schedulerThread(boost::bind(&sc::fifo_scheduler<>::operator(), &scheduler1, 0));
166
167 // use the main thread for the signal detector component (waiting actionclient requests)
168 signalDetector.pollingLoop();
169
170 // After polling loop exits (due to shutdown), terminate the scheduler from main thread
171 // This is safe to call here (not from signal handler) as we're in the main thread context
172 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "Polling loop exited. Terminating scheduler...");
173 signalDetector.terminateScheduler();
174
175 // Wait for scheduler thread to finish
176 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "Waiting for scheduler thread to join...");
177 schedulerThread.join();
178
179 // Wait for the signal thread's Context::shutdown() before destroying anything (study, F-6); not via
180 // rclcpp::shutdown(), which uninstalls the signal handlers so a second SIGINT kills the teardown (Y).
181 if (!rclcpp::ok())
182 {
183 rclcpp::contexts::get_global_default_context()->shutdown("SMACC2 run finished");
184 }
185
186 // No transition is in progress now. Stop and join the onEntry threads of the active state's
187 // async behaviors while the state machine and this signal detector are still alive; the
188 // destructors below would otherwise do it with both half-destroyed.
189 signalDetector.joinAsyncClientBehaviorThreads();
190 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "Scheduler thread terminated. Shutdown complete.");
191}
boost::statechart::fifo_scheduler< SmaccFifoWorker, SmaccAllocator > SmaccFifoScheduler

References smacc2::SignalDetector::joinAsyncClientBehaviorThreads(), onSigQuit(), smacc2::SignalDetector::pollingLoop(), smacc2::SignalDetector::setProcessorHandle(), and smacc2::SignalDetector::terminateScheduler().

Referenced by smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sleepUnlessShutdown()

static bool smacc2::sleepUnlessShutdown ( rclcpp::Rate & rate)
static

Definition at line 368 of file signal_detector.cpp.

369{
370 try
371 {
372 rate.sleep();
373 }
374 catch (const std::runtime_error &)
375 {
376 if (rclcpp::ok())
377 {
378 throw;
379 }
380 return false;
381 }
382 return true;
383}

Referenced by smacc2::SignalDetector::pollingLoop().

Here is the caller graph for this function:

◆ specificNamedOnExit() [1/3]

template<typename TState , typename TTransitionTagName >
void smacc2::specificNamedOnExit ( TState & ,
TTransitionTagName ,
std::false_type  )

Definition at line 50 of file state_traits.hpp.

51{
52}

◆ specificNamedOnExit() [2/3]

template<typename TState , typename TTransitionTagName >
void smacc2::specificNamedOnExit ( TState & m,
TTransitionTagName tn )

Definition at line 55 of file state_traits.hpp.

56{
58 m, tn,
59 std::integral_constant<bool, HasSpecificNamedOnExit<TState, TTransitionTagName>::value>());
60}
void specificNamedOnExit(TState &st, TTransitionTagName tn, std::true_type)

References specificNamedOnExit().

Here is the call graph for this function:

◆ specificNamedOnExit() [3/3]

template<typename TState , typename TTransitionTagName >
void smacc2::specificNamedOnExit ( TState & st,
TTransitionTagName tn,
std::true_type  )

◆ standardOnExit() [1/3]

template<typename TState >
void smacc2::standardOnExit ( TState & ,
std::false_type  )

Definition at line 89 of file state_traits.hpp.

90{
91}

◆ standardOnExit() [2/3]

template<typename TState >
void smacc2::standardOnExit ( TState & m)

Definition at line 94 of file state_traits.hpp.

95{
96 standardOnExit(m, std::integral_constant<bool, HasStandardOnExit<TState>::value>());
97}
void standardOnExit(TState &st, std::true_type)

References standardOnExit().

Here is the call graph for this function:

◆ standardOnExit() [3/3]

template<typename TState >
void smacc2::standardOnExit ( TState & st,
std::true_type  )

Definition at line 83 of file state_traits.hpp.

84{
85 st.onExit();
86}

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::exit(), and standardOnExit().

Here is the caller graph for this function: