From: g0dil Date: Fri, 17 Aug 2007 20:19:41 +0000 (+0000) Subject: PPI: Implement joins X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=914af680a37d303da51e3877972ca9bd68d6190b;p=senf.git PPI: Implement joins Packets: Silence PacketRegistry warnings with final=1 Utils: Remove MicroTime Scheduler: Sart implementing more reliable timing mechanism git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@397 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/Connectors.cci b/PPI/Connectors.cci index 1f3f192..5dcb08e 100644 --- a/PPI/Connectors.cci +++ b/PPI/Connectors.cci @@ -60,6 +60,7 @@ prefix_ senf::ppi::connector::Connector::~Connector() prefix_ void senf::ppi::connector::Connector::connect(Connector & target) { + BOOST_ASSERT( ! peer_ && ! target.peer_ ); peer_ = & target; target.peer_ = this; } @@ -89,9 +90,10 @@ prefix_ bool senf::ppi::connector::PassiveConnector::nativeThrottled() prefix_ void senf::ppi::connector::PassiveConnector::throttle() { - if (!throttled()) + if (!throttled()) { + nativeThrottled_ = true; emitThrottle(); - nativeThrottled_ = true; + } } prefix_ void senf::ppi::connector::PassiveConnector::unthrottle() diff --git a/PPI/Joins.cc b/PPI/Joins.cc new file mode 100644 index 0000000..4be6c97 --- /dev/null +++ b/PPI/Joins.cc @@ -0,0 +1,130 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief Joins non-inline non-template implementation */ + +#include "Joins.hh" +//#include "Joins.ih" + +// Custom includes +#include +#include +#include +#include + +//#include "Joins.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PassiveJoin + +//////////////////////////////////////// +// private members + +prefix_ senf::ppi::connector::PassiveInput & senf::ppi::module::PassiveJoin::newInput() +{ + inputs_.push_back(new connector::PassiveInput()); + connector::PassiveInput & input (inputs_.back()); + + noroute(input); + input.onRequest(boost::bind(&PassiveJoin::request,this,boost::ref(input))); + + return input; +} + +prefix_ void senf::ppi::module::PassiveJoin::request(connector::PassiveInput & input) +{ + output(input()); +} + +prefix_ void senf::ppi::module::PassiveJoin::onThrottle() +{ + using boost::lambda::_1; + using boost::lambda::bind; + std::for_each(inputs_.begin(), inputs_.end(), + bind(&connector::PassiveInput::throttle, _1)); +} + +prefix_ void senf::ppi::module::PassiveJoin::onUnthrottle() +{ + using boost::lambda::_1; + using boost::lambda::bind; + std::for_each(inputs_.begin(), inputs_.end(), + bind(&connector::PassiveInput::unthrottle, _1)); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PriorityJoin + +//////////////////////////////////////// +// private members + +prefix_ senf::ppi::connector::ActiveInput & senf::ppi::module::PriorityJoin::newInput() +{ + inputs_.push_back(new connector::ActiveInput()); + connector::ActiveInput & input (inputs_.back()); + + noroute(input); + input.onThrottle(&PriorityJoin::onThrottle); + input.onUnthrottle(&PriorityJoin::onUnthrottle); + + return input; +} + +prefix_ void senf::ppi::module::PriorityJoin::request() +{ + using boost::lambda::_1; + using boost::lambda::bind; + Inputs::iterator i (std::find_if(inputs_.begin(), inputs_.end(), + ! bind(&connector::ActiveInput::throttled, _1))); + if (i != inputs_.end()) + output((*i)()); +} + +prefix_ void senf::ppi::module::PriorityJoin::onThrottle() +{ + if (std::find_if(inputs_.begin(), inputs_.end(), + ! bind(&connector::ActiveInput::throttled, _1)) == inputs_.end()) + output.throttle(); +} + +prefix_ void senf::ppi::module::PriorityJoin::onUnthrottle() +{ + output.unthrottle(); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ +//#include "Joins.mpp" + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/Utils/MicroTime.cc b/PPI/Joins.cci similarity index 52% rename from Utils/MicroTime.cc rename to PPI/Joins.cci index 4a19fdf..00c7c9a 100644 --- a/Utils/MicroTime.cc +++ b/PPI/Joins.cci @@ -1,6 +1,9 @@ // $Id$ // -// Copyright (C) 2006 Stefan Bund +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -18,42 +21,42 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief MicroTime non-inline non-template implementation */ - -#include "MicroTime.hh" -//#include "MicroTime.ih" + \brief Joins inline non-template implementation */ // Custom includes -#include -#include -#include -#include "Utils/Exception.hh" +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// -//#include "MicroTime.mpp" -#define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PassiveJoin -prefix_ senf::MicroTime senf::now() +prefix_ senf::ppi::module::PassiveJoin::PassiveJoin() { - struct timeval tv; - if (gettimeofday(&tv,0) < 0) - throw SystemException(errno); - return 1000000*MicroTime(tv.tv_sec) + tv.tv_usec; + noroute(output); + output.onThrottle(&PassiveJoin::onThrottle); + output.onUnthrottle(&PassiveJoin::onUnthrottle); } +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PriorityJoin + +prefix_ senf::ppi::module::PriorityJoin::PriorityJoin() +{ + noroute(output); + output.onRequest(&PriorityJoin::request); +} -///////////////////////////////cc.e//////////////////////////////////////// +///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ -//#include "MicroTime.mpp" // Local Variables: // mode: c++ // fill-column: 100 +// comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" -// comment-column: 40 // End: diff --git a/PPI/Joins.cti b/PPI/Joins.cti new file mode 100644 index 0000000..e100b08 --- /dev/null +++ b/PPI/Joins.cti @@ -0,0 +1,87 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief Joins inline template implementation */ + +//#include "Joins.ih" + +// Custom includes +#include "Setup.hh" + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PassiveJoin + +template +prefix_ senf::ppi::connector::PassiveInput & +senf::ppi::module::PassiveJoin::connect(Source & source) +{ + connector::PassiveInput & input (newInput()); + ppi::connect(source,input); + return input; +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PriorityJoin + +template +prefix_ senf::ppi::connector::ActiveInput & +senf::ppi::module::PriorityJoin::connect(Source & source) +{ + connector::ActiveInput & input (newInput()); + ppi::connect(source,input); + return input; +} + +/////////////////////////////////////////////////////////////////////////// +// namespace members + +template +prefix_ senf::ppi::connector::PassiveInput & senf::ppi::connect(Source & source, + module::PassiveJoin & target) +{ + return target.connect(source); +} + +template +prefix_ senf::ppi::connector::ActiveInput & senf::ppi::connect(Source & source, + module::PriorityJoin & target) +{ + return target.connect(source); +} + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/PPI/Joins.hh b/PPI/Joins.hh new file mode 100644 index 0000000..7276384 --- /dev/null +++ b/PPI/Joins.hh @@ -0,0 +1,112 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief Joins public header */ + +#ifndef HH_Joins_ +#define HH_Joins_ 1 + +// Custom includes +#include +#include "predecl.hh" +#include "Connectors.hh" +#include "Module.hh" + +//#include "Joins.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { +namespace ppi { + + template + connector::PassiveInput & connect(Source & source, module::PassiveJoin & target); + + template + connector::ActiveInput & connect(Source & source, module::PriorityJoin & target); + +namespace module { + + class PassiveJoin + : public Module + { + SENF_PPI_MODULE(PassiveJoin); + public: + connector::ActiveOutput output; + + PassiveJoin(); + + template + connector::PassiveInput & connect(Source & source); + + private: + connector::PassiveInput & newInput(); + + void request(connector::PassiveInput & input); + void onThrottle(); + void onUnthrottle(); + + typedef boost::ptr_vector Inputs; + Inputs inputs_; + }; + + class PriorityJoin + : public Module + { + SENF_PPI_MODULE(PriorityJoin); + public: + connector::PassiveOutput output; + + PriorityJoin(); + + template + connector::ActiveInput & connect(Source & source); + + private: + connector::ActiveInput & newInput(); + + void request(); + void onThrottle(); + void onUnthrottle(); + + typedef boost::ptr_vector Inputs; + Inputs inputs_; + }; + +}}} + +///////////////////////////////hh.e//////////////////////////////////////// +#include "Joins.cci" +//#include "Joins.ct" +#include "Joins.cti" +#endif + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/PPI/Joins.test.cc b/PPI/Joins.test.cc new file mode 100644 index 0000000..8e336bb --- /dev/null +++ b/PPI/Joins.test.cc @@ -0,0 +1,123 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief Joins.test unit tests */ + +//#include "Joins.test.hh" +//#include "Joins.test.ih" + +// Custom includes +#include "Joins.hh" +#include "DebugModules.hh" +#include "Setup.hh" +#include "Packets/Packets.hh" + +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +namespace ppi = senf::ppi; +namespace connector = ppi::connector; +namespace module = ppi::module; +namespace debug = module::debug; + +BOOST_AUTO_UNIT_TEST(passiveJoin) +{ + debug::ActivePacketSource source1; + debug::ActivePacketSource source2; + module::PassiveJoin join; + debug::PassivePacketSink sink; + + ppi::connect(source1, join); + ppi::connect(source2, join); + ppi::connect(join, sink); + ppi::init(); + + senf::Packet p (senf::DataPacket::create()); + + source1.submit(p); + BOOST_CHECK_EQUAL( sink.size(), 1u ); + source2.submit(p); + BOOST_CHECK_EQUAL( sink.size(), 2u ); + + sink.input.throttle(); + BOOST_CHECK( ! source1 ); + BOOST_CHECK( ! source2 ); + + source1.submit(p); + source2.submit(p); + BOOST_CHECK_EQUAL( sink.size(), 2u ); + sink.input.unthrottle(); + BOOST_CHECK_EQUAL( sink.size(), 4u ); +} + +BOOST_AUTO_UNIT_TEST(priorityJoin) +{ + debug::PassivePacketSource source1; + debug::PassivePacketSource source2; + module::PriorityJoin join; + debug::ActivePacketSink sink; + + ppi::connect(source1, join); + ppi::connect(source2, join); + ppi::connect(join,sink); + ppi::init(); + + BOOST_CHECK( ! sink ); + + senf::Packet p1 (senf::DataPacket::create()); + senf::Packet p2 (senf::DataPacket::create()); + + source1.submit(p1); + BOOST_CHECK( sink ); + source2.submit(p2); + BOOST_CHECK( sink ); + BOOST_CHECK( sink.request() == p1 ); + BOOST_CHECK( sink ); + BOOST_CHECK( sink.request() == p2 ); + BOOST_CHECK( ! sink ); + + source1.submit(p1); + source2.submit(p2); + source1.submit(p1); + BOOST_CHECK( sink.request() == p1 ); + BOOST_CHECK( sink.request() == p1 ); + BOOST_CHECK( sink.request() == p2 ); + BOOST_CHECK( ! sink ); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/PPI/SocketReader.test.cc b/PPI/SocketReader.test.cc index 8a28946..b17d6bc 100644 --- a/PPI/SocketReader.test.cc +++ b/PPI/SocketReader.test.cc @@ -64,7 +64,7 @@ BOOST_AUTO_UNIT_TEST(socketReader) senf::UDPv4ClientSocketHandle outputSocket; outputSocket.writeto(senf::INet4SocketAddress("localhost:44344"),data); - senf::Scheduler::instance().timeout(100, &timeout); + senf::Scheduler::instance().timeout(100000, &timeout); senf::ppi::run(); BOOST_REQUIRE( ! sink.empty() ); diff --git a/PPI/SocketWriter.test.cc b/PPI/SocketWriter.test.cc index 25c1a5d..64687ef 100644 --- a/PPI/SocketWriter.test.cc +++ b/PPI/SocketWriter.test.cc @@ -84,7 +84,7 @@ BOOST_AUTO_UNIT_TEST(activeSocketWriter) senf::UDPv4ClientSocketHandle inputSocket; inputSocket.bind(senf::INet4SocketAddress("localhost:44344")); - senf::Scheduler::instance().timeout(100, &timeout); + senf::Scheduler::instance().timeout(100000, &timeout); source.submit(p); senf::ppi::run(); diff --git a/PPI/predecl.hh b/PPI/predecl.hh index 2b8f6ea..49eae2b 100644 --- a/PPI/predecl.hh +++ b/PPI/predecl.hh @@ -64,6 +64,8 @@ namespace ppi { namespace detail { template class RouteHelper; } + class PassiveJoin; + class PriorityJoin; } namespace connector { diff --git a/Packets/PacketRegistry.ct b/Packets/PacketRegistry.ct index 2147023..a0bf61c 100644 --- a/Packets/PacketRegistry.ct +++ b/Packets/PacketRegistry.ct @@ -42,6 +42,10 @@ template template prefix_ void senf::detail::PacketRegistryImpl::registerPacket(key_t key) { +#ifdef NDEBUG + registry_.insert(std::make_pair(key, Entry_ptr(new detail::PkReg_EntryImpl()))); + reverseRegistry_.insert(std::make_pair(senf::typeIdValue(), key)); +#else bool isUnique ( registry_.insert( std::make_pair(key, Entry_ptr(new detail::PkReg_EntryImpl()))).second); @@ -52,6 +56,7 @@ prefix_ void senf::detail::PacketRegistryImpl::registerPacket(key_t key std::make_pair(senf::typeIdValue(), key)).second); // If this assertion fails, the same Packet was registered with two different keys BOOST_ASSERT( isNew ); +#endif } template diff --git a/Scheduler/Scheduler.cc b/Scheduler/Scheduler.cc index ed6649d..799c4a5 100644 --- a/Scheduler/Scheduler.cc +++ b/Scheduler/Scheduler.cc @@ -79,7 +79,6 @@ #include #include #include "Utils/Exception.hh" -#include "Utils/MicroTime.hh" static const int EPollInitialSize = 16; @@ -92,13 +91,14 @@ prefix_ senf::Scheduler::Scheduler & senf::Scheduler::instance() return instance; } -prefix_ void senf::Scheduler::timeout(unsigned long timeout, TimerCallback const & cb) +prefix_ void senf::Scheduler::timeout(sched_time timeout, TimerCallback const & cb) { - timerQueue_.push(TimerSpec(now()+1000*timeout,cb)); + timerQueue_.push(TimerSpec(now()+timeout,cb)); } prefix_ senf::Scheduler::Scheduler() - : epollFd_(epoll_create(EPollInitialSize)) + : epollFd_ (epoll_create(EPollInitialSize)), + epoch_ (boost::posix_time::microsec_clock::universal_time()) { if (epollFd_<0) throw SystemException(errno); @@ -166,20 +166,27 @@ prefix_ void senf::Scheduler::process() { terminate_ = false; while (! terminate_) { + sched_time timeNow = now(); - MicroTime timeNow = now(); while ( ! timerQueue_.empty() && timerQueue_.top().timeout <= timeNow ) { timerQueue_.top().cb(); timerQueue_.pop(); } + if (terminate_) return; - int timeout = timerQueue_.empty() ? -1 : int((timerQueue_.top().timeout - timeNow)/1000); + + int timeout (MinTimeout); + if (! timerQueue_.empty()) { + sched_time delta ((timerQueue_.top().timeout - timeNow)/1000000UL); + if (deltasecond); unsigned extraFlags (0); diff --git a/Scheduler/Scheduler.cci b/Scheduler/Scheduler.cci index 2308705..1c1e7ef 100644 --- a/Scheduler/Scheduler.cci +++ b/Scheduler/Scheduler.cci @@ -36,6 +36,15 @@ prefix_ void senf::Scheduler::terminate() terminate_ = true; } +prefix_ senf::Scheduler::sched_time senf::Scheduler::now() + const +{ + boost::posix_time::time_duration delta ( + boost::posix_time::microsec_clock::universal_time() - epoch_); + return sched_time( delta.ticks() ) + * sched_time( 1000000000UL / boost::posix_time::time_duration::ticks_per_second() ); +} + prefix_ int senf::retrieve_filehandle(int fd) { return fd; diff --git a/Scheduler/Scheduler.hh b/Scheduler/Scheduler.hh index 12b4b6c..ba077e4 100644 --- a/Scheduler/Scheduler.hh +++ b/Scheduler/Scheduler.hh @@ -33,8 +33,8 @@ #include #include #include - -#include "Utils/MicroTime.hh" +#include +#include //#include "scheduler.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -74,7 +74,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 +92,20 @@ namespace senf { typedef boost::function::param_type, EventId) > Callback; }; + + /** \brief Scheduler time data type + + Unsigned integer type representing scheduler time. Scheduler time is measured in + nanoseconds relative to some implementation defined reference time. + */ + typedef boost::uint_fast64_t sched_time; + + /** \brief Absolute time data type + + Boost.DateTime datatype used to represent absolute date/time values. + */ + typedef boost::posix_time::ptime abs_time; + /** \brief Callback type for timer events */ typedef boost::function TimerCallback; @@ -146,8 +160,8 @@ 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 + void timeout(sched_time 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 @@ -163,12 +177,34 @@ namespace senf { main loop to terminate. The main loop will return to it's caller after the currently running callback returns. */ + + abs_time abstime(sched_time time) const; ///< Convert scheduler time to absolute time + /**< This member converts a scheduler time value into an + absolute Boost.DateTime value. + \note You should not base timeout calculations on this + absolute time value. Scheduler time is guaranteed + to be monotonous, absolute time may be + non-monotonous if the system date/time is + changed. */ + + sched_time schedtime(abs_time time) const; ///< Convert absolute time to scheduler time + /**< This member converst an absolute time value into the + corresponding scheduler time. + \see abstime */ + + sched_time now() const; ///< Return current date/time + /**< The return value represents the current date/time in + scheduler time representation */ + + sched_time eventTime() const; ///< Return date/time of last event protected: private: typedef boost::function SimpleCallback; + static unsigned const MinTimeout = 1000; + Scheduler(); void do_add(int fd, SimpleCallback const & cb, int eventMask = EV_ALL); @@ -190,13 +226,13 @@ namespace senf { struct TimerSpec { TimerSpec() : timeout(), cb() {} - TimerSpec(unsigned long long timeout_, TimerCallback cb_) + TimerSpec(sched_time timeout_, TimerCallback cb_) : timeout(timeout_), cb(cb_) {} bool operator< (TimerSpec const & other) const { return timeout > other.timeout; } - unsigned long long timeout; + sched_time timeout; TimerCallback cb; }; @@ -207,6 +243,7 @@ namespace senf { TimerQueue timerQueue_; int epollFd_; bool terminate_; + abs_time epoch_; }; /** \brief Default file descriptor accessor diff --git a/Scheduler/Scheduler.test.cc b/Scheduler/Scheduler.test.cc index f0055a5..2521b4a 100644 --- a/Scheduler/Scheduler.test.cc +++ b/Scheduler/Scheduler.test.cc @@ -184,9 +184,9 @@ namespace { callback(handle.fd_,event); } - bool is_close(MicroTime a, MicroTime b) + bool is_close(Scheduler::sched_time a, Scheduler::sched_time b) { - return (a -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -/** \file - \brief MicroTime public header */ - -/** \defgroup time Microseconds Time - - MicroTime provides extremely rudimentary support for a time data - type precise to 10-6 seconds. Up to now, the only - supported members are the datatype (which just uses a 64 bit - integer) and the now() function to get the current UTC time in - microseconds since the Epoch. - - \idea This thing only exists as a quick hack. We can probably make - use of Boost.Time or some such thing so it probably does not - make sense to extend this further. We should however check the - performance of Boost.Time since this is used heavily in the - Scheduler. - */ - -#ifndef HH_MicroTime_ -#define HH_MicroTime_ 1 - -// Custom includes -#include - -//#include "MicroTime.mpp" -///////////////////////////////hh.p//////////////////////////////////////// - -namespace senf { - - /// \addtogroup time - /// @{ - - typedef boost::uint64_t MicroTime; ///< Microsecond accurent time datatype - - MicroTime now(); ///< Get current UTC time with microsecond accuracy - - /// @} - -} - -///////////////////////////////hh.e//////////////////////////////////////// -//#include "MicroTime.cci" -//#include "MicroTime.ct" -//#include "MicroTime.cti" -//#include "MicroTime.mpp" -#endif - - -// Local Variables: -// mode: c++ -// fill-column: 100 -// c-file-style: "senf" -// indent-tabs-mode: nil -// ispell-local-dictionary: "american" -// compile-command: "scons -u test" -// comment-column: 40 -// End: diff --git a/Utils/MicroTime.test.cc b/Utils/MicroTime.test.cc deleted file mode 100644 index fe9e183..0000000 --- a/Utils/MicroTime.test.cc +++ /dev/null @@ -1,51 +0,0 @@ -// $Id$ -// -// Copyright (C) 2006 Stefan Bund -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -// Unit tests - -//#include "MicroTime.test.hh" -//#include "MicroTime.test.ih" - -// Custom includes -#include "MicroTime.hh" - -#include -#include - -#define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// - -BOOST_AUTO_UNIT_TEST(microTime) -{ - BOOST_CHECK_NO_THROW( senf::now() ); -} - -///////////////////////////////cc.e//////////////////////////////////////// -#undef prefix_ - - -// Local Variables: -// mode: c++ -// fill-column: 100 -// c-file-style: "senf" -// indent-tabs-mode: nil -// ispell-local-dictionary: "american" -// compile-command: "scons -u test" -// comment-column: 40 -// End: