1/*
2 SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#ifndef KSIGNALHANDLER_H
8#define KSIGNALHANDLER_H
9
10#include <QObject>
11#include <kcoreaddons_export.h>
12
13class KSignalHandlerPrivate;
14
15/**
16 * Allows getting ANSI C signals and forward them onto the Qt eventloop.
17 *
18 * It's a singleton as it relies on static data getting defined.
19 *
20 * \code
21 * {
22 * KSignalHandler::self()->watchSignal(SIGTERM);
23 * connect(KSignalHandler::self(), &KSignalHandler::signalReceived,
24 * this, &SomeClass::handleSignal);
25 * job->start();
26 * }
27 * \endcode
28 *
29 * @since 5.92
30 */
31class KCOREADDONS_EXPORT KSignalHandler : public QObject
32{
33 Q_OBJECT
34public:
35 ~KSignalHandler() override;
36
37 /**
38 * Adds @p signal to be watched for. Once the process is notified about this signal, @m signalReceived will be emitted with the same @p signal as an
39 * argument.
40 *
41 * @see signalReceived
42 */
43 void watchSignal(int signal);
44
45 /**
46 * Fetches an instance we can use to register our signals.
47 */
48 static KSignalHandler *self();
49
50Q_SIGNALS:
51 /**
52 * Notifies that @p signal is emitted.
53 *
54 * To catch a signal, we need to make sure it's registered using @m watchSignal.
55 *
56 * @see watchSignal
57 */
58 void signalReceived(int signal);
59
60private:
61 KCOREADDONS_NO_EXPORT KSignalHandler();
62
63 QScopedPointer<KSignalHandlerPrivate> d;
64};
65
66#endif
67

source code of kcoreaddons/src/lib/util/ksignalhandler.h