OSVR-Core
RegisterShutdownHandlerPOSIXSignal.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_RegisterShutdownHandlerPOSIXSignal_h_GUID_0B85D38D_08A2_49AA_7FA4_1BED1048FD11
27 #define INCLUDED_RegisterShutdownHandlerPOSIXSignal_h_GUID_0B85D38D_08A2_49AA_7FA4_1BED1048FD11
28 
29 #ifdef OSVR_USE_POSIX_SIGNAL_SHUTDOWN_HANDLER
30 
31 // Internal Includes
32 // - none
33 
34 // Library/third-party includes
35 // - none
36 
37 // Standard includes
38 #include <signal.h>
39 
40 namespace osvr {
41 namespace server {
42 #ifndef OSVR_DOXYGEN_EXTERNAL
43  namespace detail {
44  template <ShutdownHandler F> void handlerWrapper(int) { F(); }
45  } // namespace detail
46 #endif // #ifndef OSVR_DOXYGEN_EXTERNAL
47 
53  template <ShutdownHandler F> inline void registerShutdownHandler() {
54  signal(SIGINT, &detail::handlerWrapper<F>);
55  signal(SIGKILL, &detail::handlerWrapper<F>);
56  signal(SIGTERM, &detail::handlerWrapper<F>);
57  signal(SIGPIPE, &detail::handlerWrapper<F>);
58  }
59 } // namespace server
60 } // namespace osvr
61 
62 #endif // OSVR_USE_POSIX_SIGNAL_SHUTDOWN_HANDLER
63 
64 #endif // INCLUDED_RegisterShutdownHandlerPOSIXSignal_h_GUID_0B85D38D_08A2_49AA_7FA4_1BED1048FD11
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Definition: newuoa.h:1888