Goby3 3.7.0
2026.11.12
Loading...
Searching...
No Matches
single_thread.h
Go to the documentation of this file.
1// Copyright 2016-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_SINGLE_THREAD_H
25#define GOBY_MIDDLEWARE_APPLICATION_SINGLE_THREAD_H
26
27#include <boost/units/systems/si.hpp>
28
32
37
41
42namespace goby
43{
44namespace middleware
45{
50template <class Config, template <class = NullTransporter> class InterProcessPortal>
52 : public goby::middleware::Application<Config>,
53 public Thread<Config, InterVehicleForwarder<InterProcessPortal<>>>,
54 public coroner::Application<SingleThreadApplication<Config, InterProcessPortal>>,
55 public terminate::Application<SingleThreadApplication<Config, InterProcessPortal>>
56{
57 private:
59
60 InterProcessPortal<> interprocess_;
62
63 friend class coroner::Application<SingleThreadApplication<Config, InterProcessPortal>>;
64 friend class terminate::Application<SingleThreadApplication<Config, InterProcessPortal>>;
65 template <typename App> friend class goby::middleware::julia::ApplicationWrapper;
66 template <typename App> friend class goby::middleware::python::ApplicationWrapper;
67
68 public:
72 SingleThreadApplication(double loop_freq_hertz = 0)
73 : SingleThreadApplication(loop_freq_hertz * boost::units::si::hertz)
74 {
75 }
76
80 SingleThreadApplication(boost::units::quantity<boost::units::si::frequency> loop_freq)
81 : MainThread(this->app_cfg(), this->choose_loop_freq(loop_freq)),
82 interprocess_(
83 detail::make_interprocess_config(this->app_cfg().interprocess(), this->app_name())),
84 intervehicle_(interprocess_)
85 {
86 this->set_transporter(&intervehicle_);
87
88 this->subscribe_terminate();
89 this->subscribe_coroner();
90
91 this->interprocess().template subscribe<goby::middleware::groups::datum_update>(
92 [this](const protobuf::DatumUpdate& datum_update)
93 {
95 {datum_update.datum().lat_with_units(), datum_update.datum().lon_with_units()});
96 });
97
98 this->interprocess().template publish<goby::middleware::groups::configuration>(
99 this->app_cfg());
100 }
101
103
104 protected:
105 InterProcessPortal<>& interprocess() { return interprocess_; }
107
109 {
110 health.set_name(this->app_name());
112 }
113
115 virtual void post_initialize() override { interprocess().ready(); };
116
117 private:
118 void run() override { MainThread::run_once(); }
119};
120
125template <class Config, typename ImplementationTag>
129
130} // namespace middleware
131} // namespace goby
132
133#endif
Base class for Goby applications. Generally you will want to use SingleThreadApplication or MultiThre...
Definition interface.h:85
void configure_geodesy(goby::util::UTMGeodesy::LatLonPoint datum)
Definition interface.h:362
boost::units::quantity< boost::units::si::frequency > choose_loop_freq(boost::units::quantity< boost::units::si::frequency > compiled_loop_freq)
Definition interface.h:146
const Config & app_cfg()
Accesses configuration object passed at launch.
Definition interface.h:127
Implements the forwarder concept for the intervehicle layer.
Implements an Application for a two layer middleware setup ([ intervehicle [ interprocess ] ]) based ...
SingleThreadApplication(boost::units::quantity< boost::units::si::frequency > loop_freq)
Construct the application calling loop() at the given frequency (boost::units overload)
virtual void post_initialize() override
Assume all required subscriptions are done in the Constructor or in initialize(). If this isn't the c...
virtual void health(goby::middleware::protobuf::ThreadHealth &health) override
Called when HealthRequest is made by goby_coroner.
InterVehicleForwarder< InterProcessPortal<> > & intervehicle()
SingleThreadApplication(double loop_freq_hertz=0)
Construct the application calling loop() at the given frequency (double overload)
Represents a thread of execution within the Goby middleware, interleaving periodic events (loop()) wi...
Definition thread.h:61
void set_transporter(InterVehicleForwarder< InterProcessPortal<> > *transporter)
Definition thread.h:202
const ::goby::middleware::protobuf::LatLonPoint & datum() const
void set_state(::goby::middleware::protobuf::HealthState value)
The class exposed to Python; user application classes subclass this.
void subscribe_terminate(bool do_quit=true)
Definition terminate.h:78
detail namespace with internal helper functions
Definition json.hpp:263
InterProcessPortalImplementation< InnerTransporter, middleware::InterProcessPortalBase, detail::InterProcessTag > InterProcessPortal
The global namespace for the Goby project.
Maps an ImplementationTag to the portal that implements it, so that generic code can be written again...