discoLight
Loading...
Searching...
No Matches
SWE4211RPi::RunnableClass Class Referenceabstract

#include <RunnableClass.h>

Inheritance diagram for SWE4211RPi::RunnableClass:

Public Member Functions

 RunnableClass (std::string threadName, int priority=0)
 
virtual ~RunnableClass ()
 
virtual void resetThreadDiagnostics ()
 
virtual void printInformation ()
 
virtual double getCPUUsageInfo ()
 
virtual pid_t getThreadID ()
 
virtual void start () final
 
virtual void setPriority (int priority) final
 
virtual int getPriority () final
 
virtual void run ()=0
 
virtual bool isShutdown () final
 
virtual bool isStarted () final
 
virtual void stopThreadExecution ()
 
virtual void waitForShutdown ()
 

Static Public Member Functions

static void printThreads ()
 
static void resetAllThreadInformation ()
 

Protected Member Functions

virtual void startChildRunnables ()
 
virtual void stopChildRunnables ()
 

Protected Attributes

std::thread * myThread = NULL
 
pthread_t executingThread = 0
 
pid_t myOSThreadID = 0
 
std::string myName
 
bool keepGoing = true
 
bool runCompleted = false
 
bool runStarted = false
 
int priority = -1
 

Static Protected Attributes

static std::list< RunnableClass * > runningThreads
 

Private Member Functions

virtual void invokeRunMethod () final
 

Detailed Description

This is the runnable class, which mimics the runnable interface from Java. It is a virtual class which should not directly be instantiated.

Constructor & Destructor Documentation

◆ RunnableClass()

RunnableClass::RunnableClass ( std::string  threadName,
int  priority = 0 
)

This is the default constructor for the class.

Parameters
threadNameThis is the name of the thread in a human readable format.
priorityThis is the priority for the task. By default, will be 0 unless another priority is passed into the constructor.

This is the default constructor for the class.

Parameters
threadNameThis is the name of the thread in a human readable format.

◆ ~RunnableClass()

RunnableClass::~RunnableClass ( )
virtual

This is the default destructor for the class. It must properly clean up the instantiated thread.

If the thread is not NULL, delete it.

Member Function Documentation

◆ getCPUUsageInfo()

double RunnableClass::getCPUUsageInfo ( )
virtual

This method will return the CPU usage for the given task. The usage will be as a percentage value.

Note that for a simple runnable class, we do not currently have this metric.

Reimplemented in SWE4211RPi::FreeRunningRepeatingTask, and SWE4211RPi::PeriodicTask.

Here is the caller graph for this function:

◆ getPriority()

int RunnableClass::getPriority ( )
finalvirtual

This method will obtain the priority set for this runnable class.

Returns
The return will be the set priority for the runnable class.
Here is the caller graph for this function:

◆ getThreadID()

pid_t RunnableClass::getThreadID ( )
virtual

This method will obtain the thread ID for this runnable.

Returns
The OS Thread ID.

◆ invokeRunMethod()

void RunnableClass::invokeRunMethod ( )
finalprivatevirtual

This private method initializes the runnable class. It is actually the method invoked when the thread starts, and it will ultimately call the Run method.

This private method initializes the runnable class. It is actually the method invoked when the thread starts.

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

◆ isShutdown()

bool RunnableClass::isShutdown ( )
finalvirtual

This method will determine if the given thread is shutdown.

Returns
The return will be true if the thread is shutdown or false otherwise.

◆ isStarted()

bool RunnableClass::isStarted ( )
finalvirtual

This method will determine if the given runnable class has been started or not.

Returns
true if the task has been started. False otherwise.

◆ printInformation()

void RunnableClass::printInformation ( )
virtual

This method will print out information about the given thread. The info will be dependent upon the given thread.

Reimplemented in SWE4211RPi::FreeRunningRepeatingTask, and SWE4211RPi::PeriodicTask.

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

◆ printThreads()

void RunnableClass::printThreads ( )
static

This method will print out to the console each of the running threads and their thread ID's.

Here is the call graph for this function:

◆ resetAllThreadInformation()

void RunnableClass::resetAllThreadInformation ( )
static

This method will reset the thread information which is dynamic in nature and changes as the robot runs. This predominantly impacts threads which are not part of the Runnable class.

Here is the call graph for this function:

◆ resetThreadDiagnostics()

void RunnableClass::resetThreadDiagnostics ( )
virtual

This method will reset thread diagnostics back to their default values.

Reimplemented in SWE4211RPi::FreeRunningRepeatingTask, and SWE4211RPi::PeriodicTask.

Here is the caller graph for this function:

