#pragma once #ifndef MESSMER_CPPUTILS_PROCESS_SIGNALCATCHER_H_ #define MESSMER_CPPUTILS_PROCESS_SIGNALCATCHER_H_ #include #include #include #include #include namespace cpputils { namespace details { class SignalCatcherImpl; } /* * While an instance of this class is in scope, the specified signal (e.g. SIGINT) * is caught and doesn't exit the application. You can poll if the signal occurred. */ class SignalCatcher final { public: SignalCatcher(): SignalCatcher({SIGINT, SIGTERM}) {} SignalCatcher(std::initializer_list signals); ~SignalCatcher(); bool signal_occurred() const { return _signal_occurred; } private: // note: _signal_occurred must be initialized before _impl because _impl might use it std::atomic _signal_occurred; std::vector> _impls; DISALLOW_COPY_AND_ASSIGN(SignalCatcher); }; } #endif