Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
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
34namespace goby
35{
36namespace middleware
37{
42template <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
88
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
Implements the forwarder concept for the interprocess layer.
A transporter for the interthread layer.
Definition interthread.h:59
Implements the forwarder concept for the intervehicle layer.
Implements Thread for a three layer middleware setup ([ intervehicle [ interprocess [ interthread ] ]...
InterProcessForwarder< InterThreadTransporter > & interprocess()
Access the transporter on the interprocess layer (which wraps interthread)
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.
InterThreadTransporter & interthread()
Access the transporter on the interthread layer (this is the innermost transporter)
InterVehicleForwarder< InterProcessForwarder< InterThreadTransporter > > & intervehicle()
Access the transporter on the intervehicle layer (which wraps interprocess and interthread)
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...
Represents a thread of execution within the Goby middleware, interleaving periodic events (loop()) wi...
Definition thread.h:61
void set_transporter(InterVehicleForwarder< InterProcessForwarder< InterThreadTransporter > > *transporter)
Definition thread.h:186
InterVehicleForwarder< InterProcessForwarder< InterThreadTransporter > > & transporter() const
Definition thread.h:199
The global namespace for the Goby project.