Goby3 3.4.0
2026.04.13
Loading...
Searching...
No Matches
simple_thread.h
Go to the documentation of this file.
1// Copyright 2022-2026:
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{
44template <typename Config, typename ImplementationTag = void>
46 : public Thread<Config, InterVehicleForwarder<
47 InterProcessForwarder<InterThreadTransporter, ImplementationTag>>>,
48 public coroner::Thread<SimpleThread<Config, ImplementationTag>>
49{
51 Config,
53
54 friend class coroner::Thread<SimpleThread<Config, ImplementationTag>>;
55
56 public:
62 SimpleThread(const Config& cfg, double loop_freq_hertz = 0, int index = -1)
63 : SimpleThread(cfg, loop_freq_hertz * boost::units::si::hertz, index)
64 {
65 }
66
72 SimpleThread(const Config& cfg, boost::units::quantity<boost::units::si::frequency> loop_freq,
73 int index = -1)
74 : SimpleThreadBase(cfg, loop_freq, index)
75 {
76 interthread_.reset(new InterThreadTransporter);
77 interprocess_.reset(
79 intervehicle_.reset(
82
83 this->set_transporter(intervehicle_.get());
84
85 this->subscribe_coroner();
86 }
87
89 InterVehicleForwarder<InterProcessForwarder<InterThreadTransporter, ImplementationTag>>&
91 {
92 return this->transporter();
93 }
94
100
103
104 private:
105 std::unique_ptr<InterThreadTransporter> interthread_;
106 std::unique_ptr<InterProcessForwarder<InterThreadTransporter, ImplementationTag>> interprocess_;
107 std::unique_ptr<
109 intervehicle_;
110};
111
112} // namespace middleware
113} // namespace goby
114
116
117namespace goby
118{
119namespace middleware
120{
121
123template <typename Config>
124class SimpleThread<Config, void>
125 : public SimpleThread<Config, zeromq::detail::InterProcessTag>
126{
127 public:
128 using Base = SimpleThread<Config, zeromq::detail::InterProcessTag>;
129
130 [[deprecated("Use goby::zeromq::SimpleThread or goby::udpm::SimpleThread instead of "
131 "goby::middleware::SimpleThread")]]
132 SimpleThread(const Config& cfg, double loop_freq_hertz = 0, int index = -1)
133 : Base(cfg, loop_freq_hertz, index)
134 {
135 }
136
137 [[deprecated("Use goby::zeromq::SimpleThread or goby::udpm::SimpleThread instead of "
138 "goby::middleware::SimpleThread")]]
139 SimpleThread(const Config& cfg, boost::units::quantity<boost::units::si::frequency> loop_freq,
140 int index = -1)
141 : Base(cfg, loop_freq, index)
142 {
143 }
144};
145
146} // namespace middleware
147} // namespace goby
148
149#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 ] ]...
InterVehicleForwarder< InterProcessForwarder< InterThreadTransporter, ImplementationTag > > & intervehicle()
Access the transporter on the intervehicle layer (which wraps interprocess and 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)
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...
InterProcessForwarder< InterThreadTransporter, ImplementationTag > & interprocess()
Access the transporter on the interprocess layer (which wraps interthread)
Represents a thread of execution within the Goby middleware, interleaving periodic events (loop()) wi...
Definition thread.h:61
void set_transporter(TransporterType *transporter)
Definition thread.h:202
TransporterType & transporter() const
Definition thread.h:213
const Config & cfg() const
Definition thread.h:215
middleware::SimpleThread< Config, detail::InterProcessTag > SimpleThread
UDPM-backed SimpleThread. Derives from middleware::SimpleThread using InterProcessTag.
The global namespace for the Goby project.