◆ run()

virtual void SWE4211RPi::RunnableClass::run ( )
pure virtual

This is the virtual run method. It will execute the given code that is to be executed by this class.

Implemented in SWE4211RPi::NetworkManager, SWE4211RPi::FreeRunningRepeatingTask, SWE4211RPi::GenericThreadInfo, and SWE4211RPi::PeriodicTask.

Here is the caller graph for this function:

◆ setPriority()

void RunnableClass::setPriority ( int  priority)
finalvirtual

This method will set the priority for the given task, using the real time FIFO scheduler as well as setting the priority.

Parameters
priorityThis is the priority for the task. It must be between 0 and 99, with 99 being the highest priority.

This method will set the priority for the given task.

Parameters
priorityThis is the priority for the task. It must be between 0 and 99, with 99 being the highest priority.
Here is the caller graph for this function:

◆ start()

void RunnableClass::start ( )
finalvirtual

This virtual method is the start method. It must be implemented in child classes. The purpose of this method is to instantiate a new thread and invoke the run method. This method will cause the task to start with the default priority.

Here is the call graph for this function:

◆ startChildRunnables()

void RunnableClass::startChildRunnables ( )
protectedvirtual

This method will start up any runnable objects which are contained within a class that implements the RUnnable interface. If there are no other objects that are runnable, there is no need to override this method. However, if a child class contains an instance of a runnable object, then this method must be overridden in the derived class.

This default implementation does nothing.

Reimplemented in SWE4211RPi::FreeRunningRepeatingTask, and SWE4211RPi::PeriodicTask.

Here is the caller graph for this function:

◆ stopChildRunnables()

void RunnableClass::stopChildRunnables ( )
protectedvirtual

This method will stop any runnable objects which are contained within a class that implements the Runnable interface. If there are no other objects that are runnable, there is no need to override this method. However, if a child class contains an instance of a runnable object, then this method must be overridden in the derived class.

This default implementation does nothing.

Reimplemented in SWE4211RPi::FreeRunningRepeatingTask, and SWE4211RPi::PeriodicTask.

Here is the caller graph for this function:

◆ stopThreadExecution()

void RunnableClass::stopThreadExecution ( )
virtual

This method will stop the execution of the given class.

Stop the thread by changing the value of keepGoing if the thread is running. If there is a child class that has a RUnnable object inside of it, then stop must be called on that object.

Reimplemented in SWE4211RPi::PulsedGPIOPin, and SWE4211RPi::NetworkManager.

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

◆ waitForShutdown()

void RunnableClass::waitForShutdown ( )
virtual

This method will block waiting for the given thread to terminate before continuing. This should be overridden if any child class has it's own runnable objects encapsulated within it.

This method will block waiting for the given thread to terminate before continuing. If a class that is derived from this class has a child class with a RUnnable object, this method must be overridden to wait for the child method to shutdown.

If thread is joinable

Join the thread and wait for shutdown.

Member Data Documentation

◆ executingThread

pthread_t SWE4211RPi::RunnableClass::executingThread = 0
protected

This attribute is the executing thread. It is set when the thread is started and then is cached afterwards.

◆ keepGoing

bool SWE4211RPi::RunnableClass::keepGoing = true
protected

This variable will determine whether or not the given thread is to continue executing. If this goes to false, then the thread is to shutdown in an appropriate manner.

◆ myName

std::string SWE4211RPi::RunnableClass::myName
protected

This is the name of the thread. It is shown as a string so that it can easily be viewed in human-readable format.

◆ myOSThreadID

pid_t SWE4211RPi::RunnableClass::myOSThreadID = 0
protected

This is the thread id (tid) for this task.

◆ myThread

std::thread* SWE4211RPi::RunnableClass::myThread = NULL
protected

This is the instance of the thread that is to be executed by this class. At instantiation it is NULL. It will be instantiated when the start method of the class is invoked.

◆ priority

int SWE4211RPi::RunnableClass::priority = -1
protected

This is the priority of the given thread. A value of -1 indicates no change in the priority and to use the default setup. For a runnable class, this must be set before the class starts. For other derived classes, it may be changeable at run time.

◆ runCompleted

bool SWE4211RPi::RunnableClass::runCompleted = false
protected

This variable will determine if the current Runnable class has completed execution and the run method has returned.

◆ runningThreads

std::list< RunnableClass * > RunnableClass::runningThreads
staticprotected

This is a list of all of the running threads which have been started by this set of libraries.

◆ runStarted

bool SWE4211RPi::RunnableClass::runStarted = false
protected

This variable will determine whether or not the current task has been started or not.


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