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