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

405{
406 // IMPORTANT: Signal handlers can only call async-signal-safe functions
407 // We must NOT call complex C++ methods here (like terminateScheduler)
408 // as they may use mutexes/condition variables which are not signal-safe
409
410 // Stop the signal detector loop (atomic operation - signal-safe)
411 SmExecution & smExecution = SmExecution::getInstance();
412 if (smExecution.signalDetector)
413 {
414 smExecution.signalDetector->stop();
415 }
416
417 // Trigger ROS2 shutdown (this handles its own signal safety)
418 rclcpp::shutdown();
419
420 // Note: Scheduler termination will happen from main thread after polling loop exits
421}

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

424{
425 RCLCPP_INFO(rclcpp::get_logger("SMACC"), "SignalDetector: SIGQUIT received.");
426 exit(0);
427}

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

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

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