5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the
17 // Free Software Foundation, Inc.,
18 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 \brief Binding public header */
27 #include <boost/utility.hpp>
28 #include "Scheduler.hh"
30 //#include "Binding.mpp"
31 ///////////////////////////////hh.p////////////////////////////////////////
35 /** \brief Manage scheduler handle binding
37 This class will manage the binding of an arbitrary handle to the scheduler: The handle will
38 automatically be removed from the Scheduler when this instance is destroyed. Example using a
39 SocketHandle instance for the handle:
44 Foo(SocketHandle handle) : binding_ (handle, senf::membind(&cb, this),
45 senf::Scheduler::EV_READ) {}
47 void blarf() { binding_.disable(); }
50 void cb(Scheduler::EventId event);
52 senf::SchedulerBinding binding_;
56 The handle will be registered automatically in the constructor and will be unregistered in
57 the destructor. Additionally, the helper has enable() and disable() members to register or
58 remove the handle to/from the Scheduler.
60 class SchedulerBinding
64 template <class Handle>
65 SchedulerBinding(Handle const & handle, Scheduler::FdCallback cb,
66 int eventMask = Scheduler::EV_ALL, bool enabled = true);
67 ///< Register handle with the Scheduler
68 /**< This constructor is like calling Scheduler::add()
69 unless \a enabled is \c false, in which case the handle
70 is \e not initially registered (it may be registered by
72 \param[in] handle Handle to register
73 \param[in] cb Callback
74 \param[in] eventMask type of events to register for
75 \param[in] enabled wether to add handle to Scheduler
78 ~SchedulerBinding(); ///< Remove scheduler registration
80 void enable(); ///< Add handle to Scheduler
81 /**< Adds the handle if it is not already registered */
82 void disable(); ///< Remove handle from Scheduler
83 /**< Remove handle from Scheduler if registered */
85 bool enabled(); ///< \c true, if handle is registered
91 Scheduler::FdCallback cb_;
97 ///////////////////////////////hh.e////////////////////////////////////////
98 #include "Binding.cci"
99 //#include "Binding.ct"
100 #include "Binding.cti"
107 // comment-column: 40
108 // c-file-style: "senf"
109 // indent-tabs-mode: nil
110 // ispell-local-dictionary: "american"
111 // compile-command: "scons -u test"