Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::ActiveObject Class Referenceabstract

#include <ActiveObject.h>

Inheritance diagram for Boardcore::ActiveObject:

Public Member Functions

 ActiveObject (unsigned int stacksize=miosix::STACK_DEFAULT_FOR_PTHREAD, miosix::Priority priority=miosix::MAIN_PRIORITY)
 
virtual ~ActiveObject ()
 
virtual bool start ()
 Start the thread associated with this active object.
 
virtual void stop ()
 Signals the runner thread to terminate and joins the thread.
 
bool isRunning ()
 

Protected Member Functions

virtual void run ()=0
 
bool shouldStop ()
 Tells whether or not the ActiveObject should stop its execution.
 

Protected Attributes

miosix::Thread * thread = nullptr
 Gives access to the thread object.
 
std::atomic< bool > stopFlag {false}
 
std::atomic< bool > running {false}
 

Detailed Description

Utility class implementing the Active Object pattern Deriving from this class causes a thread to be spawned for each instance. This thread will call the run() function.

Definition at line 38 of file ActiveObject.h.

Constructor & Destructor Documentation

◆ ActiveObject()

Boardcore::ActiveObject::ActiveObject ( unsigned int stacksize = miosix::STACK_DEFAULT_FOR_PTHREAD,
miosix::Priority priority = miosix::MAIN_PRIORITY )
inline

Constructor. This will create the AO, but will NOT start the thread associated with it. call start() in order to start the thread.

Parameters
stacksizethe stack of the thread that will be spawned
prioritypriority of the thread that will be spawned

Definition at line 109 of file ActiveObject.h.

◆ ~ActiveObject()

virtual Boardcore::ActiveObject::~ActiveObject ( )
inlinevirtual

Definition at line 50 of file ActiveObject.h.

Member Function Documentation

◆ isRunning()

bool Boardcore::ActiveObject::isRunning ( )
inline

Definition at line 144 of file ActiveObject.h.

◆ run()

virtual void Boardcore::ActiveObject::run ( )
protectedpure virtual

The thread that will be spawned just calls this function. Override it to implement your logic. Remember to frequently check for shouldStop() to see if you should terminate the execution of the thread.

Implemented in Boardcore::EventHandler, Boardcore::EventInjector, Boardcore::SignaledDeadlineTask, and Boardcore::ScreenManager.

◆ shouldStop()

bool Boardcore::ActiveObject::shouldStop ( )
inlineprotected

Tells whether or not the ActiveObject should stop its execution.

Your implementation of the run() method should periodically check this function and should terminate as soon as possible if required to.

Returns
true if the ActiveObject should stop executing.

Definition at line 146 of file ActiveObject.h.

◆ start()

bool Boardcore::ActiveObject::start ( )
inlinevirtual

Start the thread associated with this active object.

Warning
The method is not thread safe.

Call stop() to terminate execution of the thread.

Returns
true if the thread has been started.

Reimplemented in Boardcore::HSM< T >, Boardcore::HIL< FlightPhases, SimulatorData, ActuatorData >, and Boardcore::TaskScheduler.

Definition at line 115 of file ActiveObject.h.

◆ stop()

void Boardcore::ActiveObject::stop ( )
inlinevirtual

Signals the runner thread to terminate and joins the thread.

This is a blocking call that will not return until the thread terminates! Your run() implementation must check shouldStop() and terminate ASAP if it returns true.

Reimplemented in Boardcore::HIL< FlightPhases, SimulatorData, ActuatorData >, Boardcore::EventHandler, and Boardcore::TaskScheduler.

Definition at line 135 of file ActiveObject.h.

Member Data Documentation

◆ running

std::atomic<bool> Boardcore::ActiveObject::running {false}
protected

Definition at line 95 of file ActiveObject.h.

◆ stopFlag

std::atomic<bool> Boardcore::ActiveObject::stopFlag {false}
protected

Definition at line 94 of file ActiveObject.h.

◆ thread

miosix::Thread* Boardcore::ActiveObject::thread = nullptr
protected

Gives access to the thread object.

Definition at line 92 of file ActiveObject.h.


The documentation for this class was generated from the following file: