From: g0dil Date: Mon, 6 Nov 2006 11:53:26 +0000 (+0000) Subject: Restructure internal Scheduler callback representation X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=1835b928b179302ecb716d697fbf3fa24b415ba4;p=senf.git Restructure internal Scheduler callback representation Add missing operators to integer Parsers Fix satcom::pkf::nil to be a valid iterator git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@149 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/ParseInt.ih b/Packets/ParseInt.ih index 70c5859..fd58b04 100644 --- a/Packets/ParseInt.ih +++ b/Packets/ParseInt.ih @@ -71,6 +71,11 @@ namespace impl { Derived const & operator -- () { derived().value( derived.value()-1 ); return derived(); } + Derived const & operator ++ (int) + { Value v (derived.value()); derived().value( v+1 ); return v; } + Derived const & operator -- (int) + { Value v (derived.value()); derived().value( v-1 ); return v; } + private: Derived & derived() { return *static_cast(this); } Derived const & derived() const { return *static_cast(this); }; diff --git a/Packets/ParserBase.cti b/Packets/ParserBase.cti index 5ba7367..084c625 100644 --- a/Packets/ParserBase.cti +++ b/Packets/ParserBase.cti @@ -22,7 +22,7 @@ // Definition of inline template functions -//#include "ParserBase.ih" +#include "ParserBase.ih" // Custom includes diff --git a/Packets/ParserBase.hh b/Packets/ParserBase.hh index 69508b7..cb2ecce 100644 --- a/Packets/ParserBase.hh +++ b/Packets/ParserBase.hh @@ -29,6 +29,7 @@ // Custom includes #include +#include #include #include "ParserBase.ih" @@ -39,7 +40,19 @@ namespace pkf { namespace impl { struct ParserBase; } - struct nil {}; + struct nil + : public boost::iterator_facade + { + // Theese are declared to make nil a valid iterator. All + // access to an instance of this iterator however is invalid + // (these members are not implemented only declared) + char & dereference() const; + bool equal(nil other) const; + void increment(); + void decrement(); + void advance(int n); + int distance_to(nil other) const; + }; /** \brief Parser framework diff --git a/Scheduler/Scheduler.cc b/Scheduler/Scheduler.cc index 21885f2..5e8a860 100644 --- a/Scheduler/Scheduler.cc +++ b/Scheduler/Scheduler.cc @@ -90,7 +90,7 @@ prefix_ satcom::lib::Scheduler::Scheduler() throw SystemException(errno); } -prefix_ void satcom::lib::Scheduler::add(int fd, Callback const & cb, EventId eventMask) +prefix_ void satcom::lib::Scheduler::do_add(int fd, InternalCallback const & cb, EventId eventMask) { FdTable::iterator i (fdTable_.find(fd)); int action (EPOLL_CTL_MOD); @@ -114,7 +114,7 @@ prefix_ void satcom::lib::Scheduler::add(int fd, Callback const & cb, EventId ev throw SystemException(errno); } -prefix_ void satcom::lib::Scheduler::remove(int fd, EventId eventMask) +prefix_ void satcom::lib::Scheduler::do_remove(int fd, EventId eventMask) { FdTable::iterator i (fdTable_.find(fd)); if (i == fdTable_.end()) @@ -171,24 +171,24 @@ prefix_ void satcom::lib::Scheduler::process() if (ev.events & EPOLLIN) { BOOST_ASSERT(spec.cb_read); - spec.cb_read(ev.data.fd, EV_READ); + spec.cb_read(EV_READ); } else if (ev.events & EPOLLPRI) { BOOST_ASSERT(spec.cb_prio); - spec.cb_prio (ev.data.fd, EV_PRIO); + spec.cb_prio(EV_PRIO); } else if (ev.events & EPOLLOUT) { BOOST_ASSERT(spec.cb_write); - spec.cb_write(ev.data.fd, EV_WRITE); + spec.cb_write(EV_WRITE); } else if (ev.events & EPOLLHUP) { BOOST_ASSERT(spec.cb_hup); - spec.cb_hup(ev.data.fd, EV_HUP); + spec.cb_hup(EV_HUP); } else if (ev.events & EPOLLERR) { BOOST_ASSERT(spec.cb_err); - spec.cb_err(ev.data.fd, EV_ERR); + spec.cb_err(EV_ERR); } } } diff --git a/Scheduler/Scheduler.cci b/Scheduler/Scheduler.cci index f34286e..d332654 100644 --- a/Scheduler/Scheduler.cci +++ b/Scheduler/Scheduler.cci @@ -34,6 +34,11 @@ prefix_ void satcom::lib::Scheduler::terminate() terminate_ = true; } +prefix_ int satcom::lib::retrieve_filehandle(int fd) +{ + return fd; +} + ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ diff --git a/Scheduler/Scheduler.cti b/Scheduler/Scheduler.cti index 7ef1148..be41961 100644 --- a/Scheduler/Scheduler.cti +++ b/Scheduler/Scheduler.cti @@ -35,14 +35,15 @@ prefix_ void satcom::lib::Scheduler::add(Handle const & handle, typename GenericCallback::Callback const & cb, EventId eventMask) { - add(retrieve_filehandle(handle),boost::bind(cb,handle,_2),eventMask); + // retrieve_filehandle is found via ADL + do_add(retrieve_filehandle(handle),boost::bind(cb,handle,_1),eventMask); } template prefix_ void satcom::lib::Scheduler::remove(Handle const & handle, EventId eventMask) { // retrieve_filehandle is found via ADL - remove(retrieve_filehandle(handle),eventMask); + do_remove(retrieve_filehandle(handle),eventMask); } ///////////////////////////////cti.e/////////////////////////////////////// diff --git a/Scheduler/Scheduler.hh b/Scheduler/Scheduler.hh index e731db4..8916723 100644 --- a/Scheduler/Scheduler.hh +++ b/Scheduler/Scheduler.hh @@ -59,7 +59,6 @@ namespace lib { typedef boost::function::param_type, EventId) > Callback; }; - typedef GenericCallback::Callback Callback; /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members @@ -76,9 +75,6 @@ namespace lib { ///@} /////////////////////////////////////////////////////////////////////////// - void add(int fd, Callback const & cb, EventId eventMask = EV_ALL); - void remove(int fd, EventId eventMask = EV_ALL); - template void add(Handle const & handle, typename GenericCallback::Callback const & cb, @@ -94,14 +90,19 @@ namespace lib { private: Scheduler(); - - struct EventSpec + + typedef boost::function InternalCallback; + + void do_add(int fd, InternalCallback const & cb, EventId eventMask = EV_ALL); + void do_remove(int fd, EventId eventMask = EV_ALL); + + struct EventSpec { - Callback cb_read; - Callback cb_prio; - Callback cb_write; - Callback cb_hup; - Callback cb_err; + InternalCallback cb_read; + InternalCallback cb_prio; + InternalCallback cb_write; + InternalCallback cb_hup; + InternalCallback cb_err; int epollMask() const; }; @@ -113,6 +114,8 @@ namespace lib { bool terminate_; }; + int retrieve_filehandle(int fd); + }} ///////////////////////////////hh.e////////////////////////////////////////