Goby3 3.5.1
2026.06.04
Loading...
Searching...
No Matches
goby::middleware::TimerThread< i > Class Template Reference

Thread that simply publishes an empty message on its loop interval to TimerThread::group. More...

#include <goby/middleware/application/multi_thread.h>

Inheritance diagram for goby::middleware::TimerThread< i >:
goby::middleware::Thread< boost::units::quantity< boost::units::si::frequency >, InterThreadTransporter > goby::middleware::coroner::Thread< TimerThread< i > >

Public Member Functions

 TimerThread (const boost::units::quantity< boost::units::si::frequency > &freq)
Public Member Functions inherited from goby::middleware::Thread< boost::units::quantity< boost::units::si::frequency >, InterThreadTransporter >
 Thread (const boost::units::quantity< boost::units::si::frequency > &cfg, InterThreadTransporter *transporter, int index)
 Construct a thread with a given configuration, underlying transporter, and index (for multiple instantiations), but without any loop() frequency.
 Thread (const boost::units::quantity< boost::units::si::frequency > &cfg, InterThreadTransporter *transporter, double loop_freq_hertz=0, int index=-1)
 Construct a thread with all possible metadata (using double to specify frequency in Hertz).
 Thread (const boost::units::quantity< boost::units::si::frequency > &cfg, InterThreadTransporter *transporter, boost::units::quantity< boost::units::si::frequency > loop_freq, int index=-1)
 Construct a thread with all possible metadata (using boost::units to specify frequency).
virtual ~Thread ()
void run (std::atomic< bool > &alive)
 Run the thread until the boolean reference passed is set false. This call blocks, and should be run in a std::thread by the caller.
int index () const
std::type_index type_index ()
void set_type_index (std::type_index type_i)
std::string name ()
void set_name (const std::string &name)
int uid ()
void set_uid (int uid)
double loop_frequency_hertz () const
decltype(loop_frequency_) loop_frequency () const
void set_loop_frequency_hertz (double loop_freq_hertz)
void set_loop_frequency (boost::units::quantity< boost::units::si::frequency > loop_freq)

Static Public Attributes

static constexpr goby::middleware::Group expire_group
Static Public Attributes inherited from goby::middleware::Thread< boost::units::quantity< boost::units::si::frequency >, InterThreadTransporter >
static constexpr goby::middleware::Group shutdown_group_
static constexpr goby::middleware::Group joinable_group_

Friends

class coroner::Thread< TimerThread< i > >

Additional Inherited Members

Public Types inherited from goby::middleware::Thread< boost::units::quantity< boost::units::si::frequency >, InterThreadTransporter >
using Transporter
Protected Member Functions inherited from goby::middleware::Thread< boost::units::quantity< boost::units::si::frequency >, InterThreadTransporter >
 Thread (const boost::units::quantity< boost::units::si::frequency > &cfg, boost::units::quantity< boost::units::si::frequency > loop_freq, int index=-1)
void set_transporter (InterThreadTransporter *transporter)
double loop_max_frequency () const
void run_once ()
InterThreadTransportertransporter () const
const boost::units::quantity< boost::units::si::frequency > & cfg () const
virtual void initialize ()
virtual void finalize ()
void thread_health (goby::middleware::protobuf::ThreadHealth &health)
virtual void health (goby::middleware::protobuf::ThreadHealth &health)
 Called when HealthRequest is made by goby_coroner.
void thread_quit ()
bool alive ()
Protected Member Functions inherited from goby::middleware::coroner::Thread< TimerThread< i > >
void subscribe_coroner ()

Detailed Description

template<int i>
class goby::middleware::TimerThread< i >

Thread that simply publishes an empty message on its loop interval to TimerThread::group.

This can be launched to provide a simple timer by subscribing to TimerThread::group.

For example, to create timer that expires every two seconds:

launch_thread<goby::middleware::TimerThread<0>>(0.5*boost::units::si::hertz);
interthread().subscribe_empty<goby::middleware::TimerThread<0>::expire_group>([]() { std::cout << "Timer expired." << std::endl; });
static constexpr goby::middleware::Group expire_group

Definition at line 64 of file multi_thread.h.

Constructor & Destructor Documentation

◆ TimerThread()

template<int i>
goby::middleware::TimerThread< i >::TimerThread ( const boost::units::quantity< boost::units::si::frequency > & freq)
inline

Definition at line 77 of file multi_thread.h.

◆ coroner::Thread< TimerThread< i > >

template<int i>
friend class coroner::Thread< TimerThread< i > >
friend

Definition at line 92 of file multi_thread.h.

Member Data Documentation

◆ expire_group

template<int i>
goby::middleware::Group goby::middleware::TimerThread< i >::expire_group
staticconstexpr
Initial value:
{"goby::middleware::TimerThread::timer",
i}

Definition at line 74 of file multi_thread.h.


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