Scarab  v3.5.3
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  static void add_cancelable_s( cancelable* a_cancelable );
81  static void remove_cancelable_s( cancelable* a_cancelable );
82 
84  [[noreturn]] static void handle_terminate() noexcept;
85 
87  static void handle_exit_error( int a_sig );
88 
90  static void handle_exit_success( int a_sig );
91 
93  [[noreturn]] static void terminate( int a_code ) noexcept;
94 
96  static void exit( int a_code );
97 
99  static void print_current_exception( bool a_use_logging );
100 
102  static void print_stack_trace( bool a_use_logging );
103 
105  static void cancel_all( int a_code );
106 
107  private:
108 
109  typedef std::set< cancelable* > cancelers;
110  typedef cancelers::const_iterator cancelers_cit_t;
111  typedef cancelers::iterator cancelers_it_t;
112 
113  static cancelers s_cancelers;
114  static std::recursive_mutex s_mutex;
115 
116  public:
117  mv_accessible_static_noset( bool, exited );
118  mv_accessible_static( int, return_code );
119 
120  mv_accessible_static_noset( bool, handling_sig_abrt );
121  mv_accessible_static_noset( bool, handling_sig_term );
122  mv_accessible_static_noset( bool, handling_sig_int );
123  mv_accessible_static_noset( bool, handling_sig_quit );
124 
125  };
126 
127 } /* namespace scarab */
128 #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