Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
single_thread.h
Go to the documentation of this file.
1// Copyright 2016-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_SINGLE_THREAD_H
25#define GOBY_MIDDLEWARE_APPLICATION_SINGLE_THREAD_H
26
27#include <boost/units/systems/si.hpp>
28
32
37
40
41namespace goby
42{
43namespace middleware
44{
49template <class Config, template <class = NullTransporter> class InterProcessPortal>
51 : public goby::middleware::Application<Config>,
52 public Thread<Config, InterVehicleForwarder<InterProcessPortal<>>>,
53 public coroner::Application<SingleThreadApplication<Config, InterProcessPortal>>,
54 public terminate::Application<SingleThreadApplication<Config, InterProcessPortal>>
55{
56 private:
58
59 InterProcessPortal<> interprocess_;
61
62 friend class coroner::Application<SingleThreadApplication<Config, InterProcessPortal>>;
63 friend class terminate::Application<SingleThreadApplication<Config, InterProcessPortal>>;
64
65 public:
69 SingleThreadApplication(double loop_freq_hertz = 0)
70 : SingleThreadApplication(loop_freq_hertz * boost::units::si::hertz)
71 {
72 }
73
77 SingleThreadApplication(boost::units::quantity<boost::units::si::frequency> loop_freq)
78 : MainThread(this->app_cfg(), loop_freq),
79 interprocess_(
80 detail::make_interprocess_config(this->app_cfg().interprocess(), this->app_name())),
81 intervehicle_(interprocess_)
82 {
83 this->set_transporter(&intervehicle_);
84
85 this->subscribe_terminate();
86 this->subscribe_coroner();
87
88 this->interprocess().template subscribe<goby::middleware::groups::datum_update>(
89 [this](const protobuf::DatumUpdate& datum_update)
90 {
92 {datum_update.datum().lat_with_units(), datum_update.datum().lon_with_units()});
93 });
94
95 this->interprocess().template publish<goby::middleware::groups::configuration>(
96 this->app_cfg());
97 }
98
100
101 protected:
102 InterProcessPortal<>& interprocess() { return interprocess_; }
104
106 {
107 health.set_name(this->app_name());
109 }
110
112 virtual void post_initialize() override { interprocess().ready(); };
113
114 private:
115 void run() override { MainThread::run_once(); }
116};
117
118} // namespace middleware
119} // namespace goby
120
121#endif
Base class for Goby applications. Generally you will want to use SingleThreadApplication or MultiThre...
Definition interface.h:72
void configure_geodesy(goby::util::UTMGeodesy::LatLonPoint datum)
Definition interface.h:288
const Config & app_cfg()
Accesses configuration object passed at launch.
Definition interface.h:114
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:186
const ::goby::middleware::protobuf::LatLonPoint & datum() const
void set_state(::goby::middleware::protobuf::HealthState value)
void subscribe_terminate(bool do_quit=true)
Definition terminate.h:78
detail namespace with internal helper functions
Definition json.hpp:247
InterProcessPortalImplementation< InnerTransporter, middleware::InterProcessPortalBase > InterProcessPortal
The global namespace for the Goby project.