NCBI C++ ToolKit
ncbi_signal.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CORELIB___NCBI_SIGNAL__HPP
2 #define CORELIB___NCBI_SIGNAL__HPP
3 
4 /* $Id: ncbi_signal.hpp 83046 2018-07-24 12:05:33Z ivanov $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Mike DiCuccio
30  *
31  * File Description:
32  *
33  */
34 
35 /// @file ncbi_signal.hpp
36 /// Setup interrupt signal handling.
37 
38 #include <corelib/ncbistd.hpp>
39 
40 /** @addtogroup Utility
41  *
42  * @{
43  */
44 
46 
47 
48 /////////////////////////////////////////////////////////////////////////////
49 ///
50 /// CSignal --
51 ///
52 /// Setup interrupt signal handling.
53 ///
54 /// @note
55 /// Windows:
56 /// The SIGINT cannot be cough by handler, except it was explicitly
57 /// generated by calling raise().
58 /// The SIGILL, SIGSEGV, and SIGTERM signals are not generated under
59 /// Windows NT. They are included for ANSI compatibility. Thus you can
60 /// set signal handlers for these signals, and you can also explicitly
61 /// generate these signals by calling raise().
62 /// @note
63 /// Signal settings are not preserved in spawned processes, they resets
64 /// to the default in the each child process.
65 
67 {
68 public:
69  enum ESignal {
70  eSignal_HUP = (1<<1), ///< Hangup
71  eSignal_INT = (1<<2), ///< Interrupt
72  eSignal_QUIT = (1<<3), ///< Quit
73  eSignal_ILL = (1<<4), ///< Illegal instruction
74  eSignal_FPE = (1<<5), ///< Floating-point exception
75  eSignal_ABRT = (1<<6), ///< Abort
76  eSignal_SEGV = (1<<7), ///< Segmentation violation
77  eSignal_PIPE = (1<<8), ///< Broken pipe
78  eSignal_TERM = (1<<9), ///< Termination
79  eSignal_USR1 = (1<<10), ///< User defined signal 1
80  eSignal_USR2 = (1<<11), ///< User defined signal 2
81 
82  eSignal_Any = 0xfffffff ///< Any/all signal(s) from the list above
83  };
84  typedef int TSignalMask; ///< Binary OR of "ESignal"
85 
86  /// Sets interrupt signal handling.
87  ///
88  /// Install default signal handler for all specified signal types.
89  /// Use IsSignaled/GetSignals to check in your code to check that some
90  /// signal was caught. Consecutive calls add signals to list of handled
91  /// signals.
92  /// @sa IsSignaled, GetSignals, Reset
93  /// @param signals
94  /// The set of signals to check.
95  static void TrapSignals(TSignalMask signals);
96 
97  /// Reset the list of handled signal.
98  ///
99  /// Default signal handlers will be used for all handled signals (SIG_DFL).
100  /// @return
101  /// List of handled signals before reset.
102  /// @sa TrapSignals, GetSignals
103  static TSignalMask Reset(void);
104 
105  /// Check that any of specified signals is received.
106  ///
107  /// @param signals
108  /// The set of signals to check.
109  /// @return
110  /// TRUE if any of specified signals is set, FALSE otherwise.
111  /// @sa TrapSignals, GetSignals, ClearSignals
112  static bool IsSignaled(TSignalMask signals = eSignal_Any);
113 
114  /// Get signals state.
115  ///
116  /// @return
117  /// Current signal state. Each bit represent some caught signal.
118  /// @sa TrapSignals, ClearSignals, IsSignaled
119  static TSignalMask GetSignals(void);
120 
121  /// Clear signals state.
122  ///
123  /// @return
124  /// Current signal state after clearing. Each bit represent some caught signal.
125  /// @sa TrapSignals, GetSignals, IsSignaled
126  static TSignalMask ClearSignals(TSignalMask signals = eSignal_Any);
127 
128  /// Sends a signal to the current process.
129  ///
130  /// @param signal
131  /// Signal to send to the current process.
132  /// @return
133  /// TRUE on success, FALSE otherwise. Return FALSE also if the signal
134  /// is not supported on current platform.
135  static bool Raise(ESignal signal);
136 };
137 
138 
140 
141 
142 #endif // CORELIB___NCBI_SIGNAL__HPP
CSignal –.
Definition: ncbi_signal.hpp:67
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static bool IsSignaled(TSignalMask signals=eSignal_Any)
Check that any of specified signals is received.
static TSignalMask Reset(void)
Reset the list of handled signal.
static void TrapSignals(TSignalMask signals)
Sets interrupt signal handling.
int TSignalMask
Binary OR of "ESignal".
Definition: ncbi_signal.hpp:84
static bool Raise(ESignal signal)
Sends a signal to the current process.
static TSignalMask ClearSignals(TSignalMask signals=eSignal_Any)
Clear signals state.
static TSignalMask GetSignals(void)
Get signals state.
#define NCBI_XNCBI_EXPORT
Definition: ncbi_export.h:1283
Modified on Fri Sep 20 14:57:58 2024 by modify_doxy.py rev. 669887