Goby3  3.1.5a
2024.05.23
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 
41 namespace goby
42 {
43 namespace middleware
44 {
49 template <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 
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_(
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  {
91  this->configure_geodesy(
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
goby::middleware::SingleThreadApplication::SingleThreadApplication
SingleThreadApplication(double loop_freq_hertz=0)
Construct the application calling loop() at the given frequency (double overload)
Definition: single_thread.h:69
goby::middleware::coroner::Application
Definition: coroner.h:58
goby::middleware::InterVehicleForwarder
Implements the forwarder concept for the intervehicle layer.
Definition: intervehicle.h:576
goby::middleware::coroner::Application::subscribe_coroner
void subscribe_coroner()
Definition: coroner.h:61
goby::middleware::Thread::run_once
void run_once()
Definition: thread.h:275
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::middleware::SingleThreadApplication::health
virtual void health(goby::middleware::protobuf::ThreadHealth &health) override
Called when HealthRequest is made by goby_coroner.
Definition: single_thread.h:105
goby::middleware::Application::app_name
std::string app_name()
Definition: interface.h:128
goby::run
int run(const goby::middleware::ConfiguratorInterface< typename App::ConfigType > &cfgtor)
Run a Goby application using the provided Configurator.
Definition: interface.h:318
goby::middleware::SingleThreadApplication::post_initialize
virtual void post_initialize() override
Assume all required subscriptions are done in the Constructor or in initialize(). If this isn't the c...
Definition: single_thread.h:112
navigation.h
goby::middleware::protobuf::ThreadHealth
Definition: coroner.pb.h:231
detail
detail namespace with internal helper functions
Definition: json.hpp:246
goby::middleware::protobuf::ThreadHealth::set_state
void set_state(::goby::middleware::protobuf::HealthState value)
Definition: coroner.pb.h:962
boost
Definition: udp_driver.h:41
goby::middleware::SingleThreadApplication::SingleThreadApplication
SingleThreadApplication(boost::units::quantity< boost::units::si::frequency > loop_freq)
Construct the application calling loop() at the given frequency (boost::units overload)
Definition: single_thread.h:77
goby::middleware::SingleThreadApplication::~SingleThreadApplication
virtual ~SingleThreadApplication()
Definition: single_thread.h:99
goby::middleware::Thread< Config, InterVehicleForwarder< InterProcessPortal<> > >::set_transporter
void set_transporter(InterVehicleForwarder< InterProcessPortal<> > *transporter)
Definition: thread.h:186
goby::zeromq::InterProcessPortal
InterProcessPortalImplementation< InnerTransporter, middleware::InterProcessPortalBase > InterProcessPortal
Definition: interprocess.h:827
intervehicle.h
goby::middleware::SingleThreadApplication::intervehicle
InterVehicleForwarder< InterProcessPortal<> > & intervehicle()
Definition: single_thread.h:103
goby::middleware::Application::configure_geodesy
void configure_geodesy(goby::util::UTMGeodesy::LatLonPoint datum)
Definition: interface.h:288
goby::middleware::Thread
Represents a thread of execution within the Goby middleware, interleaving periodic events (loop()) wi...
Definition: thread.h:60
goby::middleware::detail::make_interprocess_config
Config make_interprocess_config(Config cfg, std::string app_name)
Definition: interprocess_common.h:33
interprocess_common.h
interprocess.h
goby::middleware::Application::app_cfg
const Config & app_cfg()
Accesses configuration object passed at launch.
Definition: interface.h:114
goby::middleware::groups::datum_update
constexpr goby::middleware::Group datum_update
Definition: groups.h:36
goby::middleware::SingleThreadApplication::interprocess
InterProcessPortal & interprocess()
Definition: single_thread.h:102
interface.h
terminate.h
goby::middleware::terminate::Application< SingleThreadApplication< Config, InterProcessPortal > >::subscribe_terminate
void subscribe_terminate(bool do_quit=true)
Definition: terminate.h:78
goby::middleware::terminate::Application
Definition: terminate.h:75
groups.h
goby::middleware::protobuf::DatumUpdate::datum
const ::goby::middleware::protobuf::LatLonPoint & datum() const
Definition: navigation.pb.h:217
goby::middleware::protobuf::HEALTH__OK
@ HEALTH__OK
Definition: coroner.pb.h:87
goby::middleware::SingleThreadApplication
Implements an Application for a two layer middleware setup ([ intervehicle [ interprocess ] ]) based ...
Definition: single_thread.h:50
goby::middleware::protobuf::DatumUpdate
Definition: navigation.pb.h:76
coroner.h
thread.h
goby::middleware::Application
Base class for Goby applications. Generally you will want to use SingleThreadApplication or MultiThre...
Definition: interface.h:71