From: g0dil Date: Mon, 20 Jul 2009 16:10:16 +0000 (+0000) Subject: PPI: Implement Jack reset() capability X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=af1d0936ba912bb301ac6604965df5b28d79c63e;p=senf.git PPI: Implement Jack reset() capability git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1274 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/Jack.cci b/PPI/Jack.cci index 9ae3da5..f40a3e9 100644 --- a/PPI/Jack.cci +++ b/PPI/Jack.cci @@ -33,46 +33,87 @@ prefix_ senf::ppi::connector::GenericActiveInputJack:: GenericActiveInputJack(GenericActiveInput & input) - : input_ (input) + : input_ (&input) {} prefix_ senf::ppi::connector::GenericActiveInput & senf::ppi::connector::GenericActiveInputJack::connector() { - return input_; + return *input_; +} + +prefix_ void senf::ppi::connector::GenericActiveInputJack::reset(GenericActiveInput & input) +{ + if (input_->connected()) { + GenericPassiveOutput & peer (input_->peer()); + input_->disconnect(); + connect(peer, input); + } + input_ = & input; } prefix_ senf::ppi::connector::GenericActiveOutputJack:: GenericActiveOutputJack(GenericActiveOutput & output) - : output_ (output) + : output_ (&output) {} prefix_ senf::ppi::connector::GenericActiveOutput & senf::ppi::connector::GenericActiveOutputJack::connector() { - return output_; + return *output_; +} + +prefix_ void senf::ppi::connector::GenericActiveOutputJack::reset(GenericActiveOutput & output) +{ + if (output_->connected()) { + GenericPassiveInput & peer (output_->peer()); + output_->disconnect(); + connect(output, peer); + } + output_ = & output; } prefix_ senf::ppi::connector::GenericPassiveInputJack:: GenericPassiveInputJack(GenericPassiveInput & input) - : input_ (input) + : input_ (&input) {} prefix_ senf::ppi::connector::GenericPassiveInput & senf::ppi::connector::GenericPassiveInputJack::connector() { - return input_; + return *input_; +} + +prefix_ void senf::ppi::connector::GenericPassiveInputJack::reset(GenericPassiveInput & input) +{ + if (input_->connected()) { + GenericActiveOutput & peer (input_->peer()); + input_->disconnect(); + connect(peer, input); + } + input_ = & input; } prefix_ senf::ppi::connector::GenericPassiveOutputJack:: GenericPassiveOutputJack(GenericPassiveOutput & output) - : output_ (output) + : output_ (&output) {} prefix_ senf::ppi::connector::GenericPassiveOutput & senf::ppi::connector::GenericPassiveOutputJack::connector() { - return output_; + return *output_; +} + +prefix_ void +senf::ppi::connector::GenericPassiveOutputJack::reset(GenericPassiveOutput & output) +{ + if (output_->connected()) { + GenericActiveInput & peer (output_->peer()); + output_->disconnect(); + connect(output, peer); + } + output_ = & output; } prefix_ senf::ppi::connector::ActiveInputJack:: @@ -85,6 +126,16 @@ ActiveInputJack(GenericActiveInputJack input) : GenericActiveInputJack (input.connector()) {} +prefix_ void senf::ppi::connector::ActiveInputJack::reset(GenericActiveInput & input) +{ + GenericActiveInputJack::reset(input); +} + +prefix_ void senf::ppi::connector::ActiveInputJack::reset(GenericActiveInputJack input) +{ + GenericActiveInputJack::reset(input.connector()); +} + prefix_ senf::ppi::connector::ActiveOutputJack:: ActiveOutputJack(GenericActiveOutput & output) : GenericActiveOutputJack (output) @@ -95,6 +146,17 @@ ActiveOutputJack(GenericActiveOutputJack & output) : GenericActiveOutputJack (output.connector()) {} +prefix_ void senf::ppi::connector::ActiveOutputJack::reset(GenericActiveOutput & output) +{ + GenericActiveOutputJack::reset(output); +} + +prefix_ void +senf::ppi::connector::ActiveOutputJack::reset(GenericActiveOutputJack & output) +{ + GenericActiveOutputJack::reset(output.connector()); +} + prefix_ senf::ppi::connector::PassiveInputJack:: PassiveInputJack(GenericPassiveInput & input) : GenericPassiveInputJack (input) @@ -105,6 +167,17 @@ PassiveInputJack(GenericPassiveInputJack & input) : GenericPassiveInputJack (input.connector()) {} +prefix_ void senf::ppi::connector::PassiveInputJack::reset(GenericPassiveInput & input) +{ + GenericPassiveInputJack::reset(input); +} + +prefix_ void +senf::ppi::connector::PassiveInputJack::reset(GenericPassiveInputJack & input) +{ + GenericPassiveInputJack::reset(input.connector()); +} + prefix_ senf::ppi::connector::PassiveOutputJack:: PassiveOutputJack(GenericPassiveOutput & output) : GenericPassiveOutputJack (output) @@ -115,6 +188,18 @@ PassiveOutputJack(GenericPassiveOutputJack & output) : GenericPassiveOutputJack (output.connector()) {} +prefix_ void +senf::ppi::connector::PassiveOutputJack::reset(GenericPassiveOutput & output) +{ + GenericPassiveOutputJack::reset(output); +} + +prefix_ void +senf::ppi::connector::PassiveOutputJack::reset(GenericPassiveOutputJack & output) +{ + GenericPassiveOutputJack::reset(output.connector()); +} + prefix_ void senf::ppi::connect(connector::GenericActiveOutputJack & source, connector::GenericPassiveInputJack & target) { diff --git a/PPI/Jack.cti b/PPI/Jack.cti index 30a4c64..bdd3eca 100644 --- a/PPI/Jack.cti +++ b/PPI/Jack.cti @@ -56,6 +56,31 @@ senf::ppi::connector::ActiveInputJack::ActiveInputJack(ActiveInputJa {} template +prefix_ void +senf::ppi::connector::ActiveInputJack::reset(ActiveInput & input) +{ + GenericActiveInputJack::reset(input); +} + +template +prefix_ void senf::ppi::connector::ActiveInputJack::reset(ActiveInput<> & input) +{ + GenericActiveInputJack::reset(input); +} + +template +prefix_ void senf::ppi::connector::ActiveInputJack::reset(ActiveInputJack & input) +{ + GenericActiveInputJack::reset(input); +} + +template +prefix_ void senf::ppi::connector::ActiveInputJack::reset(ActiveInputJack<> & input) +{ + GenericActiveInputJack::reset(input); +} + +template prefix_ senf::ppi::connector::ActiveOutputJack:: ActiveOutputJack(ActiveOutput & output) : GenericActiveOutputJack (output) @@ -80,6 +105,33 @@ ActiveOutputJack(ActiveOutputJack<> & output) {} template +prefix_ void +senf::ppi::connector::ActiveOutputJack::reset(ActiveOutput & output) +{ + GenericActiveOutputJack::reset(output); +} + +template +prefix_ void senf::ppi::connector::ActiveOutputJack::reset(ActiveOutput<> & output) +{ + GenericActiveOutputJack::reset(output); +} + +template +prefix_ void +senf::ppi::connector::ActiveOutputJack::reset(ActiveOutputJack & output) +{ + GenericActiveOutputJack::reset(output); +} + +template +prefix_ void +senf::ppi::connector::ActiveOutputJack::reset(ActiveOutputJack<> & output) +{ + GenericActiveOutputJack::reset(output); +} + +template prefix_ senf::ppi::connector::PassiveInputJack:: PassiveInputJack(PassiveInput & input) : GenericPassiveInputJack (input) @@ -104,6 +156,32 @@ PassiveInputJack(PassiveInputJack<> & input) {} template +prefix_ void +senf::ppi::connector::PassiveInputJack::reset(PassiveInput & input) +{ + GenericPassiveInputJack::reset(input); +} + +template +prefix_ void senf::ppi::connector::PassiveInputJack::reset(PassiveInput<> & input) +{ + GenericPassiveInputJack::reset(input); +} + +template +prefix_ void senf::ppi::connector::PassiveInputJack::reset(PassiveInputJack & input) +{ + GenericPassiveInputJack::reset(input); +} + +template +prefix_ void +senf::ppi::connector::PassiveInputJack::reset(PassiveInputJack<> & input) +{ + GenericPassiveInputJack::reset(input); +} + +template prefix_ senf::ppi::connector::PassiveOutputJack:: PassiveOutputJack(PassiveOutput & output) : GenericPassiveOutputJack (output) @@ -127,6 +205,34 @@ PassiveOutputJack(PassiveOutputJack<> & output) : GenericPassiveOutputJack (output.connector()) {} +template +prefix_ void +senf::ppi::connector::PassiveOutputJack::reset(PassiveOutput & output) +{ + GenericPassiveOutputJack::reset(output); +} + +template +prefix_ void +senf::ppi::connector::PassiveOutputJack::reset(PassiveOutput<> & output) +{ + GenericPassiveOutputJack::reset(output); +} + +template +prefix_ void +senf::ppi::connector::PassiveOutputJack::reset(PassiveOutputJack & output) +{ + GenericPassiveOutputJack::reset(output); +} + +template +prefix_ void +senf::ppi::connector::PassiveOutputJack::reset(PassiveOutputJack<> & output) +{ + GenericPassiveOutputJack::reset(output); +} + template prefix_ void senf::ppi::connect(connector::GenericActiveOutputJack & source, T & target, diff --git a/PPI/Jack.hh b/PPI/Jack.hh index a47d15d..9d57186 100644 --- a/PPI/Jack.hh +++ b/PPI/Jack.hh @@ -55,8 +55,11 @@ namespace connector { GenericActiveInput & connector(); ///< Get referenced connector + void reset(GenericActiveInput & input); ///< Change connector + /**< Will update any existing connection accordingly */ + private: - GenericActiveInput & input_; + GenericActiveInput * input_; }; /** \brief Jack referencing an ActiveOutput @@ -69,8 +72,11 @@ namespace connector { GenericActiveOutput & connector(); ///< Get referenced connector + void reset(GenericActiveOutput & output); ///< Change connector + /**< Will update any existing connection accordingly */ + private: - GenericActiveOutput & output_; + GenericActiveOutput * output_; }; /** \brief Jack referencing a PassiveInput @@ -83,8 +89,11 @@ namespace connector { GenericPassiveInput & connector(); ///< Get referenced connector + void reset(GenericPassiveInput & input); ///< Change connector + /**< Will update any existing connection accordingly */ + private: - GenericPassiveInput & input_; + GenericPassiveInput * input_; }; /** \brief Jack referencing a PassiveOutput @@ -97,8 +106,11 @@ namespace connector { GenericPassiveOutput & connector(); ///< Get referenced connector + void reset(GenericPassiveOutput & output); ///< Change connector + /**< Will update any existing connection accordingly */ + private: - GenericPassiveOutput & output_; + GenericPassiveOutput * output_; }; /** \brief Jack with packet type referencing an ActiveInput @@ -113,6 +125,12 @@ namespace connector { explicit ActiveInputJack(ActiveInputJack & input); explicit ActiveInputJack(ActiveInputJack<> & input); + + void reset(ActiveInput & input); + void reset(ActiveInput<> & input); + + void reset(ActiveInputJack & input); + void reset(ActiveInputJack<> & input); }; #ifndef DOXYGEN @@ -124,6 +142,9 @@ namespace connector { public: explicit ActiveInputJack(GenericActiveInput & input); explicit ActiveInputJack(GenericActiveInputJack input); + + void reset(GenericActiveInput & input); + void reset(GenericActiveInputJack input); }; #endif @@ -140,6 +161,12 @@ namespace connector { explicit ActiveOutputJack(ActiveOutputJack & output); explicit ActiveOutputJack(ActiveOutputJack<> & output); + + void reset(ActiveOutput & output); + void reset(ActiveOutput<> & output); + + void reset(ActiveOutputJack & output); + void reset(ActiveOutputJack<> & output); }; #ifndef DOXYGEN @@ -151,6 +178,9 @@ namespace connector { public: explicit ActiveOutputJack(GenericActiveOutput & output); explicit ActiveOutputJack(GenericActiveOutputJack & output); + + void reset(GenericActiveOutput & output); + void reset(GenericActiveOutputJack & output); }; #endif @@ -167,6 +197,12 @@ namespace connector { explicit PassiveInputJack(PassiveInputJack & input); explicit PassiveInputJack(PassiveInputJack<> & input); + + void reset(PassiveInput & input); + void reset(PassiveInput<> & input); + + void reset(PassiveInputJack & input); + void reset(PassiveInputJack<> & input); }; #ifndef DOXYGEN @@ -178,6 +214,9 @@ namespace connector { public: explicit PassiveInputJack(GenericPassiveInput & input); explicit PassiveInputJack(GenericPassiveInputJack & input); + + void reset(GenericPassiveInput & input); + void reset(GenericPassiveInputJack & input); }; #endif @@ -194,6 +233,12 @@ namespace connector { explicit PassiveOutputJack(PassiveOutputJack & output); explicit PassiveOutputJack(PassiveOutputJack<> & output); + + void reset(PassiveOutput & output); + void reset(PassiveOutput<> & output); + + void reset(PassiveOutputJack & output); + void reset(PassiveOutputJack<> & output); }; #ifndef DOXYGEN @@ -205,6 +250,9 @@ namespace connector { public: explicit PassiveOutputJack(GenericPassiveOutput & output); explicit PassiveOutputJack(GenericPassiveOutputJack & output); + + void reset(GenericPassiveOutput & output); + void reset(GenericPassiveOutputJack & output); }; #endif diff --git a/PPI/Jack.test.cc b/PPI/Jack.test.cc index 10a20e3..bc6b0c1 100644 --- a/PPI/Jack.test.cc +++ b/PPI/Jack.test.cc @@ -45,12 +45,14 @@ namespace { senf::ppi::connector::ActiveInput<> input; senf::ppi::connector::PassiveOutput<> output; - ActiveDummyForward() + ActiveDummyForward() : n (0) { route(input, output); output.onRequest(&ActiveDummyForward::request); } + unsigned n; + private: void request() - { output(input()); } + { ++n; output(input()); } }; class PassiveDummyForward @@ -61,38 +63,50 @@ namespace { senf::ppi::connector::PassiveInput<> input; senf::ppi::connector::ActiveOutput<> output; - PassiveDummyForward() + PassiveDummyForward() : n (0) { route(input, output); input.onRequest(&PassiveDummyForward::request); } + unsigned n; + private: void request() - { output(input()); } + { ++n; output(input()); } }; - class ActiveGroup + struct ActiveGroup { - public: senf::ppi::connector::ActiveInputJack<> input; senf::ppi::connector::PassiveOutputJack<> output; ActiveGroup() - : input (forward.input), output (forward.output) {} + : input (forward1.input), output (forward1.output) {} - private: - ActiveDummyForward forward; + void flip() + { + input.reset(forward2.input); + output.reset(forward2.output); + } + + ActiveDummyForward forward1; + ActiveDummyForward forward2; }; - class PassiveGroup + struct PassiveGroup { - public: senf::ppi::connector::PassiveInputJack<> input; senf::ppi::connector::ActiveOutputJack<> output; PassiveGroup() - : input (forward.input), output (forward.output) {} + : input (forward1.input), output (forward1.output) {} - private: - PassiveDummyForward forward; + void flip() + { + input.reset(forward2.input); + output.reset(forward2.output); + } + + PassiveDummyForward forward1; + PassiveDummyForward forward2; }; } @@ -109,10 +123,25 @@ BOOST_AUTO_UNIT_TEST(jacks) senf::ppi::init(); - senf::Packet p (senf::DataPacket::create()); - source.submit(p); + { + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + + BOOST_CHECK(p == sink.request()); + } + + group.flip(); + senf::ppi::init(); - BOOST_CHECK(p == sink.request()); + { + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + + BOOST_CHECK(p == sink.request()); + } + + BOOST_CHECK_EQUAL( group.forward1.n, 1u ); + BOOST_CHECK_EQUAL( group.forward2.n, 1u ); } { @@ -125,10 +154,25 @@ BOOST_AUTO_UNIT_TEST(jacks) senf::ppi::init(); - senf::Packet p (senf::DataPacket::create()); - source.submit(p); + { + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + + BOOST_CHECK(p == sink.pop_front()); + } + + group.flip(); + senf::ppi::init(); + + { + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + + BOOST_CHECK(p == sink.pop_front()); + } - BOOST_CHECK(p == sink.front()); + BOOST_CHECK_EQUAL( group.forward1.n, 1u ); + BOOST_CHECK_EQUAL( group.forward2.n, 1u ); } }