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...
 
class  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 ()
 

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 421 of file signal_detector.cpp.

422{
423 // IMPORTANT: Signal handlers can only call async-signal-safe functions
424 // We must NOT call complex C++ methods here (like terminateScheduler)
425 // as they may use mutexes/condition variables which are not signal-safe
426
427 // Stop the signal detector loop (atomic operation - signal-safe)
428 SmExecution & smExecution = SmExecution::getInstance();
429 if (smExecution.signalDetector)
430 {
431 smExecution.signalDetector->stop();
432 }
433
434 // Trigger ROS2 shutdown (this handles its own signal safety)
435 rclcpp::shutdown();
436
437 // Note: Scheduler termination will happen from main thread after polling loop exits
438}

References smacc2::SmExecution::getInstance(), smacc2::SmExecution::signalDetector, 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 440 of file signal_detector.cpp.

441{
442 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "SignalDetector: SIGQUIT received.");
443 exit(0);
444}

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 151 of file smacc_signal_detector.hpp.

152{
153 // Register signal handlers for graceful shutdown
154 ::signal(SIGINT, onSignalShutdown);
155 ::signal(SIGTERM, onSignalShutdown);
156 ::signal(SIGQUIT, onSigQuit);
157
158 // Get singleton instance
159 SmExecution & smExecution = SmExecution::getInstance();
160
161 // create the asynchronous state machine scheduler
162 SmaccFifoScheduler scheduler1(true);
163
164 // create the signalDetector component
165 SignalDetector signalDetector(&scheduler1, executionModel);
166
167 // Store in singleton for signal handler access
168 smExecution.signalDetector = &signalDetector;
169 smExecution.scheduler1 = &scheduler1;
170
171 // create the asynchronous state machine processor
172 SmaccFifoScheduler::processor_handle sm =
173 scheduler1.create_processor<StateMachineType>(&signalDetector);
174
175 // initialize the asynchronous state machine processor
176 signalDetector.setProcessorHandle(sm);
177 smExecution.sm = sm;
178
179 scheduler1.initiate_processor(sm);
180
181 //create a thread for the asynchronous state machine processor execution
182 boost::thread schedulerThread(boost::bind(&sc::fifo_scheduler<>::operator(), &scheduler1, 0));
183 smExecution.schedulerThread = &schedulerThread;
184
185 // use the main thread for the signal detector component (waiting actionclient requests)
186 signalDetector.pollingLoop();
187
188 // After polling loop exits (due to shutdown), terminate the scheduler from main thread
189 // This is safe to call here (not from signal handler) as we're in the main thread context
190 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "Polling loop exited. Terminating scheduler...");
191 signalDetector.terminateScheduler();
192
193 // Wait for scheduler thread to finish
194 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "Waiting for scheduler thread to join...");
195 schedulerThread.join();
196 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "Scheduler thread terminated. Shutdown complete.");
197
198 // Clear singleton references
199 smExecution.signalDetector = nullptr;
200 smExecution.scheduler1 = nullptr;
201 smExecution.schedulerThread = nullptr;
202}
SmaccFifoScheduler::processor_handle sm
SmaccFifoScheduler * scheduler1
boost::statechart::fifo_scheduler< SmaccFifoWorker, SmaccAllocator > SmaccFifoScheduler

References smacc2::SmExecution::getInstance(), onSignalShutdown(), onSigQuit(), smacc2::SignalDetector::pollingLoop(), smacc2::SmExecution::scheduler1, smacc2::SmExecution::schedulerThread, smacc2::SignalDetector::setProcessorHandle(), smacc2::SmExecution::signalDetector, smacc2::SmExecution::sm, 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 205 of file smacc_signal_detector.hpp.

206{
207 // Register signal handlers for graceful shutdown
208 ::signal(SIGINT, onSignalShutdown);
209 ::signal(SIGTERM, onSignalShutdown);
210 ::signal(SIGQUIT, onSigQuit);
211
212 // Get singleton instance
213 SmExecution & smExecution = SmExecution::getInstance();
214
215 // create the asynchronous state machine scheduler
216 smExecution.scheduler1 = new SmaccFifoScheduler(true);
217
218 // create the signalDetector component
219 smExecution.signalDetector = new SignalDetector(smExecution.scheduler1);
220
221 // create the asynchronous state machine processor
222 smExecution.sm =
223 smExecution.scheduler1->create_processor<StateMachineType>(smExecution.signalDetector);
224
225 // initialize the asynchronous state machine processor
226 smExecution.signalDetector->setProcessorHandle(smExecution.sm);
227
228 smExecution.scheduler1->initiate_processor(smExecution.sm);
229
230 //create a thread for the asynchronous state machine processor execution
231 smExecution.schedulerThread =
232 new boost::thread(boost::bind(&sc::fifo_scheduler<>::operator(), smExecution.scheduler1, NULL));
233 smExecution.signalDetectorLoop =
234 new boost::thread(boost::bind(&SignalDetector::pollingLoop, smExecution.signalDetector));
235
236 return smExecution;
237}
void setProcessorHandle(SmaccFifoScheduler::processor_handle processorHandle)

References smacc2::SmExecution::getInstance(), 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: