4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief SignalDispatcher public header */
31 #ifndef HH_SENF_Scheduler_SignalEvent_
32 #define HH_SENF_Scheduler_SignalEvent_ 1
36 #include <boost/function.hpp>
37 #include "FIFORunner.hh"
38 #include <senf/boost_intrusive/iset_hook.hpp>
40 //#include "SignalEvent.mpp"
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
51 typedef boost::intrusive::iset_base_hook<SignalSetTag> SignalSetBase;
52 struct SignalSetCompare;
53 struct FindNumericSignal;
54 struct SignalDispatcher;
57 /** \brief UNIX signal event
59 The SignalEvent class registers a callback for UNIX signals. The callback will be called \e
60 synchronously (not from within the UNIX signal handler) by the scheduler.
62 The SignalEvent class is an implementation of the RAII idiom: The event will be
63 automatically unregistered in the SignalEvent destructor. The SignalEvent instance should be
64 created within the same scope or on a scope below where the callback is defined (e.g. if the
65 callback is a member function it should be defined as a class member).
68 : public detail::FIFORunner::TaskInfo,
69 public detail::SignalSetBase
72 //-////////////////////////////////////////////////////////////////////////
75 typedef boost::function<void (siginfo_t const &)> Callback;
78 //-////////////////////////////////////////////////////////////////////////
79 ///\name Structors and default members
82 SignalEvent(int signal, Callback const & cb, bool initiallyEnabled=true);
83 ///< Register a signal event
84 /**< Registers \a cb as callback for the UNIX signal \a
85 signal. If \a initiallyEnabled is set \c false, the
86 callback will not be enabled automatically. Use
88 \param[in] signal UNIX signal to register callback for
89 \param[in] cb Callback to call
90 \param[in] initiallyEnabled if set \c false, do not
91 enable callback automatically. */
95 //-////////////////////////////////////////////////////////////////////////
97 void disable(); ///< Enable signal event registration
98 void enable(); ///< Disable the signal event registration
100 void action(Callback const & cb); ///< Change signal event callback
103 virtual void v_run();
104 virtual char const * v_type() const;
105 virtual std::string v_info() const;
111 friend class detail::SignalSetCompare;
112 friend class detail::FindNumericSignal;
113 friend class detail::SignalDispatcher;
119 //-/////////////////////////////////////////////////////////////////////////////////////////////////
120 #include "SignalEvent.cci"
121 //#include "SignalEvent.ct"
122 //#include "SignalEvent.cti"
129 // comment-column: 40
130 // c-file-style: "senf"
131 // indent-tabs-mode: nil
132 // ispell-local-dictionary: "american"
133 // compile-command: "scons -u test"