Nuria Framework - Core
Core module of the NuriaProject Framework
 All Classes Functions Typedefs Enumerations Enumerator Groups
unixsignalhandler.hpp
1 /* Copyright (c) 2014, The Nuria Project
2  * This software is provided 'as-is', without any express or implied
3  * warranty. In no event will the authors be held liable for any damages
4  * arising from the use of this software.
5  * Permission is granted to anyone to use this software for any purpose,
6  * including commercial applications, and to alter it and redistribute it
7  * freely, subject to the following restrictions:
8  * 1. The origin of this software must not be misrepresented; you must not
9  * claim that you wrote the original software. If you use this software
10  * in a product, an acknowledgment in the product documentation would be
11  * appreciated but is not required.
12  * 2. Altered source versions must be plainly marked as such, and must not be
13  * misrepresented as being the original software.
14  * 3. This notice may not be removed or altered from any source
15  * distribution.
16  */
17 
18 #ifndef UNIXSIGNALHANDLER_HPP
19 #define UNIXSIGNALHANDLER_HPP
20 
21 #include "callback.hpp"
22 #include <QObject>
23 
24 namespace Nuria {
25 
26 class UnixSignalHandlerPrivate;
27 
59 class NURIA_CORE_EXPORT UnixSignalHandler : public QObject {
60  Q_OBJECT
61 public:
62 
64  static UnixSignalHandler *get ();
65 
67  ~UnixSignalHandler () override;
68 
74  bool listenToUnixSignal (int signalId);
75 
81  bool ignoreUnixSignal (int signalId);
82 
87  bool isListeningTo (int signalId);
88 
97  void invokeOnSignal (int signalId, const Callback &callback);
98 
99 signals:
100 
105  void signalRaised (int signalId);
106 
108  void sigTerm ();
109 
111  void sigInterrupt ();
112 
114  void sigUser1 ();
115 
117  void sigUser2 ();
118 
119 private slots:
120 
121  void signalDelegate ();
122 
123 private:
124  explicit UnixSignalHandler (QObject *parent = 0);
125 
126  bool createInternalPipe ();
127  void printError (const char *message);
128  bool tryReadUnixSignal ();
129  void invokeSignalHandlers (int signalId);
130 
131  UnixSignalHandlerPrivate *d_ptr;
132 
133 };
134 
135 }
136 
137 #endif // UNIXSIGNALHANDLER_HPP
A modern style callback mechanism which can be bound to various method types including slots...
Definition: callback.hpp:141
Utility class to react to UNIX signals in a Qt fashion.
Definition: unixsignalhandler.hpp:59