SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
SoDa::Thread Class Referenceabstract

The Thread baseclass for all SoDa thread objects. More...

#include <SoDaThread.hxx>

Inheritance diagram for SoDa::Thread:
SoDa::Base SoDa::Debug CommandMonitor IFServer SimpleAccessory SoDa::AudioQt SoDa::BaseBandRX SoDa::BaseBandTX SoDa::CWTX SoDa::IFRecorder SoDa::RadioControl SoDa::RadioRX SoDa::RadioTX SoDa::UI

Public Member Functions

void registerThread (SoDa::ThreadPtr me)
virtual void subscribeToMailBoxes (const std::vector< MailBoxBasePtr > &mailboxes)=0
 the creator of this thread may offer one or more mailboxes to this object.
void operator() ()
void start ()
 Execute the thread's run loop.
void join ()
 more properly "Wait for this thread to exit its run loop".
virtual void run ()
 Each thread object must define its "run" loop.
void execCommand (CommandPtr cmd)
 Execute (dispatch) a message removed from the command stream to one of the basic Command handler functions.
virtual void execGetCommand (CommandPtr cmd)
 optional method to handle "GET" commands – commands that request a response
virtual void execSetCommand (CommandPtr cmd)
 optional method to handle "SET" commands – commands that set internal state in the object.
virtual void execRepCommand (CommandPtr cmd)
 optional method that reports status or the result of some action.
virtual void shutDown ()
 optional method that performs cleanup – may not delete.
void sleep_ms (unsigned int milliseconds)
void sleep_us (unsigned int microseconds)
uint32_t getID ()
 Get the process/thread ID for this thread – helps with figuring out who caused a segfault.
Public Member Functions inherited from SoDa::Base
 Base (const std::string &oname)
 The constructor – pass a name for the object.
void registerSelf (BasePtr ptr)
std::string & getObjName ()
 get the name of this object
BasePtr findSoDaObject (const std::string &oname)
 find a SoDa Object by name.
double getTime ()
 Get a time stamp in nS resolution that monotonically increases and that is very inexpensive (typically < 100nS).
BasePtr getSelfPtr ()
 get a pointer to myself.
Public Member Functions inherited from SoDa::Debug
 Debug (std::string _unit_name=std::string("UNKNOWN"))
 Debug (const char *_unit_name_cstr)
 Debug (unsigned int _debug_level, std::string _unit_name=std::string("UNKNOWN"))
 Debug (unsigned int _debug_level, const char *_unit_name_cstr)
void debugMsg (const std::string &msg, unsigned int threshold=1)
void debugMsg (const SoDa::Format &fmt, unsigned int threshold=1)
void debugMsg (const char *msg, unsigned int threshold=1)
void setDebugLevel (unsigned int v)
unsigned int getDebugLevel ()

Protected Member Functions

 Thread (const std::string &oname, const std::string &version=std::string("12.2.0"))
 make the thread object.
Protected Member Functions inherited from SoDa::Debug
std::string curDateTime ()

Protected Attributes

std::weak_ptr< Threadself
 A pointer to ourself.
Protected Attributes inherited from SoDa::Debug
std::string unit_name
 the name of the unit reporting status
unsigned int debug_level
 the debug level (threshold) for messages

Private Member Functions

void outerRun ()
 the run method that is called by the thread handler.
void hookSigSeg ()

Static Private Member Functions

static void sigsegHandler (int sig)

Private Attributes

std::unique_ptr< std::thread > thread_ptr
 This is the actual thread object –.
std::string version

Additional Inherited Members

Static Public Member Functions inherited from SoDa::Debug
static void setDefaultLevel (unsigned int v)
static unsigned int getDefaultLevel ()
static void setGlobalLevel (unsigned int v)
static unsigned int getGlobalLevel ()
Static Public Attributes inherited from SoDa::Debug
static std::mutex debug_msg_mutex
Static Protected Attributes inherited from SoDa::Debug
static unsigned int default_debug_level
static unsigned int global_debug_level

Detailed Description

The Thread baseclass for all SoDa thread objects.

The SoDaThread baseclass simplifies interaction with threads. Since SoDa thread objects aren't created and destroyed very often, we don't need many bells and whistles here. Just the ability to start a thread a join a thread.

All threads, however, must declare a "run" function, and handlers for three types of SoDa::Command objects (GET, SET, and REPort)

Definition at line 79 of file SoDaThread.hxx.

Constructor & Destructor Documentation

◆ Thread()

SoDa::Thread::Thread ( const std::string & oname,
const std::string & version = std::string("12.2.0") )
protected

make the thread object.

Register it by name and store a version string, so we can test it against the current version of the SoDaServer.

Parameters
onameThe name of the thread.
versiona string of the form "M.m.p" where M is the major version, m is minor, and p is patch.

Invoking this thread should always leave the version parameter as the default. This is a hack to get the actual version information from the included file (used for the build) rather than from the shared library.

This constructor is only called by derived types.

References version.

Member Function Documentation

◆ execCommand()

void SoDa::Thread::execCommand ( CommandPtr cmd)

Execute (dispatch) a message removed from the command stream to one of the basic Command handler functions.

This sequence appears in so many of the instances of Thread that it was factored out.

Parameters
cmdthe command message to be handled

◆ execGetCommand()

