1+ #include < signal.h>
12#include < viam/sdk/module/signal_manager.hpp>
2- #include < signal.h>
3- #include < windows.h> // this file assumes WIN32
3+ #include < windows.h> // this file assumes WIN32
44
55#include < stdexcept>
66
77namespace viam {
88namespace sdk {
99
10- struct SignalManager ::Impl { // Windows implementation details of SignalManager
11- static BOOL WINAPI console_handler_routine_ (DWORD dwCtrlType){
10+ struct SignalManager ::Impl { // Windows implementation details of SignalManager
11+ static BOOL WINAPI console_handler_routine_ (DWORD dwCtrlType) {
1212 if (dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_BREAK_EVENT) {
13- instance_->handle_signal_ (SIGINT);
13+ instance_->pImpl -> handle_signal_ (SIGINT);
1414 return TRUE ;
1515 } else if (dwCtrlType == CTRL_CLOSE_EVENT || dwCtrlType == CTRL_LOGOFF_EVENT ||
16- dwCtrlType == CTRL_SHUTDOWN_EVENT) {
17- instance_->handle_signal_ (SIGTERM);
16+ dwCtrlType == CTRL_SHUTDOWN_EVENT) {
17+ instance_->pImpl -> handle_signal_ (SIGTERM);
1818 return TRUE ;
1919 }
2020 return FALSE ;
2121 }
2222
23- void handle_signal_ (int signal){
23+ void handle_signal_ (int signal) {
2424 if (signal_event_ != INVALID_HANDLE_VALUE) {
2525 signal_code_ = signal;
2626 SetEvent (signal_event_);
2727 }
2828 }
29-
30- static SignalManager::Impl * instance_;
29+
30+ static SignalManager* instance_;
3131 HANDLE signal_event_ = INVALID_HANDLE_VALUE;
3232 int signal_code_ = 0 ;
3333};
3434
35- SignalManager::Impl * SignalManager::Impl::instance_ = nullptr ;
35+ SignalManager* SignalManager::Impl::instance_ = nullptr ;
3636
37- SignalManager::SignalManager ()
38- :pImpl(std::make_unique<Impl>()) {
39- SignalManager::Impl::instance_ = this ->pImpl ;
37+ SignalManager::SignalManager () : pImpl(std::make_unique<Impl>()) {
38+ SignalManager::Impl::instance_ = this ;
4039 SetConsoleCtrlHandler (SignalManager::Impl::console_handler_routine_, TRUE );
4140}
4241
@@ -57,6 +56,5 @@ int SignalManager::wait() {
5756 return static_cast <DWORD>(pImpl->signal_code_ );
5857}
5958
60-
6159} // namespace sdk
6260} // namespace viam
0 commit comments