diff options
Diffstat (limited to 'examples/routingmanagerd/routingmanagerd.cpp')
-rw-r--r-- | examples/routingmanagerd/routingmanagerd.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/examples/routingmanagerd/routingmanagerd.cpp b/examples/routingmanagerd/routingmanagerd.cpp index ff0a280..b2118f6 100644 --- a/examples/routingmanagerd/routingmanagerd.cpp +++ b/examples/routingmanagerd/routingmanagerd.cpp @@ -23,6 +23,7 @@ static std::shared_ptr<vsomeip::application> its_application; #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING +static vsomeip::routing_state_e routing_state = vsomeip::routing_state_e::RS_RUNNING; static bool stop_application = false; static bool stop_sighandler = false; static std::condition_variable_any sighandler_condition; @@ -35,9 +36,24 @@ static std::recursive_mutex sighandler_mutex; */ void routingmanagerd_stop(int _signal) { // Do not log messages in signal handler as this can cause deadlock in boost logger - if (_signal == SIGINT || _signal == SIGTERM) { + switch (_signal) { + case SIGINT: + case SIGTERM: stop_application = true; - } + break; + + case SIGUSR1: + routing_state = vsomeip::routing_state_e::RS_SUSPENDED; + break; + + case SIGUSR2: + routing_state = vsomeip::routing_state_e::RS_RESUMED; + break; + + default: + ; + }; + std::unique_lock<std::recursive_mutex> its_lock(sighandler_mutex); sighandler_condition.notify_one(); } @@ -68,6 +84,8 @@ int routingmanagerd_process(bool _is_quiet) { // Unblock signals for this thread only sigset_t handler_mask; sigemptyset(&handler_mask); + sigaddset(&handler_mask, SIGUSR1); + sigaddset(&handler_mask, SIGUSR2); sigaddset(&handler_mask, SIGTERM); sigaddset(&handler_mask, SIGINT); sigaddset(&handler_mask, SIGSEGV); @@ -77,6 +95,8 @@ int routingmanagerd_process(bool _is_quiet) { // Handle the following signals signal(SIGINT, routingmanagerd_stop); signal(SIGTERM, routingmanagerd_stop); + signal(SIGUSR1, routingmanagerd_stop); + signal(SIGUSR2, routingmanagerd_stop); while (!stop_sighandler) { std::unique_lock<std::recursive_mutex> its_lock(sighandler_mutex); @@ -84,6 +104,11 @@ int routingmanagerd_process(bool _is_quiet) { if (stop_application) { its_application->stop(); return; + } else if (routing_state == vsomeip::routing_state_e::RS_RESUMED || + routing_state == vsomeip::routing_state_e::RS_SUSPENDED){ + VSOMEIP_INFO << "Received signal for setting routing_state to: 0x" + << std::hex << static_cast<int>(routing_state ); + its_application->set_routing_state(routing_state); } } }); |