Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
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
33namespace goby
34{
35namespace middleware
36{
37
38namespace coroner
39{
40
41template <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
58template <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
79template <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
92 preseed_hook(health_response);
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
virtual void preseed_hook(std::shared_ptr< protobuf::ProcessHealth > &ph)
Definition coroner.h:100
The global namespace for the Goby project.