senf::ClockService::clock_type start (senf::ClockService::now());
run( senf::ClockService::seconds(1));
std::cerr << "\nActiveFeeder: "
- << (sink.size()*1e9)/ (SENF_CLOCKTYPEVAL(senf::ClockService::now()) - SENF_CLOCKTYPEVAL(start))
+ << (sink.size()*1e9)/ (senf::ClockService::now() - start)
<< " packets/s" << std::endl;
BOOST_CHECK( sink.size() > 0);
}
// Custom includes
#include "EventManager.hh"
-#include <senf/Utils/ClockTypeMacros.hh>
-//#include "IntervalTimer.mpp"
#define prefix_
//-/////////////////////////////////////////////////////////////////////////////////////////////////
prefix_ void senf::ppi::IntervalTimer::schedule()
{
- info_.expected = SENF_INT2CLOCKTYPE(SENF_CLOCKTYPEVAL(info_.intervalStart) + ( SENF_CLOCKTYPEVAL(interval_) * (info_.number+1) ) / eventsPerInterval_);
+ info_.expected = info_.intervalStart + ( interval_ * (info_.number+1) ) / eventsPerInterval_;
timer_.timeout(info_.expected);
}
namespace debug = module::debug;
namespace {
- void timeout() {
- senf::scheduler::terminate();
+ void runPPI(senf::ClockService::clock_type t) {
+ senf::scheduler::TimerEvent timeout(
+ "emulatedDvbInterface test timer", &senf::scheduler::terminate, senf::scheduler::now() + t);
+ senf::ppi::run();
}
}
SENF_AUTO_UNIT_TEST(rateFilter)
{
- module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) );
+ module::RateFilter rateFilter ( senf::ClockService::milliseconds(200) );
debug::PassiveSource source;
debug::PassiveSink sink;
for (int i=0; i<10; i++)
source.submit(p);
- senf::scheduler::TimerEvent timer (
- "rateFilter test timer", &timeout,
- senf::ClockService::now() + senf::ClockService::milliseconds(250));
-
- senf::ppi::run();
+ runPPI( senf::ClockService::milliseconds(500));
- BOOST_CHECK_EQUAL( rateFilter.interval(), senf::ClockService::milliseconds(100) );
+ BOOST_CHECK_EQUAL( rateFilter.interval(), senf::ClockService::milliseconds(200) );
BOOST_CHECK_EQUAL( sink.size(), 2u );
}
for (int i=0; i<10; i++)
source.submit(p);
- senf::scheduler::TimerEvent timeoutTimer (
- "rateFilter test timer", &timeout,
- senf::ClockService::now() + senf::ClockService::milliseconds(675));
-
RateFilter_IntervalChanger intervalChanger (rateFilter);
senf::scheduler::TimerEvent timer ( "RateFilter_IntervalChanger timer",
senf::membind(&RateFilter_IntervalChanger::changeInterval, intervalChanger),
senf::ClockService::now() + senf::ClockService::milliseconds(250));
- senf::ppi::run();
+ runPPI( senf::ClockService::milliseconds(675));
BOOST_CHECK_EQUAL( rateFilter.interval(), senf::ClockService::milliseconds(200) );
if (enabled)
// Custom includes
#include <boost/regex.hpp>
#include <senf/Utils/Console/Traits.hh>
-#include <senf/Utils/ClockTypeMacros.hh>
-//#include "ClockService.mpp"
+
#define prefix_
//-/////////////////////////////////////////////////////////////////////////////////////////////////
#include <time.h>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <senf/Utils/Exception.hh>
-#include <senf/Utils/ClockTypeMacros.hh>
#define prefix_ inline
//-/////////////////////////////////////////////////////////////////////////////////////////////////
+#ifdef SENF_DEBUG
+# define SENF_CLOCKTYPEVAL(clock) (clock).value()
+#else
+# define SENF_CLOCKTYPEVAL(clock) (clock)
+#endif
+
//-/////////////////////////////////////////////////////////////////////////////////////////////////
// senf::ClockService
struct timespec spec;
if (clock_gettime(CLOCK_MONOTONIC, &spec) < 0)
SENF_THROW_SYSTEM_EXCEPTION("clock_gettime()");
- return SENF_INT2CLOCKTYPE(spec.tv_sec * 1000000000LL + spec.tv_nsec);
+ return clock_type(spec.tv_sec * 1000000000LL + spec.tv_nsec);
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
if (scheduler::now() - baseClock_ > clock_type(1000000000ll))
restart_m();
#ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
- return baseAbstime_ + boost::posix_time::nanoseconds(clock-baseClock_);
+ return baseAbstime_ + boost::posix_time::nanoseconds(
+ SENF_CLOCKTYPEVAL( clock-baseClock_));
#else
- return baseAbstime_ + boost::posix_time::microseconds((clock.value() - baseClock_.value() + 500 )/1000);
+ return baseAbstime_ + boost::posix_time::microseconds(
+ SENF_CLOCKTYPEVAL( (clock-baseClock_+clock_type(500))/1000));
#endif
}
prefix_ senf::ClockService::reltime_type senf::ClockService::reltime(clock_type clock)
{
#ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
- return boost::posix_time::nanoseconds(clock);
+ return boost::posix_time::nanoseconds(
+ SENF_CLOCKTYPEVAL( clock));
#else
- return boost::posix_time::microseconds((clock.value() + 500)/1000);
+ return boost::posix_time::microseconds(
+ SENF_CLOCKTYPEVAL( (clock + clock_type(500))/1000));
#endif
}
prefix_ senf::ClockService::clock_type senf::ClockService::nanoseconds(int64_type v)
{
- return SENF_INT2CLOCKTYPE(v);
+ return clock_type(v);
}
prefix_ senf::ClockService::clock_type senf::ClockService::microseconds(int64_type v)
{
- return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(nanoseconds(1000)));
+ return v * nanoseconds(1000);
}
prefix_ senf::ClockService::clock_type senf::ClockService::milliseconds(int64_type v)
{
- return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(microseconds(1000)));
+ return v * microseconds(1000);
}
prefix_ senf::ClockService::clock_type senf::ClockService::seconds(int64_type v)
{
- return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(milliseconds(1000)));
+ return v * milliseconds(1000);
}
prefix_ senf::ClockService::clock_type senf::ClockService::minutes(int64_type v)
{
- return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(seconds(60)));
+ return v * seconds(60);
}
prefix_ senf::ClockService::clock_type senf::ClockService::hours(int64_type v)
{
- return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(minutes(60)));
+ return v * minutes(60);
}
prefix_ senf::ClockService::clock_type senf::ClockService::days(int64_type v)
{
- return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(hours(24)));
+ return v * hours(24);
}
prefix_ senf::ClockService::int64_type senf::ClockService::in_nanoseconds(clock_type v)
{
- return SENF_CLOCKTYPEVAL(v);
+ return SENF_CLOCKTYPEVAL( v);
}
prefix_ senf::ClockService::int64_type senf::ClockService::in_microseconds(clock_type v)
{
- return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(nanoseconds(1000)));
+ return SENF_CLOCKTYPEVAL( v / nanoseconds(1000));
}
prefix_ senf::ClockService::int64_type senf::ClockService::in_milliseconds(clock_type v)
{
- return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(microseconds(1000)));
+ return SENF_CLOCKTYPEVAL( v / microseconds(1000));
}
prefix_ senf::ClockService::int64_type senf::ClockService::in_seconds(clock_type v)
{
- return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(milliseconds(1000)));
+ return SENF_CLOCKTYPEVAL( v / milliseconds(1000));
}
prefix_ senf::ClockService::int64_type senf::ClockService::in_minutes(clock_type v)
{
- return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(seconds(60)));
+ return SENF_CLOCKTYPEVAL( v / seconds(60));
}
prefix_ senf::ClockService::int64_type senf::ClockService::in_hours(clock_type v)
{
- return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(minutes(60))) ;
+ return SENF_CLOCKTYPEVAL( v / minutes(60));
}
prefix_ senf::ClockService::int64_type senf::ClockService::in_days(clock_type v)
{
- return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(hours(24))) ;
+ return SENF_CLOCKTYPEVAL( v / hours(24));
}
prefix_ senf::ClockService::clock_type senf::ClockService::from_timeval(timeval const & time)
instance().restart_m();
}
+#undef SENF_CLOCKTYPEVAL
+
//-/////////////////////////////////////////////////////////////////////////////////////////////////
#undef prefix_
This type is used to represent varies supplementary values (e.g. number of microseconds)
*/
-
typedef boost::int_fast64_t int64_type;
/** \brief Absolute time data type
(t1 + senf::ClockService::milliseconds(200))
(senf::ClockService::now())
(senf::ClockService::milliseconds(100)) );
+
+ BOOST_CHECK_EQUAL( senf::ClockService::seconds(1), senf::ClockService::milliseconds(1000) );
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
prefix_ senf::log::time_type senf::scheduler::LogTimeSource::operator()()
const
{
- return SENF_CLOCKTYPEVAL(scheduler::now());
+ return senf::ClockService::in_nanoseconds( scheduler::now());
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
}
prefix_ senf::scheduler::TimerEvent::TimerEvent(std::string const & name, Callback const & cb)
- : detail::FIFORunner::TaskInfo (name), cb_ (cb), timeout_ (SENF_INT2CLOCKTYPE(0))
+ : detail::FIFORunner::TaskInfo (name), cb_ (cb), timeout_(ClockService::clock_type(0))
{}
prefix_ senf::scheduler::TimerEvent::~TimerEvent()
}
unsigned count (0);
- senf::ClockService::clock_type delay (0);
+ senf::ClockService::int64_type delay (0);
bool haveCb (false);
void jitterCb(senf::scheduler::TimerEvent & tm)
{
//std::cerr << "diff:" << senf::ClockService::in_microseconds( senf::scheduler::now() - tm.timeout()) << '\n';
count ++;
- delay += SENF_INT2CLOCKTYPE(senf::ClockService::in_microseconds( senf::scheduler::now() - tm.timeout()));
+ delay += senf::ClockService::in_microseconds( senf::scheduler::now() - tm.timeout());
haveCb = true;
tm.timeout(randomDelay());
}
void jitterTest()
{
count = 0;
- delay = senf::ClockService::clock_type(0);
+ delay = 0;
// senf::scheduler::EventHook pre ("jitterTest::preCb", &preCb,
// senf::scheduler::EventHook::PRE);
// senf::scheduler::EventHook post ("jitterTest::postCb", &postCb,
senf::scheduler::process();
- std::cerr << "Average scheduling delay: " << SENF_CLOCKTYPEVAL(delay)/count << " microseconds\n";
+ std::cerr << "Average scheduling delay: " << delay/count << " microseconds\n";
}
}
: entrySetById( entrySet.template get<Id>()),
entrySetByTimeout( entrySet.template get<Timeout> ()),
timer( "TimerEventProxy " + description,
- membind(&TimerEventProxy<IdType>::timerEvent, this), SENF_INT2CLOCKTYPE(0), false)
+ membind(&TimerEventProxy<IdType>::timerEvent, this), ClockService::clock_type(0), false)
{ }
template<typename IdType>
const
{
typename EntrySetById_t::const_iterator i ( entrySetById.find( id));
- return i == entrySetById.end() ? SENF_INT2CLOCKTYPE(0) : i->timeout;
+ return i == entrySetById.end() ? ClockService::clock_type(0) : i->timeout;
}
timers.add( now + ClockService::milliseconds(200), 1, &handler);
BOOST_CHECK( timers.remove( 4));
BOOST_CHECK(! timers.remove( 4));
- BOOST_CHECK_EQUAL( timers.timeout(4), SENF_INT2CLOCKTYPE(0));
+ BOOST_CHECK_EQUAL( timers.timeout(4), ClockService::clock_type(0));
timers.add( now + ClockService::milliseconds(700), 2, &handler);
BOOST_CHECK_EQUAL( timers.timeout(1), now + ClockService::milliseconds(200));
#include TIMERFD_H_PATH
#endif
#include "senf/Utils/IgnoreValue.hh"
-#include <senf/Utils/ClockTypeMacros.hh>
//#include "TimerSource.mpp"
#define prefix_
{
if (! timeoutEnabled_ || timeout_ != timeout) {
timeout_ = timeout;
- if (SENF_CLOCKTYPEVAL(timeout_) <= 0)
- timeout_ = SENF_INT2CLOCKTYPE(1);
+ if (timeout_ <= ClockService::clock_type(0))
+ timeout_ = ClockService::clock_type(1);
timeoutEnabled_ = true;
reschedule();
}
#ifdef HAVE_TIMERFD_CREATE
prefix_ senf::scheduler::detail::TimerFDTimerSource::TimerFDTimerSource()
- : timerfd_ (-1), timeoutEnabled_ (false), timeout_ (0)
+ : timerfd_ (-1), timeoutEnabled_ (false), timeout_(0)
{
timerfd_ = timerfd_create(CLOCK_MONOTONIC, 0);
if (timerfd_ < 0)
{
if (!timeoutEnabled_ || timeout_ != timeout) {
timeout_ = timeout;
- if (SENF_CLOCKTYPEVAL(timeout_) <= 0)
- timeout_ = SENF_INT2CLOCKTYPE(1);
+ if (timeout_ <= ClockService::clock_type(0))
+ timeout_ = ClockService::clock_type(1);
timeoutEnabled_ = true;
reschedule();
}
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
-#include <senf/Utils/ClockTypeMacros.hh>
//#include "DatagramSocketProtocol.mpp"
#define prefix_
// this may reduce the precision, but we only care about +/- 1ms, for now
struct timeval tv;
::gettimeofday( &tv, NULL);
- return SENF_INT2CLOCKTYPE(tv.tv_sec * 1000000000LL + tv.tv_usec * 1000LL);
+ return ClockService::clock_type(tv.tv_sec * 1000000000LL + tv.tv_usec * 1000LL);
}
// senf::Beeper
prefix_ senf::Beeper::Beeper(std::string const & device)
- : timer_( "senf::Beeper::timer", boost::bind(&Beeper::timeout, this), SENF_INT2CLOCKTYPE(0), false)
+ : timer_( "senf::Beeper::timer", boost::bind(&Beeper::timeout, this), ClockService::clock_type(0), false)
{
if ((fd_ = ::open(device.c_str(), O_WRONLY)) == -1) {
SENF_THROW_SYSTEM_EXCEPTION("Could not open device for Beeper.");
+++ /dev/null
-// $Id: ClockService.hh 1795 2011-07-14 08:42:24Z pba $
-//
-// Copyright (C) 2007
-// Fraunhofer Institute for Open Communication Systems (FOKUS)
-//
-// The contents of this file are subject to the Fraunhofer FOKUS Public License
-// Version 1.0 (the "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-// http://senf.berlios.de/license.html
-//
-// The Fraunhofer FOKUS Public License Version 1.0 is based on,
-// but modifies the Mozilla Public License Version 1.1.
-// See the full license text for the amendments.
-//
-// Software distributed under the License is distributed on an "AS IS" basis,
-// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-// for the specific language governing rights and limitations under the License.
-//
-// The Original Code is Fraunhofer FOKUS code.
-//
-// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
-// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
-// All Rights Reserved.
-//
-// Contributor(s):
-// Philipp Batroff <philipp.batroff@fokus.fraunhofer.de>
-
-
-#ifndef HH_SENF_Utils_CLOCKTYPEMACROS
-#define HH_SENF_Utils_CLOCKTYPEMACROS_1
-
-
-#ifdef SENF_DEBUG
-#define SENF_INT2CLOCKTYPE(clock) \
- senf::ClockService::clock_type(clock)
-
-#define SENF_CLOCKTYPEVAL(clock) \
- clock.value()
-#endif
-
-#ifndef SENF_DEBUG
-#define SENF_INT2CLOCKTYPE(clock) \
- (clock)
-#define SENF_CLOCKTYPEVAL(clock) \
- (clock)
-#endif
-
-#endif // CLOCKTYPEMACROS_HH
-
-
-// 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:
SENF_AUTO_UNIT_TEST(ipChecksum)
{
- char data[] = { 0x45, 0x00, 0x00, 0x28, 0x49, 0x44, 0x40, 0x00,
+ unsigned char data[] = { 0x45, 0x00, 0x00, 0x28, 0x49, 0x44, 0x40, 0x00,
0x40, 0x06, 0x00, 0x00, 0x0a, 0xc1, 0x01, 0x06,
0xc2, 0x9f, 0xa4, 0xc3 };
timeFormat_ = format;
if (format.empty()) {
noformat_ = true;
- timeBase_ = SENF_CLOCKTYPEVAL(ClockService::now());
+ timeBase_ = senf::ClockService::in_nanoseconds( ClockService::now());
} else {
noformat_ = false;
std::locale const & loc (datestream_.getloc());
<< std::setw(9) << (delta % 1000000000ll);
}
else
- datestream_ << senf::ClockService::abstime(SENF_INT2CLOCKTYPE(timestamp));
+ datestream_ << senf::ClockService::abstime( senf::ClockService::nanoseconds(timestamp));
datestream_ << ' ';
}
if (!tag_.empty())
prefix_ senf::log::time_type senf::log::SystemTimeSource::operator()()
const
{
- return SENF_CLOCKTYPEVAL(senf::ClockService::now());
+ return senf::ClockService::in_nanoseconds( senf::ClockService::now());
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
bool boolean_test() const
{ return value_; }
- RestrictedInt<Base, Tag> operator*(int i) const
- { return RestrictedInt<Base, Tag>(value_ * i); }
-
- RestrictedInt<Base, Tag> operator/(int i) const
- { return RestrictedInt<Base, Tag>(value_ / i); }
-
- bool operator>(int i) const
- { return value_ > i; }
-
- bool operator>=(int i) const
- { return value_ >= i; }
+ private:
+ Base value_;
+ };
- bool operator<(int i) const
- { return value_ < i; }
- bool operator<=(int i) const
- { return value_ <= i; }
+ template <class Base, class Tag, typename OtherType>
+ RestrictedInt<Base, Tag> operator*(OtherType a, RestrictedInt<Base,Tag> b)
+ {
+ return RestrictedInt<Base, Tag>( a * b.value());
+ }
- bool operator==(int i) const
- { return value_ == i; }
+ template <class Base, class Tag, typename OtherType>
+ RestrictedInt<Base, Tag> operator*(RestrictedInt<Base,Tag> a, OtherType b)
+ {
+ return RestrictedInt<Base, Tag>( a.value() * b);
+ }
- bool operator!=(int i) const
- { return value_ != i; }
+ template <class Base, class Tag, typename OtherType>
+ RestrictedInt<Base, Tag> operator/(OtherType a, RestrictedInt<Base,Tag> b)
+ {
+ return RestrictedInt<Base, Tag>( a / b.value());
+ }
- private:
- Base value_;
- };
+ template <class Base, class Tag, typename OtherType>
+ RestrictedInt<Base, Tag> operator/(RestrictedInt<Base,Tag> a, OtherType b)
+ {
+ return RestrictedInt<Base, Tag>( a.value() / b);
+ }
template <class Base, class Tag>
std::ostream & operator<<(std::ostream & os, RestrictedInt<Base, Tag> value)
- { os << value.value(); return os; }
+ {
+ os << value.value();
+ return os;
+ }
template <class Base, class Tag>
std::istream & operator>>(std::istream & is, RestrictedInt<Base, Tag> & value)
- { Base v; is >> v; value = RestrictedInt<Base,Tag>(v); return is; }
+ {
+ Base v; is >> v; value = RestrictedInt<Base,Tag>(v);
+ return is;
+ }
}