Goby3  3.1.4
2024.02.22
coroner.h
Go to the documentation of this file.
1 // Copyright 2017-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_CORONER_CORONER_H
25 #define GOBY_MIDDLEWARE_CORONER_CORONER_H
26 
28 
32 
33 namespace goby
34 {
35 namespace middleware
36 {
37 
38 namespace coroner
39 {
40 
41 template <typename Derived> class Thread
42 {
43  protected:
45  {
46  static_cast<Derived*>(this)->interthread().template subscribe<groups::health_request>(
47  [this](const protobuf::HealthRequest& request)
48  {
49  std::shared_ptr<protobuf::ThreadHealth> response(new protobuf::ThreadHealth);
50  static_cast<Derived*>(this)->thread_health(*response);
51  static_cast<Derived*>(this)
52  ->interthread()
53  .template publish<groups::health_response>(response);
54  });
55  }
56 };
57 
58 template <typename Derived> class Application
59 {
60  protected:
62  {
63  static_cast<Derived*>(this)->interprocess().template subscribe<groups::health_request>(
64  [this](const protobuf::HealthRequest& request)
65  {
66  auto health_response = std::make_shared<protobuf::ProcessHealth>();
67 
68  health_response->set_name(static_cast<Derived*>(this)->app_name());
69  health_response->set_pid(getpid());
70 
71  static_cast<Derived*>(this)->thread_health(*health_response->mutable_main());
72  static_cast<Derived*>(this)
73  ->interprocess()
74  .template publish<groups::health_response>(health_response);
75  });
76  }
77 };
78 
79 template <typename Derived> class ApplicationInterThread
80 {
81  protected:
83  {
84  static_cast<Derived*>(this)->interthread().template subscribe<groups::health_request>(
85  [this](const protobuf::HealthRequest& request)
86  {
87  auto health_response = std::make_shared<protobuf::ProcessHealth>();
88 
89  health_response->set_name(static_cast<Derived*>(this)->app_name());
90  health_response->set_pid(getpid());
91 
93 
94  static_cast<Derived*>(this)->thread_health(*health_response->mutable_main());
95  static_cast<Derived*>(this)
96  ->interthread()
97  .template publish<groups::health_response>(health_response);
98  });
99  }
100  virtual void preseed_hook(std::shared_ptr<protobuf::ProcessHealth>& ph) {}
101 };
102 
103 } // namespace coroner
104 } // namespace middleware
105 } // namespace goby
106 
107 #endif
goby::middleware::coroner::Thread::subscribe_coroner
void subscribe_coroner()
Definition: coroner.h:44
goby::middleware::coroner::Application
Definition: coroner.h:58
goby::middleware::coroner::ApplicationInterThread::preseed_hook
virtual void preseed_hook(std::shared_ptr< protobuf::ProcessHealth > &ph)
Definition: coroner.h:100
goby::middleware::coroner::Application::subscribe_coroner
void subscribe_coroner()
Definition: coroner.h:61
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::middleware::coroner::Thread
Definition: coroner.h:41
protobuf.h
goby::middleware::protobuf::ThreadHealth
Definition: coroner.pb.h:231
goby::middleware::coroner::ApplicationInterThread
Definition: coroner.h:79
groups.h
goby::middleware::groups::health_response
constexpr goby::middleware::Group health_response
Definition: groups.h:37
interthread.h
goby::middleware::coroner::ApplicationInterThread::subscribe_coroner
void subscribe_coroner()
Definition: coroner.h:82
goby::middleware::protobuf::HealthRequest
Definition: coroner.pb.h:127
coroner.pb.h