X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Scheduler%2FScheduler.hh;h=babc1997e4883d56c9c89d6fee7359649b84a9c8;hb=82ad2ed94c12c3e53097fef92978de8c28239fab;hp=12b4b6cf081c8ee69b67d8c588721383eddde5f4;hpb=145f6a7d0f3a6aaa77b3625351c952d24cb0b8a1;p=senf.git diff --git a/Scheduler/Scheduler.hh b/Scheduler/Scheduler.hh index 12b4b6c..babc199 100644 --- a/Scheduler/Scheduler.hh +++ b/Scheduler/Scheduler.hh @@ -33,8 +33,9 @@ #include #include #include - -#include "Utils/MicroTime.hh" +#include +#include "ClockService.hh" +#include "../Utils/Logger/Target.hh" //#include "scheduler.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -74,7 +75,7 @@ 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_ALL=7, @@ -92,6 +93,7 @@ namespace senf { typedef boost::function::param_type, EventId) > Callback; }; + /** \brief Callback type for timer events */ typedef boost::function TimerCallback; @@ -146,12 +148,13 @@ 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 */ + milliseconds */ + + void cancelTimeout(unsigned id); void process(); ///< Event handler main loop /**< This member must be called at some time to enter the @@ -163,6 +166,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: @@ -190,23 +195,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 @@ -218,6 +240,17 @@ namespace senf { */ int retrieve_filehandle(int fd); + /** \brief Scheduler specific time source for Utils/Logger framework + + This time source may be used to provide timing information for log messages within the + Utils/Logger framework. This time source will use Scheduler::eventTime() to provide timing + information. + */ + struct SchedulerLogTimeSource : public senf::log::TimeSource + { + boost::posix_time::ptime operator()() const; + }; + } ///////////////////////////////hh.e////////////////////////////////////////