virtual void SoDa::Thread::execGetCommand ( CommandPtr cmd)
inlinevirtual

optional method to handle "GET" commands – commands that request a response

Reimplemented in CommandMonitor, SimpleAccessory, SoDa::BaseBandRX, SoDa::BaseBandTX, SoDa::CWTX, SoDa::IFRecorder, SoDa::RadioControl, SoDa::RadioRX, SoDa::RadioTX, and SoDa::UI.

Definition at line 155 of file SoDaThread.hxx.

◆ execRepCommand()

virtual void SoDa::Thread::execRepCommand ( CommandPtr cmd)
inlinevirtual

optional method that reports status or the result of some action.

Reimplemented in CommandMonitor, SimpleAccessory, SoDa::BaseBandRX, SoDa::BaseBandTX, SoDa::CWTX, SoDa::IFRecorder, SoDa::RadioControl, SoDa::RadioRX, SoDa::RadioTX, and SoDa::UI.

Definition at line 165 of file SoDaThread.hxx.

◆ execSetCommand()

virtual void SoDa::Thread::execSetCommand ( CommandPtr cmd)
inlinevirtual

optional method to handle "SET" commands – commands that set internal state in the object.

Reimplemented in CommandMonitor, SimpleAccessory, SoDa::BaseBandRX, SoDa::BaseBandTX, SoDa::CWTX, SoDa::IFRecorder, SoDa::RadioControl, SoDa::RadioRX, SoDa::RadioTX, and SoDa::UI.

Definition at line 160 of file SoDaThread.hxx.

◆ getID()

uint32_t SoDa::Thread::getID ( )

Get the process/thread ID for this thread – helps with figuring out who caused a segfault.

Returns
the process ID reported by sysgettid;

◆ hookSigSeg()

void SoDa::Thread::hookSigSeg ( )
private

◆ join()

void SoDa::Thread::join ( )
inline

more properly "Wait for this thread to exit its run loop".

returns after the thread has received a STOP message.

Definition at line 128 of file SoDaThread.hxx.

References thread_ptr.

◆ operator()()

void SoDa::Thread::operator() ( )
inline

Definition at line 112 of file SoDaThread.hxx.

References outerRun().

◆ outerRun()

void SoDa::Thread::outerRun ( )
private

the run method that is called by the thread handler.

This method wraps the thread objects run loop in an exception handler so that we can do something useful with it.

We call the subclass's "run" method inside a wrapper that can give us some limited information about what happened.

Referenced by operator()(), and start().

◆ registerThread()

void SoDa::Thread::registerThread ( SoDa::ThreadPtr me)

◆ run()

virtual void SoDa::Thread::run ( )
inlinevirtual

Each thread object must define its "run" loop.

This loop exits only when the thread has received a STOP command on one of its command mailboxes.

Reimplemented in CommandMonitor, IFServer, SimpleAccessory, SoDa::AudioQt, SoDa::BaseBandRX, SoDa::BaseBandTX, SoDa::CWTX, SoDa::IFRecorder, SoDa::RadioControl, SoDa::RadioRX, SoDa::RadioTX, and SoDa::UI.

Definition at line 137 of file SoDaThread.hxx.

References SoDa::Base::getObjName().

◆ shutDown()

virtual void SoDa::Thread::shutDown ( )
inlinevirtual

optional method that performs cleanup – may not delete.

Reimplemented in CommandMonitor, IFServer, and SimpleAccessory.

Definition at line 170 of file SoDaThread.hxx.

◆ sigsegHandler()

void SoDa::Thread::sigsegHandler ( int sig)
staticprivate

◆ sleep_ms()

void SoDa::Thread::sleep_ms ( unsigned int milliseconds)
inline

Definition at line 174 of file SoDaThread.hxx.

◆ sleep_us()

void SoDa::Thread::sleep_us ( unsigned int microseconds)
inline

Definition at line 177 of file SoDaThread.hxx.

◆ start()

void SoDa::Thread::start ( )
inline

Execute the thread's run loop.

Definition at line 120 of file SoDaThread.hxx.

References outerRun(), and thread_ptr.

◆ subscribeToMailBoxes()

virtual void SoDa::Thread::subscribeToMailBoxes ( const std::vector< MailBoxBasePtr > & mailboxes)
pure virtual

the creator of this thread may offer one or more mailboxes to this object.

The thread may "subscribe" to the mailboxes as it chooses.

Parameters
mailboxesA list of all mailboxes that we know about.

Implemented in SoDa::AudioQt, SoDa::BaseBandRX, SoDa::BaseBandTX, SoDa::CWTX, SoDa::IFRecorder, SoDa::RadioControl, SoDa::RadioRX, SoDa::RadioTX, and SoDa::UI.

Member Data Documentation

◆ self

std::weak_ptr<Thread> SoDa::Thread::self
protected

A pointer to ourself.

Definition at line 193 of file SoDaThread.hxx.

◆ thread_ptr

std::unique_ptr<std::thread> SoDa::Thread::thread_ptr
private

This is the actual thread object –.

Definition at line 199 of file SoDaThread.hxx.

Referenced by join(), and start().

◆ version

std::string SoDa::Thread::version
private

Definition at line 216 of file SoDaThread.hxx.

Referenced by Thread().


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