File indexing completed on 2024-05-19 05:39:08
0001 /* 0002 SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #pragma once 0008 0009 #include <QObject> 0010 #include <QSet> 0011 #include <QSocketNotifier> 0012 0013 /** 0014 * Class to be able to receive ANSI C signals and forward them onto the Qt eventloop 0015 * 0016 * It's a singleton as it relies on static data getting defined. 0017 */ 0018 class SignalHandler : public QObject 0019 { 0020 Q_OBJECT 0021 public: 0022 ~SignalHandler() override; 0023 void addSignal(int signal); 0024 0025 static SignalHandler *self(); 0026 0027 Q_SIGNALS: 0028 void signalReceived(int signal); 0029 0030 private: 0031 SignalHandler(); 0032 void handleSignal(); 0033 static void signalHandler(int signal); 0034 0035 QSet<int> m_signalsRegistered; 0036 static int signalFd[2]; 0037 QSocketNotifier *m_handler = nullptr; 0038 };