2020-06-27 07:04:56 +00:00
|
|
|
#ifndef MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_
|
|
|
|
#define MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_
|
|
|
|
|
2020-06-28 06:52:03 +00:00
|
|
|
#pragma once
|
2020-06-27 07:04:56 +00:00
|
|
|
|
2020-06-28 06:52:03 +00:00
|
|
|
#include <myx/base/config.hpp>
|
2020-06-27 07:04:56 +00:00
|
|
|
#include <myx/qt/posix_signal_watcher.hpp>
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QSocketNotifier>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#define MYX_QT_HAS_POSIX_SIGNALS 0
|
|
|
|
#else
|
|
|
|
#define MYX_QT_HAS_POSIX_SIGNALS 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MYX_QT_HAS_POSIX_SIGNALS
|
|
|
|
#include <csignal>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <cerrno>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace myx {
|
|
|
|
|
|
|
|
namespace qt {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The PosixSignalWatcherPrivate class implements the back-end signal
|
|
|
|
* handling for the PosixSignalWatcher.
|
|
|
|
*
|
|
|
|
* \see http://qt-project.org/doc/qt-5.0/qtdoc/POSIX-signals.html
|
|
|
|
*/
|
|
|
|
class PosixSignalWatcherPrivate : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
PosixSignalWatcherPrivate( PosixSignalWatcher* q );
|
|
|
|
~PosixSignalWatcherPrivate();
|
|
|
|
|
|
|
|
void watchForSignal( int signal );
|
|
|
|
static void signalHandler( int signal );
|
|
|
|
|
|
|
|
private:
|
|
|
|
Q_DECLARE_PUBLIC( PosixSignalWatcher )
|
|
|
|
|
2020-06-28 06:52:03 +00:00
|
|
|
PosixSignalWatcher* const q_ptr = nullptr;
|
|
|
|
static std::array< int, 2 > mSockpair;
|
2020-06-27 07:04:56 +00:00
|
|
|
std::unique_ptr< QSocketNotifier > m_notifier;
|
|
|
|
QList< int > m_watchedSignals;
|
|
|
|
}; // class PosixSignalWatcherPrivate
|
|
|
|
|
|
|
|
} // namespace qt
|
|
|
|
|
|
|
|
} // namespace myx
|
|
|
|
|
|
|
|
#endif // ifndef MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_
|