Skip to content
Snippets Groups Projects
Commit 9c36a341 authored by tho's avatar tho
Browse files

PPI/Ratefilter: added interval setter and unit tests

Utils/Console: doc: added example for adding an overloaded member method to the console
parent 55ffaf9d
No related branches found
No related tags found
No related merge requests found
// $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_
......
// $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;
......
// $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:
......@@ -39,9 +39,7 @@
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
namespace ppi = senf::ppi;
namespace connector = ppi::connector;
namespace module = ppi::module;
namespace debug = module::debug;
......
......@@ -39,9 +39,7 @@
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
namespace ppi = senf::ppi;
namespace connector = ppi::connector;
namespace module = ppi::module;
namespace debug = module::debug;
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment