24 #ifndef GOBY_MIDDLEWARE_TERMINATE_TERMINATE_H
25 #define GOBY_MIDDLEWARE_TERMINATE_TERMINATE_H
27 #include <sys/types.h>
47 inline std::pair<bool, protobuf::TerminateResponse>
48 check_terminate(
const protobuf::TerminateRequest& request,
const std::string& app_name)
50 protobuf::TerminateResponse resp;
51 resp.set_target_name(app_name);
52 unsigned pid = getpid();
53 resp.set_target_pid(pid);
57 if (request.has_target_name() && request.target_name() == app_name)
61 <<
"Received request matching our app name to cleanly quit() from goby_terminate"
65 else if (request.has_target_pid() && request.target_pid() == pid)
68 goby::glog <<
"Received request matching our PID to cleanly quit() from goby_terminate"
72 return std::make_pair(match, resp);
81 static_cast<Derived*
>(
this)
84 goby::middleware::protobuf::TerminateRequest>(
85 [
this, do_quit](
const goby::middleware::protobuf::TerminateRequest& request)
88 goby::middleware::protobuf::TerminateResponse resp;
90 request,
static_cast<Derived*
>(
this)->app_cfg().app().name());
93 static_cast<Derived*
>(
this)
95 .template publish<goby::middleware::groups::terminate_response>(resp);
97 static_cast<Derived*
>(
this)->quit();
void subscribe_terminate(bool do_quit=true)
constexpr goby::middleware::Group terminate_request
std::pair< bool, protobuf::TerminateResponse > check_terminate(const protobuf::TerminateRequest &request, const std::string &app_name)
Checks if the terminate request is for this application, either by target_name or PID.
The global namespace for the Goby project.
util::FlexOstream glog
Access the Goby logger through this object.