From: g0dil Date: Fri, 17 Aug 2007 12:44:29 +0000 (+0000) Subject: PPI: Implement PassiveQueue X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=be4cb7d4887e2db2ef5d76aeb7a6f0ef895d555b;p=senf.git PPI: Implement PassiveQueue git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@396 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/PassiveQueue.cc b/PPI/PassiveQueue.cc new file mode 100644 index 0000000..4005760 --- /dev/null +++ b/PPI/PassiveQueue.cc @@ -0,0 +1,72 @@ +// $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 PassiveQueue non-inline non-template implementation */ + +#include "PassiveQueue.hh" +//#include "PassiveQueue.ih" + +// Custom includes + +//#include "PassiveQueue.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PassiveQueue + +//////////////////////////////////////// +// private members + +prefix_ void senf::ppi::module::PassiveQueue::init() +{ + output.throttle(); +} + +prefix_ void senf::ppi::module::PassiveQueue::onInput() +{ + output.unthrottle(); +} + +prefix_ void senf::ppi::module::PassiveQueue::onOutput() +{ + if (input) + output(input()); + if (!input) + output.throttle(); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ +//#include "PassiveQueue.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/PPI/PassiveQueue.cci b/PPI/PassiveQueue.cci new file mode 100644 index 0000000..c419486 --- /dev/null +++ b/PPI/PassiveQueue.cci @@ -0,0 +1,53 @@ +// $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 PassiveQueue inline non-template implementation */ + +// Custom includes + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PassiveQueue + +prefix_ senf::ppi::module::PassiveQueue::PassiveQueue() +{ + route(input,output); + input.onRequest(&PassiveQueue::onInput); + output.onRequest(&PassiveQueue::onOutput); +} + +///////////////////////////////cci.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/PassiveQueue.cti b/PPI/PassiveQueue.cti new file mode 100644 index 0000000..a3e2522 --- /dev/null +++ b/PPI/PassiveQueue.cti @@ -0,0 +1,54 @@ +// $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 PassiveQueue inline template implementation */ + +//#include "PassiveQueue.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PassiveQueue + +template +prefix_ void senf::ppi::module::PassiveQueue::qdisc(QDiscipline const & disc) +{ + input.qdisc(disc); +} + +///////////////////////////////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/PassiveQueue.hh b/PPI/PassiveQueue.hh index 0d07b50..9e6c6e0 100644 --- a/PPI/PassiveQueue.hh +++ b/PPI/PassiveQueue.hh @@ -25,6 +25,9 @@ #define HH_PassiveQueue_ 1 // Custom includes +#include "Connectors.hh" +#include "Module.hh" +#include "predecl.hh" //#include "PassiveQueue.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -44,26 +47,36 @@ namespace module { forward throttling notifications are sent out whenever the queue is empty. */ class PassiveQueue + : public module::Module { + SENF_PPI_MODULE(PassiveQueue); public: connector::PassiveInput input; connector::PassiveOutput output; PassiveQueue(); - void qdisc(QueueingDiscipline const & disc); ///< Change the queueing discipline - /**< This call changes the queueing discipline of the queue. This call is just forwarded to - the \a input connector. - - \see connector::PassiveInput::qdisc() */ + template + void qdisc(QDiscipline const & disc); ///< Change the queueing discipline + /**< This call changes the queueing discipline of the + queue. This call is just forwarded to the \a input + connector. + + \see connector::PassiveInput::qdisc() */ + + private: + void init(); + + void onInput(); + void onOutput(); }; }}} ///////////////////////////////hh.e//////////////////////////////////////// -//#include "PassiveQueue.cci" +#include "PassiveQueue.cci" //#include "PassiveQueue.ct" -//#include "PassiveQueue.cti" +#include "PassiveQueue.cti" #endif diff --git a/PPI/PassiveQueue.test.cc b/PPI/PassiveQueue.test.cc new file mode 100644 index 0000000..3c5c66f --- /dev/null +++ b/PPI/PassiveQueue.test.cc @@ -0,0 +1,80 @@ +// $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 PassiveQueue.test unit tests */ + +//#include "PassiveQueue.test.hh" +//#include "PassiveQueue.test.ih" + +// Custom includes +#include "PassiveQueue.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(passiveQueue) +{ + debug::ActivePacketSource source; + module::PassiveQueue queue; + debug::ActivePacketSink sink; + + ppi::connect(source,queue); + ppi::connect(queue,sink); + ppi::init(); + + senf::Packet p (senf::DataPacket::create()); + + BOOST_CHECK( ! sink ); + source.submit(p); + BOOST_CHECK( sink ); + BOOST_CHECK( ! source ); + BOOST_CHECK_EQUAL( queue.input.queueSize(), 1u ); + BOOST_CHECK( sink.request() == p ); + BOOST_CHECK( source ); + 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: