diff --git a/PPI/RateFilter.cc b/PPI/RateFilter.cc index c9b4793be95e14a8f85762d6390139caa4704844..953bba715975805878a41b1e4d7adf036a4628ad 100644 --- a/PPI/RateFilter.cc +++ b/PPI/RateFilter.cc @@ -1,3 +1,5 @@ +// $Id$ +// // Copyright (C) 2007 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY @@ -49,13 +51,11 @@ senf::ClockService::clock_type senf::ppi::module::RateFilter::interval() return timer_.interval().first; } - -/* this should be what should happen. but _this_ most likely won't work -void senf::ppi::module::RateFilter::changeInterval(senf::ClockService::clock_type interval) +void senf::ppi::module::RateFilter::interval(senf::ClockService::clock_type interval) { - //timer = ppi::IntervalTimer(interval); + timer_.interval(interval); } -*/ + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ diff --git a/PPI/RateFilter.hh b/PPI/RateFilter.hh index 9877124b38cd03f9a2258d27b251fbe2a3f6d342..dca0fbdec8551c32dc5e0daf665bb4e941746d0b 100644 --- a/PPI/RateFilter.hh +++ b/PPI/RateFilter.hh @@ -1,3 +1,5 @@ +// $Id$ +// // Copyright (C) 2007 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY @@ -43,7 +45,7 @@ class RateFilter public: RateFilter(senf::ClockService::clock_type interval); -// void changeInterval(senf::ClockService::clock_type interval); not yet implemented! + void interval(senf::ClockService::clock_type interval); senf::ClockService::clock_type interval() const; connector::ActiveInput<> input; diff --git a/PPI/RateFilter.test.cc b/PPI/RateFilter.test.cc new file mode 100644 index 0000000000000000000000000000000000000000..22a5a1c3ddd1e4ee3daf9d0233eb6c1470c2d438 --- /dev/null +++ b/PPI/RateFilter.test.cc @@ -0,0 +1,122 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Thorsten Horstmann <tho@berlios.de> +// +// 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 RateFilter unit tests */ + +// Custom includes +#include "RateFilter.hh" +#include "DebugModules.hh" +#include "Setup.hh" +#include "../Utils/membind.hh" + +#include "../Utils/auto_unit_test.hh" +#include <boost/test/test_tools.hpp> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// +namespace ppi = senf::ppi; +namespace module = ppi::module; +namespace debug = module::debug; + +namespace { + void timeout() { + senf::scheduler::terminate(); + } +} + +BOOST_AUTO_UNIT_TEST(rateFilter) +{ + module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) ); + debug::PassiveSource source; + debug::PassiveSink sink; + + ppi::connect(source, rateFilter); + ppi::connect(rateFilter, sink); + + std::string data ("TEST"); + senf::Packet p (senf::DataPacket::create(data)); + 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(); + + BOOST_CHECK_EQUAL( sink.size(), 2); +} + +namespace { + // just a helper class for the test + struct RateFilter_IntervalChanger { + module::RateFilter & rateFilter_; + RateFilter_IntervalChanger( module::RateFilter & rateFilter) + : rateFilter_( rateFilter) {}; + void changeInterval() { + rateFilter_.interval( senf::ClockService::milliseconds(200)); + } + }; +} + +BOOST_AUTO_UNIT_TEST(rateFilter_changeInterval) +{ + module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) ); + debug::PassiveSource source; + debug::PassiveSink sink; + + ppi::connect(source, rateFilter); + ppi::connect(rateFilter, sink); + + std::string data ("TEST"); + senf::Packet p (senf::DataPacket::create(data)); + 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(); + + BOOST_CHECK_EQUAL( sink.size(), 4); +} + +///////////////////////////////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/SocketSink.test.cc b/PPI/SocketSink.test.cc index 3cd3651cba0ef270de3e09d863379aa0f84e42e9..5b7f420ec67de23312a6bb7809782976173e6373 100644 --- a/PPI/SocketSink.test.cc +++ b/PPI/SocketSink.test.cc @@ -39,9 +39,7 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// - namespace ppi = senf::ppi; -namespace connector = ppi::connector; namespace module = ppi::module; namespace debug = module::debug; diff --git a/PPI/SocketSource.test.cc b/PPI/SocketSource.test.cc index f922db89baee98482d1cc7c1ce0d4331aac81c86..c8947a1ecc5638048d796c0bcad56fd1a6ef7e71 100644 --- a/PPI/SocketSource.test.cc +++ b/PPI/SocketSource.test.cc @@ -39,9 +39,7 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// - namespace ppi = senf::ppi; -namespace connector = ppi::connector; namespace module = ppi::module; namespace debug = module::debug; diff --git a/Utils/Console/Mainpage.dox b/Utils/Console/Mainpage.dox index eb39f764b9d3a86d5e6071b5ed2fe68712ede8fc..16e73761f9ab03d1f987adec02b8209adb1f5e92 100644 --- a/Utils/Console/Mainpage.dox +++ b/Utils/Console/Mainpage.dox @@ -779,6 +779,20 @@ .add("over", static_cast<void (*)(int)>(&over)); senf::console::root() .add("over", static_cast<void (*)(int,int)>(&over)); + + class SomeModule { + senf::console::ScopedDirectory<SomeModule> dir; + + unsigned int overlodedMethod() const {....}; + void overlodedMethod(unsigned int) {....}; + + void addConsoleCommands() { + dir.node().add("overlodedMethod", senf::membind( + static_cast<unsigned int (SomeModule::*)() const>(&SomeModule::overlodedMethod), this)); + dir.node().add("overlodedMethod", senf::membind( + static_cast<void (SomeModule::*)(unsigned int)>(&SomeModule::overlodedMethod), this)); + } + } \endcode