OSVR-Core
RegisterShutdownHandlerWin32.h
Go to the documentation of this file.
1 
12 // Copyright 2014 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 
26 #ifndef INCLUDED_RegisterShutdownHandlerWin32_h_GUID_4D1BA155_D70B_4BAD_92AF_F20D02D911AA
27 #define INCLUDED_RegisterShutdownHandlerWin32_h_GUID_4D1BA155_D70B_4BAD_92AF_F20D02D911AA
28 
29 #ifdef OSVR_USE_WIN32_SHUTDOWN_HANDLER
30 
31 // Internal Includes
32 // - none
33 
34 // Library/third-party includes
35 // - none
36 
37 // Standard includes
38 #define WIN32_LEAN_AND_MEAN
39 #include <windows.h>
40 
41 namespace osvr {
42 namespace server {
43 #ifndef OSVR_DOXYGEN_EXTERNAL
44  namespace detail {
45  template <ShutdownHandler F>
46  BOOL WINAPI handlerWrapper(DWORD signalType) {
47  switch (signalType) {
48  case CTRL_C_EVENT:
49  case CTRL_BREAK_EVENT:
50  case CTRL_CLOSE_EVENT:
51  case CTRL_LOGOFF_EVENT:
52  case CTRL_SHUTDOWN_EVENT:
53  F();
54  return TRUE;
55  default:
56  return FALSE;
57  }
58  }
59  } // namespace detail
60 #endif // #ifndef OSVR_DOXYGEN_EXTERNAL
61 
67  template <ShutdownHandler F> inline void registerShutdownHandler() {
68  SetConsoleCtrlHandler(&detail::handlerWrapper<F>, TRUE);
69  }
70 } // namespace server
71 } // namespace osvr
72 
73 #endif // OSVR_USE_WIN32_SHUTDOWN_HANDLER
74 
75 #endif // INCLUDED_RegisterShutdownHandlerWin32_h_GUID_4D1BA155_D70B_4BAD_92AF_F20D02D911AA
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Definition: newuoa.h:1888