From: g0dil Date: Mon, 23 Mar 2009 14:32:13 +0000 (+0000) Subject: PPI: Add priority argument to PriorityJoin connect() X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=160f4413563be5515d5c1d2884b06bc9807ea6dd;p=senf.git PPI: Add priority argument to PriorityJoin connect() git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1166 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/Joins.cc b/PPI/Joins.cc index 71428c6..b8ce2d6 100644 --- a/PPI/Joins.cc +++ b/PPI/Joins.cc @@ -80,10 +80,19 @@ prefix_ void senf::ppi::module::PassiveJoin::onUnthrottle() //////////////////////////////////////// // private members -prefix_ senf::ppi::connector::ActiveInput<> & senf::ppi::module::PriorityJoin::newInput() +prefix_ senf::ppi::connector::ActiveInput<> & +senf::ppi::module::PriorityJoin::newInput(int priority) { - inputs_.push_back(new connector::ActiveInput<>()); - connector::ActiveInput<> & input (inputs_.back()); + if (priority > int(inputs_.size())) + priority = inputs_.size(); + else if (priority < 0) { + priority = inputs_.size() + priority + 1; + if (priority < 0) + priority = 0; + } + + connector::ActiveInput<> & input ( + *inputs_.insert(inputs_.begin()+priority, new connector::ActiveInput<>())); noroute(input); input.onThrottle(&PriorityJoin::onThrottle); diff --git a/PPI/Joins.cti b/PPI/Joins.cti index b2dedda..1e77d16 100644 --- a/PPI/Joins.cti +++ b/PPI/Joins.cti @@ -48,9 +48,9 @@ senf::ppi::module::PassiveJoin::connect(Source & source) template prefix_ senf::ppi::connector::GenericActiveInput & -senf::ppi::module::PriorityJoin::connect(Source & source) +senf::ppi::module::PriorityJoin::connect(Source & source, int priority) { - connector::GenericActiveInput & input (newInput()); + connector::GenericActiveInput & input (newInput(priority)); ppi::connect(source,input); return input; } @@ -61,17 +61,17 @@ senf::ppi::module::PriorityJoin::connect(Source & source) #ifndef DOXYGEN template -prefix_ senf::ppi::connector::GenericPassiveInput & senf::ppi::connect(Source & source, - module::PassiveJoin & target) +prefix_ senf::ppi::connector::GenericPassiveInput & +senf::ppi::connect(Source & source, module::PassiveJoin & target) { return target.connect(source); } template -prefix_ senf::ppi::connector::GenericActiveInput & senf::ppi::connect(Source & source, - module::PriorityJoin & target) +prefix_ senf::ppi::connector::GenericActiveInput & +senf::ppi::connect(Source & source, module::PriorityJoin & target, int priority) { - return target.connect(source); + return target.connect(source, priority); } #endif diff --git a/PPI/Joins.hh b/PPI/Joins.hh index 266e807..8960551 100644 --- a/PPI/Joins.hh +++ b/PPI/Joins.hh @@ -44,7 +44,8 @@ namespace ppi { connector::GenericPassiveInput & connect(Source & source, module::PassiveJoin & target); template - connector::GenericActiveInput & connect(Source & source, module::PriorityJoin & target); + connector::GenericActiveInput & connect(Source & source, module::PriorityJoin & target, + int priority = -1); #endif @@ -133,13 +134,13 @@ namespace module { PriorityJoin(); private: - connector::ActiveInput<> & newInput(); + connector::ActiveInput<> & newInput(int priority); #ifndef DOXYGEN public: #endif template - connector::GenericActiveInput & connect(Source & source); + connector::GenericActiveInput & connect(Source & source, int prioricty); private: void request(); diff --git a/PPI/Joins.test.cc b/PPI/Joins.test.cc index 7e14488..44e9759 100644 --- a/PPI/Joins.test.cc +++ b/PPI/Joins.test.cc @@ -106,6 +106,25 @@ BOOST_AUTO_UNIT_TEST(priorityJoin) BOOST_CHECK( sink.request() == p1 ); BOOST_CHECK( sink.request() == p2 ); BOOST_CHECK( ! sink ); + + debug::PassiveSource source3; + debug::PassiveSource source4; + ppi::connect(source3, join, 0); + ppi::connect(source4, join, -2); + // Ordering now: source3, source1, source4, source2 + + senf::Packet p3 (senf::DataPacket::create()); + senf::Packet p4 (senf::DataPacket::create()); + + source4.submit(p4); + source3.submit(p3); + source2.submit(p2); + source1.submit(p1); + BOOST_CHECK( sink.request() == p3 ); + BOOST_CHECK( sink.request() == p1 ); + BOOST_CHECK( sink.request() == p4 ); + BOOST_CHECK( sink.request() == p2 ); + BOOST_CHECK( ! sink ); } ///////////////////////////////cc.e////////////////////////////////////////