From: g0dil Date: Wed, 4 Nov 2009 09:11:44 +0000 (+0000) Subject: PPI: BUGFIX: Add missing connectorDestroy() calls in MultiConnectorMixin X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=f221429e5f88f5543393d546babd958db4b5977c;p=senf.git PPI: BUGFIX: Add missing connectorDestroy() calls in MultiConnectorMixin git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1514 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/PPI/MultiConnectorMixin.ct b/senf/PPI/MultiConnectorMixin.ct index 78ae255..fc01c1a 100644 --- a/senf/PPI/MultiConnectorMixin.ct +++ b/senf/PPI/MultiConnectorMixin.ct @@ -43,8 +43,10 @@ disconnected(ConnectorType_ const & c) typename ContainerType::iterator i ( find_if(connectors_.begin(), connectors_.end(), boost::bind(&ContainerType_::value_type::second,_1) == &c)); - if (i != connectors_.end()) + if (i != connectors_.end()) { + static_cast(this)->connectorDestroy(c); connectors_.erase(i); + } } /////////////////////////////////////////////////////////////////////////// @@ -59,8 +61,10 @@ disconnected(ConnectorType_ const & c) typename ContainerType::iterator i ( find_if(connectors_.begin(), connectors_.end(), &_1 == &c)); - if (i != connectors_.end()) + if (i != connectors_.end()) { + static_cast(this)->connectorDestroy(c); connectors_.erase(i); + } } ///////////////////////////////ct.e//////////////////////////////////////// diff --git a/senf/PPI/MultiConnectorMixin.test.cc b/senf/PPI/MultiConnectorMixin.test.cc index b4d307e..841dac1 100644 --- a/senf/PPI/MultiConnectorMixin.test.cc +++ b/senf/PPI/MultiConnectorMixin.test.cc @@ -40,23 +40,62 @@ namespace module = ppi::module; namespace debug = module::debug; namespace { - // We only test the user-collection case, all other cases are already handled by - // existing modules + + // Primitive join + class SequenceContainerModule + : public module::Module, + public module::MultiConnectorMixin > + { + SENF_PPI_MODULE(SequenceContainerModule); + typedef module::MultiConnectorMixin > base; + + public: + connector::ActiveOutput<> output; + + using base::connectors; + + SequenceContainerModule() : count (0u) + { + noroute(output); + } + + unsigned count; + + private: + void connectorSetup(connector::PassiveInput<> & c) + { + route(c, output); + c.onRequest(boost::bind(&SequenceContainerModule::request, this, boost::ref(c))); + ++ count; + } + + void connectorDestroy(connector::PassiveInput<> const & c) + { + -- count; + } + + void request(connector::PassiveInput<> & c) + { + output(c()); + } + + friend class module::MultiConnectorMixin >; + }; // Primitive duplicator - class MyModule + class UserContainerModule : public module::Module, - public module::MultiConnectorMixin, void, void> + public module::MultiConnectorMixin, void, void> { - SENF_PPI_MODULE(MyModule); - typedef std::vector< boost::shared_ptr > Connectors; + SENF_PPI_MODULE(UserContainerModule); + typedef std::vector< boost::shared_ptr > Connectors; public: connector::PassiveInput<> input; - MyModule() + UserContainerModule() { noroute(input); - input.onRequest(&MyModule::request); + input.onRequest(&UserContainerModule::request); } Connectors const & connectors() const @@ -88,7 +127,7 @@ namespace { Connectors connectors_; - friend class module::MultiConnectorMixin, void, void>; + friend class module::MultiConnectorMixin, void, void>; }; struct IntAnnotation { @@ -102,10 +141,38 @@ namespace { { os << value.value; return os; } } +BOOST_AUTO_UNIT_TEST(multiConnectorMixin_sequenceContainer) +{ + debug::ActiveSource source1; + debug::ActiveSource source2; + SequenceContainerModule module; + debug::PassiveSink sink; + + ppi::connect(source1, module); + ppi::connect(source2, module); + ppi::connect(module, sink); + ppi::init(); + + senf::Packet p (senf::DataPacket::create()); + + source1.submit(p); + BOOST_CHECK_EQUAL( sink.size(), 1u ); + BOOST_CHECK( sink.pop_front() == p ); + source2.submit(p); + BOOST_CHECK_EQUAL( sink.size(), 1u ); + BOOST_CHECK( sink.pop_front() == p ); + + BOOST_CHECK_EQUAL( module.connectors().size(), 2u ); + BOOST_CHECK_EQUAL( module.count, 2u ); + source1.output.disconnect(); + BOOST_CHECK_EQUAL( module.connectors().size(), 1u ); + BOOST_CHECK_EQUAL( module.count, 1u ); +} + BOOST_AUTO_UNIT_TEST(multiConnectorMixin_userContainer) { debug::ActiveSource source; - MyModule module; + UserContainerModule module; debug::PassiveSink sink1; debug::PassiveSink sink2; @@ -134,7 +201,7 @@ BOOST_AUTO_UNIT_TEST(multiConnectorMixin_multipleModules) module::PassiveJoin join1; module::PassiveJoin join2; module::AnnotationRouter router; - MyModule module; + UserContainerModule module; ppi::connect(source, join1); ppi::connect(join1, router);