|
Sierra Toolkit
Version of the Day
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright 2002 Sandia Corporation. */ 00003 /* Under the terms of Contract DE-AC04-94AL85000, there is a */ 00004 /* non-exclusive license for use of this work by or on behalf */ 00005 /* of the U.S. Government. Export of this program may require */ 00006 /* a license from the United States Government. */ 00007 /*--------------------------------------------------------------------*/ 00008 00009 #ifndef STK_UTIL_DIAG_SignalHandler_hpp 00010 #define STK_UTIL_DIAG_SignalHandler_hpp 00011 00012 #include <map> 00013 00014 #include <stk_util/diag/String.hpp> 00015 #include <stk_util/util/Callback.hpp> 00016 00017 struct sigaction; 00018 00025 namespace sierra { 00026 00031 class SignalHandler 00032 { 00033 public: 00039 static SignalHandler &instance(); 00040 00041 static bool check_signal_name(const sierra::String& signal); 00042 00048 void handle_signal(int signal); 00049 00056 void add_handler(int signal, CallbackBase &callback); 00057 00064 void add_handler(const String &signal_name, CallbackBase &callback); 00065 00072 void remove_handler(int signal, CallbackBase &callback); 00073 00080 void remove_handler(const String &signal_name, CallbackBase &callback); 00081 00086 void remove_all_handlers(); 00087 00088 private: 00089 typedef std::multimap<int, CallbackBase *> HandlerMap; 00090 typedef std::multimap<int, struct sigaction *> OldActionMap; 00091 00092 HandlerMap m_handlerMap; 00093 OldActionMap m_oldActionMap; 00094 }; 00095 00096 } // namespace sierra 00097 00098 #endif // STK_UTIL_DIAG_SignalHandler_h