MythTV  master
signalhandling.h
Go to the documentation of this file.
1 #ifndef SIGNALHANDLING_H_
2 #define SIGNALHANDLING_H_
3 
4 #include <QObject>
5 #include <QSocketNotifier>
6 #include <QMutex>
7 #include <QList>
8 #include <QMap>
9 
10 #include <cstdint>
11 #include <csignal>
12 #include <unistd.h>
13 
14 #include "mythbaseexp.h" // MBASE_PUBLIC , etc.
15 
16 #ifdef _WIN32
17 // Quick fix to let this compile for Windows: we have it disabled on the
18 // calling side for Windows anyways, IIRC.
19 typedef void siginfo_t;
20 #endif
21 
22 typedef void (*SigHandlerFunc)(void);
23 
25 class MBASE_PUBLIC SignalHandler: public QObject
26 {
27  Q_OBJECT
28 
29  public:
30  static void Init(QList<int> &signallist, QObject *parent = nullptr);
31  static void Done(void);
32 
33  static void SetHandler(int signum, SigHandlerFunc handler);
34 
35  static bool IsExiting(void) { return s_exit_program; }
36 
37  // Unix signal handler.
38  // context is of type ucontext_t * cast to void *
39  static void signalHandler(int signum, siginfo_t *info, void *context);
40 
41  public slots:
42  // Qt signal handler.
43  void handleSignal(void);
44 
45  private:
46  SignalHandler(QList<int> &signallist, QObject *parent);
47  ~SignalHandler();
48  void SetHandlerPrivate(int signum, SigHandlerFunc handler);
49 
50  static int s_sigFd[2];
51  static volatile bool s_exit_program;
52  QSocketNotifier *m_notifier {nullptr};
53  char *m_sigStack {nullptr};
54 
55  QMutex m_sigMapLock;
56  QMap<int, SigHandlerFunc> m_sigMap;
57  static QList<int> s_defaultHandlerList;
58 
59  static QMutex s_singletonLock;
61 };
62 
63 #endif
64 
65 /*
66  * vim:ts=4:sw=4:ai:et:si:sts=4
67  */
unsigned int slots[4]
Definition: element.c:38
static bool IsExiting(void)
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
A container object to handle UNIX signals in the Qt space correctly.
static QList< int > s_defaultHandlerList
void siginfo_t
static QMutex s_singletonLock
QMutex m_sigMapLock
void(* SigHandlerFunc)(void)
static SignalHandler * s_singleton
static volatile bool s_exit_program
QMap< int, SigHandlerFunc > m_sigMap