X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Scheduler%2FScheduler.hh;h=a3e1295db7d4d7c65480a5ef35d2d75e74c907aa;hb=ffa36b2d409289a2f3f0de46667aa2bf558f393f;hp=aac4671a62c5aa8b69045d638f6c28e9fc2b6d1f;hpb=98f3f38c5872d26fcf544a9d28efe0518e3895e2;p=senf.git diff --git a/Scheduler/Scheduler.hh b/Scheduler/Scheduler.hh index aac4671..a3e1295 100644 --- a/Scheduler/Scheduler.hh +++ b/Scheduler/Scheduler.hh @@ -33,8 +33,8 @@ #include #include #include - -#include "Utils/MicroTime.hh" +#include +#include "ClockService.hh" //#include "scheduler.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -74,10 +74,11 @@ namespace senf { /////////////////////////////////////////////////////////////////////////// // Types - /// \brief Types of file descriptor events */ + /** \brief Types of file descriptor events */ enum EventId { EV_NONE=0, - EV_READ=1, EV_PRIO=2, EV_WRITE=4, EV_HUP=8, EV_ERR=16, - EV_ALL=31 }; + EV_READ=1, EV_PRIO=2, EV_WRITE=4, + EV_ALL=7, + EV_HUP=8, EV_ERR=16 }; /** \brief Template typedef for Callback type @@ -91,6 +92,7 @@ namespace senf { typedef boost::function::param_type, EventId) > Callback; }; + /** \brief Callback type for timer events */ typedef boost::function TimerCallback; @@ -128,7 +130,7 @@ namespace senf { callback will be called for the given type of event on the given arbitrary file-descriptor or handle-like object. If there already is a Callback - register ed for one of the events requested, the new + registered for one of the events requested, the new handler will replace the old one. \param[in] handle file descriptor or handle providing the Handle interface defined above. @@ -145,13 +147,16 @@ namespace senf { \param[in] eventMask arbitrary combination via '|' operator of EventId designators. */ - void timeout(unsigned long timeout, TimerCallback const & cb); ///< Add timeout event - /**< \param[in] timeout timeout in milliseconds + unsigned timeout(ClockService::clock_type timeout, TimerCallback const & cb); + ///< Add timeout event + /**< \param[in] timeout timeout in nanoseconds \param[in] cb callback to call after \a timeout milliseconds \todo Return some kind of handle/pointer and add support to update or revoke a timeout */ + void cancelTimeout(unsigned id); + void process(); ///< Event handler main loop /**< This member must be called at some time to enter the event handler main loop. Only while this function is @@ -162,6 +167,8 @@ namespace senf { main loop to terminate. The main loop will return to it's caller after the currently running callback returns. */ + + ClockService::clock_type eventTime() const; ///< Return date/time of last event protected: @@ -180,8 +187,6 @@ namespace senf { SimpleCallback cb_read; SimpleCallback cb_prio; SimpleCallback cb_write; - SimpleCallback cb_hup; - SimpleCallback cb_err; int epollMask() const; }; @@ -191,23 +196,40 @@ namespace senf { struct TimerSpec { TimerSpec() : timeout(), cb() {} - TimerSpec(unsigned long long timeout_, TimerCallback cb_) - : timeout(timeout_), cb(cb_) {} + TimerSpec(ClockService::clock_type timeout_, TimerCallback cb_, unsigned id_) + : timeout(timeout_), cb(cb_), id(id_), canceled(false) {} bool operator< (TimerSpec const & other) const { return timeout > other.timeout; } - unsigned long long timeout; + ClockService::clock_type timeout; TimerCallback cb; + unsigned id; + bool canceled; }; typedef std::map FdTable; - typedef std::priority_queue TimerQueue; + typedef std::map TimerMap; // sorted by id + + struct TimerSpecCompare + { + typedef TimerMap::iterator first_argument_type; + typedef TimerMap::iterator second_argument_type; + typedef bool result_type; + + result_type operator()(first_argument_type a, second_argument_type b); + }; + + typedef std::priority_queue, + TimerSpecCompare> TimerQueue; // sorted by time FdTable fdTable_; + unsigned timerIdCounter_; TimerQueue timerQueue_; + TimerMap timerMap_; int epollFd_; bool terminate_; + ClockService::clock_type eventTime_; }; /** \brief Default file descriptor accessor @@ -234,4 +256,6 @@ namespace senf { // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: