Restructure internal Scheduler callback representation
g0dil [Mon, 6 Nov 2006 11:53:26 +0000 (11:53 +0000)]
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

Packets/ParseInt.ih
Packets/ParserBase.cti
Packets/ParserBase.hh
Scheduler/Scheduler.cc
Scheduler/Scheduler.cci
Scheduler/Scheduler.cti
Scheduler/Scheduler.hh

index 70c5859..fd58b04 100644 (file)
@@ -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<Derived *>(this); }
         Derived const & derived() const { return *static_cast<Derived const *>(this); };
index 5ba7367..084c625 100644 (file)
@@ -22,7 +22,7 @@
 
 // Definition of inline template functions
 
-//#include "ParserBase.ih"
+#include "ParserBase.ih"
 
 // Custom includes
 
index 69508b7..cb2ecce 100644 (file)
@@ -29,6 +29,7 @@
 
 // Custom includes
 #include <utility>
+#include <boost/iterator/iterator_facade.hpp>
 #include <boost/type_traits/is_member_function_pointer.hpp>
 
 #include "ParserBase.ih"
@@ -39,7 +40,19 @@ namespace pkf {
     
     namespace impl { struct ParserBase; }
 
-    struct nil {};
+    struct nil 
+       : public boost::iterator_facade<nil,char,boost::random_access_traversal_tag>
+    {
+       // 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
 
index 21885f2..5e8a860 100644 (file)
@@ -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);
         }
     }
 }
index f34286e..d332654 100644 (file)
@@ -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_
 
index 7ef1148..be41961 100644 (file)
@@ -35,14 +35,15 @@ prefix_ void satcom::lib::Scheduler::add(Handle const & handle,
                                          typename GenericCallback<Handle>::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 <class Handle>
 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///////////////////////////////////////
index e731db4..8916723 100644 (file)
@@ -59,7 +59,6 @@ namespace lib {
             typedef boost::function<void (typename boost::call_traits<Handle>::param_type,
                                           EventId) > Callback;
         };
-        typedef GenericCallback<int>::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 <class Handle>
         void add(Handle const & handle, 
                  typename GenericCallback<Handle>::Callback const & cb,
@@ -94,14 +90,19 @@ namespace lib {
 
     private:
         Scheduler();
-
-        struct EventSpec 
+       typedef boost::function<void (EventId)> 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////////////////////////////////////////