/*! \file pisignals.h * \ingroup System * \~\brief * \~english System signals * \~russian Сигналы системы */ /* PIP - Platform Independent Primitives Signals Ivan Pelipenko peri4ko@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #ifndef PISIGNALS_H #define PISIGNALS_H #include "piflags.h" #include //! \~english System signals handler //! \~russian Обработчик системных сигналов class PIP_EXPORT PISignals { public: //! \~english Signal types //! \~russian Типы сигналов enum Signal { Interrupt = 0x01, //!< Interrupt from keyboard Illegal = 0x02, //!< Illegal Instruction Abort = 0x04, //!< Abort signal FPE = 0x08, //!< Floating point exception SegFault = 0x10, //!< Invalid memory reference Termination = 0x20, //!< Termination signal Hangup = 0x40, //!< Hangup detected Quit = 0x80, //!< Quit from keyboard Kill = 0x100, //!< Kill signal BrokenPipe = 0x200, //!< Broken pipe Timer = 0x400, //!< Timer signal UserDefined1 = 0x800, //!< User-defined signal 1 UserDefined2 = 0x1000, //!< User-defined signal 2 ChildStopped = 0x2000, //!< Child stopped or terminated Continue = 0x4000, //!< Continue if stopped StopProcess = 0x8000, //!< Stop process StopTTY = 0x10000, //!< Stop typed at tty StopTTYInput = 0x20000, //!< Stop tty input StopTTYOutput = 0x40000, //!< Stop tty output All = 0xFFFFF //!< All signals }; //! \~english Signal handler callback type //! \~russian Тип коллбэка обработчика сигналов //! \note slot is any function with format "void(PISignals::Signal)" typedef std::function SignalEvent; //! \~english Sets signal handler callback //! \~russian Устанавливает коллбэк обработчика сигналов static void setSlot(SignalEvent slot) { ret_func = slot; } //! \~english Grabs specified signals //! \~russian Перехватывает указанные сигналы static void grabSignals(PIFlags signals_); //! \~english Releases specified signals //! \~russian Освобождает указанные сигналы static void releaseSignals(PIFlags signals_); //! \~english Raises signal //! \~russian Генерирует сигнал static void raiseSignal(PISignals::Signal signal); private: PISignals() { ret_func = 0; } ~PISignals() {} static int signalCode(PISignals::Signal signal); static PISignals::Signal signalFromCode(int signal); static void signal_event(int signal); static SignalEvent ret_func; }; #endif // PISIGNALS_H