4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief SignalDispatcher public header */
26 #ifndef HH_SignalDispatcher_
27 #define HH_SignalDispatcher_ 1
32 #include "FdManager.hh"
33 #include "FIFORunner.hh"
35 //#include "SignalDispatcher.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
41 /** \brief Scheduler dispatcher managing UNIX signals
43 This dispatcher supports registering UNIX signals with the Scheduler.
45 \implementation SignalDispatcher provides a single signal handler which all registered
46 signals are assigned to. When a signal is received, data is written to a pipe which has
47 been added to the FdManager and this signals the event.
49 \todo Add signal block/unblock management to the FdManager to reduce the number of
52 class SignalDispatcher
53 : public FdManager::Event
56 ///////////////////////////////////////////////////////////////////////////
59 typedef boost::function<void (siginfo_t const &)> Callback;
61 ///////////////////////////////////////////////////////////////////////////
62 ///\name Structors and default members
65 SignalDispatcher(FdManager & manager, FIFORunner & runner);
69 ///////////////////////////////////////////////////////////////////////////
71 void add(int signal, Callback const & cb); ///< Add signal event
72 /**< \param[in] signal signal number
73 \param[in] cb Callback */
75 void remove(int signal); ///< Unregister signal event
77 void unblockSignals(); ///< Unblock registered signals
78 /**< Must be called before waiting for an event */
79 void blockSignals(); ///< Block registered signals
80 /**< Must be called directly after FdManager returns */
82 bool empty() const; ///< \c true, if no signal is registered.
87 ///< Internal: UNIX signal event
89 : public FIFORunner::TaskInfo
91 SignalEvent(int signal, Callback cb_);
98 virtual void signal(int events);
99 static void sigHandler(int signal, ::siginfo_t * siginfo, void *);
101 FdManager & manager_;
102 FIFORunner & runner_;
104 typedef std::map<int, SignalEvent> HandlerMap;
105 HandlerMap handlers_;
112 static SignalDispatcher * instance_;
118 ///////////////////////////////hh.e////////////////////////////////////////
119 #include "SignalDispatcher.cci"
120 //#include "SignalDispatcher.ct"
121 //#include "SignalDispatcher.cti"
128 // comment-column: 40
129 // c-file-style: "senf"
130 // indent-tabs-mode: nil
131 // ispell-local-dictionary: "american"
132 // compile-command: "scons -u test"