Goby3  3.1.4
2024.02.22
simple_thread.h
Go to the documentation of this file.
1 // Copyright 2022-2023:
2 // GobySoft, LLC (2013-)
3 // Community contributors (see AUTHORS file)
4 // File authors:
5 // Toby Schneider <toby@gobysoft.org>
6 //
7 //
8 // This file is part of the Goby Underwater Autonomy Project Libraries
9 // ("The Goby Libraries").
10 //
11 // The Goby Libraries are free software: you can redistribute them and/or modify
12 // them under the terms of the GNU Lesser General Public License as published by
13 // the Free Software Foundation, either version 2.1 of the License, or
14 // (at your option) any later version.
15 //
16 // The Goby Libraries are distributed in the hope that they will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public License
22 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
23 
24 #ifndef GOBY_MIDDLEWARE_APPLICATION_SIMPLE_THREAD_H
25 #define GOBY_MIDDLEWARE_APPLICATION_SIMPLE_THREAD_H
26 
29 
33 
34 namespace goby
35 {
36 namespace middleware
37 {
42 template <typename Config>
44  : public Thread<Config, InterVehicleForwarder<InterProcessForwarder<InterThreadTransporter>>>,
45  public coroner::Thread<SimpleThread<Config>>
46 {
47  using SimpleThreadBase =
49 
50  friend class coroner::Thread<SimpleThread<Config>>;
51 
52  public:
58  SimpleThread(const Config& cfg, double loop_freq_hertz = 0, int index = -1)
59  : SimpleThread(cfg, loop_freq_hertz * boost::units::si::hertz, index)
60  {
61  }
62 
68  SimpleThread(const Config& cfg, boost::units::quantity<boost::units::si::frequency> loop_freq,
69  int index = -1)
70  : SimpleThreadBase(cfg, loop_freq, index)
71  {
72  interthread_.reset(new InterThreadTransporter);
73  interprocess_.reset(new InterProcessForwarder<InterThreadTransporter>(*interthread_));
74  intervehicle_.reset(
76  *interprocess_));
77 
78  this->set_transporter(intervehicle_.get());
79 
80  this->subscribe_coroner();
81  }
82 
85  {
86  return this->transporter();
87  }
88 
91  {
92  return this->transporter().inner();
93  }
94 
97 
98  private:
99  std::unique_ptr<InterThreadTransporter> interthread_;
100  std::unique_ptr<InterProcessForwarder<InterThreadTransporter>> interprocess_;
101  std::unique_ptr<InterVehicleForwarder<InterProcessForwarder<InterThreadTransporter>>>
102  intervehicle_;
103 };
104 } // namespace middleware
105 } // namespace goby
106 
107 #endif
goby::middleware::coroner::Thread< SimpleThread< Config > >::subscribe_coroner
void subscribe_coroner()
Definition: coroner.h:44
goby::middleware::InterVehicleForwarder
Implements the forwarder concept for the intervehicle layer.
Definition: intervehicle.h:576
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::middleware::coroner::Thread
Definition: coroner.h:41
goby::middleware::Thread< Config, InterVehicleForwarder< InterProcessForwarder< InterThreadTransporter > > >::cfg
const Config & cfg() const
Definition: thread.h:201
goby::middleware::Thread< Config, InterVehicleForwarder< InterProcessForwarder< InterThreadTransporter > > >::index
int index() const
Definition: thread.h:145
boost
Definition: udp_driver.h:41
goby::middleware::InterThreadTransporter
A transporter for the interthread layer.
Definition: interthread.h:56
goby::middleware::Thread< Config, InterVehicleForwarder< InterProcessForwarder< InterThreadTransporter > > >::set_transporter
void set_transporter(InterVehicleForwarder< InterProcessForwarder< InterThreadTransporter > > *transporter)
Definition: thread.h:186
goby::middleware::InterProcessForwarder< InterThreadTransporter >
goby::middleware::SimpleThread::interprocess
InterProcessForwarder< InterThreadTransporter > & interprocess()
Access the transporter on the interprocess layer (which wraps interthread)
Definition: simple_thread.h:90
intervehicle.h
goby::middleware::SimpleThread
Implements Thread for a three layer middleware setup ([ intervehicle [ interprocess [ interthread ] ]...
Definition: simple_thread.h:43
interthread.h
goby::middleware::Thread
Represents a thread of execution within the Goby middleware, interleaving periodic events (loop()) wi...
Definition: thread.h:60
interprocess.h
goby::middleware::Thread< Config, InterVehicleForwarder< InterProcessForwarder< InterThreadTransporter > > >::transporter
InterVehicleForwarder< InterProcessForwarder< InterThreadTransporter > > & transporter() const
Definition: thread.h:199
goby::middleware::InnerTransporterInterface::inner
InnerTransporter & inner()
Definition: interface.h:63
goby::middleware::SimpleThread::SimpleThread
SimpleThread(const Config &cfg, double loop_freq_hertz=0, int index=-1)
Construct a thread with a given configuration, optionally a loop frequency and/or index.
Definition: simple_thread.h:58
goby::middleware::SimpleThread::interthread
InterThreadTransporter & interthread()
Access the transporter on the interthread layer (this is the innermost transporter)
Definition: simple_thread.h:96
goby::middleware::SimpleThread::SimpleThread
SimpleThread(const Config &cfg, boost::units::quantity< boost::units::si::frequency > loop_freq, int index=-1)
Construct a thread with a given configuration, a loop frequency (using boost::units) and optionally a...
Definition: simple_thread.h:68
coroner.h
goby::middleware::SimpleThread::intervehicle
InterVehicleForwarder< InterProcessForwarder< InterThreadTransporter > > & intervehicle()
Access the transporter on the intervehicle layer (which wraps interprocess and interthread)
Definition: simple_thread.h:84
thread.h
goby::middleware::InnerTransporterInterface::innermost
auto innermost()
Definition: interface.h:67