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

Namespaces

namespace  client_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...
 
struct  SmExecution
 
class  StateReactor
 
class  Transition
 

Typedefs

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

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
}
 

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)
 
void onSignalShutdown (int sig)
 
template<typename StateMachineType >
void run (ExecutionModel executionModel=ExecutionModel::SINGLE_THREAD_SPINNER)
 
template<typename StateMachineType >
SmExecutionrun_async ()
 

Variables

std::atomic< bool > g_shutdown_requested {false}
 
SignalDetectorg_signal_detector = nullptr
 

Typedef Documentation

◆ deep_history

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

Definition at line 54 of file common.hpp.

Enumeration Type Documentation

◆ ComponentRequirement

enum class smacc2::ComponentRequirement
strong
Enumerator
SOFT 
HARD 

Definition at line 74 of file common.hpp.

◆ EventLifeTime

enum class smacc2::EventLifeTime
strong
Enumerator
ABSOLUTE 
CURRENT_STATE 

Definition at line 46 of file smacc_state_machine.hpp.

47{
49 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*/
50};

◆ ExecutionModel

enum class smacc2::ExecutionModel
strong
Enumerator
SINGLE_THREAD_SPINNER 
MULTI_THREAD_SPINNER 

Definition at line 29 of file smacc_signal_detector.hpp.

◆ SMRunMode

enum class smacc2::SMRunMode
strong
Enumerator
DEBUG 
RELEASE 

Definition at line 68 of file common.hpp.

◆ StateMachineInternalAction

Enumerator
STATE_CONFIGURING 
STATE_ENTERING 
STATE_RUNNING 
STATE_EXITING 
TRANSITIONING 

Definition at line 52 of file smacc_state_machine.hpp.

Function Documentation

◆ onSignalShutdown()

void smacc2::onSignalShutdown ( int sig)

Definition at line 389 of file signal_detector.cpp.

390{
391 // IMPORTANT: Signal handlers can only call async-signal-safe functions
392 // We must NOT call complex C++ methods here (like terminateScheduler)
393 // as they may use mutexes/condition variables which are not signal-safe
394
395 // Set global shutdown flag (atomic operation - signal-safe)
397
398 // Stop the signal detector loop (atomic operation - signal-safe)
399 if (g_signal_detector)
400 {
402 }
403
404 // Trigger ROS2 shutdown (this handles its own signal safety)
405 rclcpp::shutdown();
406
407 // Note: Scheduler termination will happen from main thread after polling loop exits
408}
SignalDetector * g_signal_detector
std::atomic< bool > g_shutdown_requested

References g_shutdown_requested, g_signal_detector, and smacc2::SignalDetector::stop().

Referenced by run(), and run_async().

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

◆ onSigQuit()

void smacc2::onSigQuit ( int sig)

Definition at line 410 of file signal_detector.cpp.

411{
412 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "SignalDetector: SIGQUIT received.");
413 exit(0);
414}

Referenced by run(), and run_async().

Here is the caller graph for this function:

◆ run()

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

Definition at line 124 of file smacc_signal_detector.hpp.

125{
126 // Register signal handlers for graceful shutdown
127 ::signal(SIGINT, onSignalShutdown);
128 ::signal(SIGTERM, onSignalShutdown);
129 ::signal(SIGQUIT, onSigQuit);
130
131 // create the asynchronous state machine scheduler
132 SmaccFifoScheduler scheduler1(true);
133
134 // create the signalDetector component
135 SignalDetector signalDetector(&scheduler1, executionModel);
136
137 // Store global reference for signal handler access
138 g_signal_detector = &signalDetector;
139
140 // create the asynchronous state machine processor
141 SmaccFifoScheduler::processor_handle sm =
142 scheduler1.create_processor<StateMachineType>(&signalDetector);
143
144 // initialize the asynchronous state machine processor
145 signalDetector.setProcessorHandle(sm);
146
147 scheduler1.initiate_processor(sm);
148
149 //create a thread for the asynchronous state machine processor execution
150 boost::thread schedulerThread(boost::bind(&sc::fifo_scheduler<>::operator(), &scheduler1, 0));
151
152 // use the main thread for the signal detector component (waiting actionclient requests)
153 signalDetector.pollingLoop();
154
155 // After polling loop exits (due to shutdown), terminate the scheduler from main thread
156 // This is safe to call here (not from signal handler) as we're in the main thread context
157 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "Polling loop exited. Terminating scheduler...");
158 signalDetector.terminateScheduler();
159
160 // Wait for scheduler thread to finish
161 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "Waiting for scheduler thread to join...");
162 schedulerThread.join();
163 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "Scheduler thread terminated. Shutdown complete.");
164
165 // Clear global reference
166 g_signal_detector = nullptr;
167}
void setProcessorHandle(SmaccFifoScheduler::processor_handle processorHandle)
boost::statechart::fifo_scheduler< SmaccFifoWorker, SmaccAllocator > SmaccFifoScheduler

References g_signal_detector, onSignalShutdown(), 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:

◆ run_async()

template<typename StateMachineType >
SmExecution * smacc2::run_async ( )

Definition at line 179 of file smacc_signal_detector.hpp.

180{
181 // Register signal handlers for graceful shutdown
182 ::signal(SIGINT, onSignalShutdown);
183 ::signal(SIGTERM, onSignalShutdown);
184 ::signal(SIGQUIT, onSigQuit);
185
186 SmExecution * ret = new SmExecution();
187
188 // create the asynchronous state machine scheduler
189 ret->scheduler1 = new SmaccFifoScheduler(true);
190
191 // create the signalDetector component
193
194 // Store global reference for signal handler access
196
197 // create the asynchronous state machine processor
198 ret->sm = ret->scheduler1->create_processor<StateMachineType>(ret->signalDetector);
199
200 // initialize the asynchronous state machine processor
202
203 ret->scheduler1->initiate_processor(ret->sm);
204
205 //create a thread for the asynchronous state machine processor execution
206 ret->schedulerThread =
207 new boost::thread(boost::bind(&sc::fifo_scheduler<>::operator(), ret->scheduler1, NULL));
208 ret->signalDetectorLoop =
209 new boost::thread(boost::bind(&SignalDetector::pollingLoop, ret->signalDetector));
210
211 return ret;
212}
SmaccFifoScheduler::processor_handle sm
SmaccFifoScheduler * scheduler1

References g_signal_detector, onSignalShutdown(), onSigQuit(), smacc2::SignalDetector::pollingLoop(), smacc2::SmExecution::scheduler1, smacc2::SmExecution::schedulerThread, smacc2::SignalDetector::setProcessorHandle(), smacc2::SmExecution::signalDetector, smacc2::SmExecution::signalDetectorLoop, and smacc2::SmExecution::sm.

Here is the call 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:

Variable Documentation

◆ g_shutdown_requested

std::atomic< bool > smacc2::g_shutdown_requested {false}

Definition at line 41 of file signal_detector.cpp.

41{false};

Referenced by onSignalShutdown().

◆ g_signal_detector

SignalDetector * smacc2::g_signal_detector = nullptr

Definition at line 42 of file signal_detector.cpp.

Referenced by onSignalShutdown(), run(), and run_async().