myxlib/src/myx/qt/posix_signal_watcher_p.hpp

64 lines
1.3 KiB
C++

#ifndef MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_
#define MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_
#pragma once
#include <myx/base/config.hpp>
#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 )
PosixSignalWatcher* const q_ptr = nullptr;
static std::array< int, 2 > mSockpair;
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_