X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Scheduler%2FScheduler.hh;h=a54bed8444ff949e0702d3bfc05eca6aa3bf8c9f;hb=331547d2a137f796eb5fcb390502aece3e01bb16;hp=8916723181261819df9eb2e84d03feb1003216b3;hpb=1835b928b179302ecb716d697fbf3fa24b415ba4;p=senf.git diff --git a/Scheduler/Scheduler.hh b/Scheduler/Scheduler.hh index 8916723..a54bed8 100644 --- a/Scheduler/Scheduler.hh +++ b/Scheduler/Scheduler.hh @@ -20,20 +20,30 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// TODO: Fix EventId parameter (probably to int) to allow |-ing without casting ... + + +/** \mainpage The SENF Scheduler library + + */ + #ifndef HH_Scheduler_ #define HH_Scheduler_ 1 // Custom includes #include +#include #include #include #include +#include "Utils/MicroTime.hh" + //#include "scheduler.mpp" ///////////////////////////////hh.p//////////////////////////////////////// -namespace satcom { -namespace lib { +/** \brief SENF Project namespace */ +namespace senf { /** \brief Singleton class to manage the event loop @@ -59,6 +69,8 @@ namespace lib { typedef boost::function::param_type, EventId) > Callback; }; + typedef boost::function SimpleCallback; + typedef boost::function TimerCallback; /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members @@ -78,45 +90,59 @@ namespace lib { template void add(Handle const & handle, typename GenericCallback::Callback const & cb, - EventId eventMask = EV_ALL); - template - void remove(Handle const & handle, EventId eventMask = EV_ALL); + int eventMask = EV_ALL); + template + void remove(Handle const & handle, int eventMask = EV_ALL); - void process(); + void timeout(unsigned long timeout, TimerCallback const & cb); + void process(); void terminate(); protected: private: Scheduler(); - - 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); - + + void do_add(int fd, SimpleCallback const & cb, int eventMask = EV_ALL); + void do_remove(int fd, int eventMask = EV_ALL); + struct EventSpec { - InternalCallback cb_read; - InternalCallback cb_prio; - InternalCallback cb_write; - InternalCallback cb_hup; - InternalCallback cb_err; + SimpleCallback cb_read; + SimpleCallback cb_prio; + SimpleCallback cb_write; + SimpleCallback cb_hup; + SimpleCallback cb_err; int epollMask() const; }; + + struct TimerSpec + { + TimerSpec() : timeout(), cb() {} + TimerSpec(unsigned long long timeout_, TimerCallback cb_) + : timeout(timeout_), cb(cb_) {} + + bool operator< (TimerSpec const & other) const + { return timeout > other.timeout; } + + unsigned long long timeout; + TimerCallback cb; + }; typedef std::map FdTable; + typedef std::priority_queue TimerQueue; FdTable fdTable_; + TimerQueue timerQueue_; int epollFd_; bool terminate_; }; int retrieve_filehandle(int fd); -}} +} ///////////////////////////////hh.e//////////////////////////////////////// #include "Scheduler.cci" @@ -127,5 +153,5 @@ namespace lib { // Local Variables: // mode: c++ -// c-file-style: "satcom" +// c-file-style: "senf" // End: