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 EventEvent public header */
26 #ifndef HH_EventEvent_
27 #define HH_EventEvent_ 1
30 #include <boost/function.hpp>
31 #include "../boost/intrusive/ilist_hook.hpp"
32 #include "FIFORunner.hh"
34 //#include "EventEvent.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
41 struct EventEventListTag;
42 typedef boost::intrusive::ilist_base_hook<EventEventListTag> EventEventListBase;
43 class EventEventDispatcher;
46 /** \brief Event hook event
48 This event is special: It is not a real event, it is a kind of hook which is called,
49 whenever any other event is signaled. Combining this with explicit priority specification,
50 this can be used to implement hooks which are called before or after any other callback.
53 void beforeEventHook();
54 void afterEventHook();
56 senf::scheduler::EventEvent beforeEventHookEvent (
57 "beforeEventHook", beforeEventHook, true, senf::scheduler::EventEvent::PRIORITY_LOW);
58 senf::scheduler::EventEvent afterEventHookEvent (
59 "afterEventHook", afterEventHook, true, senf::scheduler::EventEvent::PRIORITY_HIGH);
62 This usage assumes, that all ordinary events are registered with \c PRIORITY_NORMAL.
64 The EventEvent class is an implementation of the RAII idiom: The event will be automatically
65 unregistered in the EventEvent destructor. The EventEvent instance should be created within
66 the same scope or on a scope below where the callback is defined (e.g. if the callback is a
67 member function it should be defined as a class member).
70 : public detail::FIFORunner::TaskInfo,
71 public detail::EventEventListBase
74 ///////////////////////////////////////////////////////////////////////////
77 typedef boost::function<void ()> Callback;
79 ///////////////////////////////////////////////////////////////////////////
80 ///\name Structors and default members
83 EventEvent(std::string const & name, Callback const & cb,
84 bool initiallyEnabled = true, Priority priority = PRIORITY_NORMAL);
85 ///< Register an event hook
86 /**< Registers \a cb to be called whenever any other event
87 is signaled by the scheduler. If \a initiallyEnabled is
88 set \c false, the callback will not be enabled
89 automatically. Use enable() to do so.
90 \param[in] name Descriptive event name (purely
92 \param[in] cb Callback to call
93 \param[in] initiallyEnabled if set \c false, do not
94 enable callback automatically.
95 \param[in] priority event priority, defaults to
100 ///////////////////////////////////////////////////////////////////////////
102 void disable(); ///< Disable event
103 void enable(); ///< Enable event
105 void action(Callback const & cb); ///< Change event callback
110 virtual void v_run();
111 virtual char const * v_type() const;
112 virtual std::string v_info() const;
116 friend class detail::EventEventDispatcher;
121 ///////////////////////////////hh.e////////////////////////////////////////
122 #include "EventEvent.cci"
123 //#include "EventEvent.ct"
124 //#include "EventEvent.cti"
131 // comment-column: 40
132 // c-file-style: "senf"
133 // indent-tabs-mode: nil
134 // ispell-local-dictionary: "american"
135 // compile-command: "scons -u test"