Scarab  v3.0.0
Project 8 C++ Utility Library
signal_handler.hh
Go to the documentation of this file.
1 /*
2  * signal_handler.hh
3  *
4  * Created on: Dec 3, 2013
5  * Author: N.S. Oblath
6  */
7 
8 #ifndef SCARAB_SIGNAL_HANDLER_HH_
9 #define SCARAB_SIGNAL_HANDLER_HH_
10 
11 #include "scarab_api.hh"
12 #include "member_variables.hh"
13 
14 #include <memory>
15 #include <mutex>
16 #include <set>
17 
18 
19 #ifndef _GNU_SOURCE
20 #define _GNU_SOURCE
21 #endif
22 #ifndef __USE_GNU
23 #define __USE_GNU
24 #endif
25 
26 
27 namespace scarab
28 {
29  class cancelable;
30 
31 
65  {
66  public:
68  virtual ~signal_handler();
69 
71  void add_cancelable( cancelable* a_cancelable );
73  void remove_cancelable( cancelable* a_cancelable );
74 
76  void reset();
77 
79  [[noreturn]] static void handle_terminate() noexcept;
80 
82  static void handle_exit_error( int a_sig );
83 
85  static void handle_exit_success( int a_sig );
86 
88  [[noreturn]] static void terminate( int a_code ) noexcept;
89 
91  static void exit( int a_code );
92 
94  static void print_current_exception( bool a_use_logging );
95 
97  static void print_stack_trace( bool a_use_logging );
98 
100  static void cancel_all( int a_code );
101 
102  private:
103 
104  typedef std::set< cancelable* > cancelers;
105  typedef cancelers::const_iterator cancelers_cit_t;
106  typedef cancelers::iterator cancelers_it_t;
107 
108  static cancelers s_cancelers;
109  static std::recursive_mutex s_mutex;
110 
111  public:
112  mv_accessible_static_noset( bool, exited );
113  mv_accessible_static( int, return_code );
114 
115  mv_accessible_static_noset( bool, handling_sig_abrt );
116  mv_accessible_static_noset( bool, handling_sig_term );
117  mv_accessible_static_noset( bool, handling_sig_int );
118  mv_accessible_static_noset( bool, handling_sig_quit );
119 
120  };
121 
122 } /* namespace scarab */
123 #endif /* SCARAB_SIGNAL_HANDLER_HH_ */
#define mv_accessible_static_noset
cancelers::iterator cancelers_it_t
static cancelers s_cancelers
cancelers::const_iterator cancelers_cit_t
#define SCARAB_API
Definition: scarab_api.hh:24
Deals with cleanly exiting an application, and includes signal and std::terminate handler functions...
#define mv_accessible_static
static std::recursive_mutex s_mutex
std::set< cancelable *> cancelers