From: g0dil Date: Mon, 16 Mar 2009 12:00:38 +0000 (+0000) Subject: PPI: Add connector jack classes X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=2eb3c777cc9db271336c226f4eeec6018c196c3e;p=senf.git PPI: Add connector jack classes git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1154 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/Jack.cci b/PPI/Jack.cci new file mode 100644 index 0000000..143afe7 --- /dev/null +++ b/PPI/Jack.cci @@ -0,0 +1,126 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// 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 Jack inline non-template implementation */ + +//#include "Jack.ih" + +// Custom includes +#include "Setup.hh" + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +prefix_ senf::ppi::connector::GenericActiveInputJack:: +GenericActiveInputJack(GenericActiveInput & input) + : input_ (input) +{} + +prefix_ senf::ppi::connector::GenericActiveInput & +senf::ppi::connector::GenericActiveInputJack::connector() +{ + return input_; +} + +prefix_ senf::ppi::connector::GenericActiveOutputJack:: +GenericActiveOutputJack(GenericActiveOutput & output) + : output_ (output) +{} + +prefix_ senf::ppi::connector::GenericActiveOutput & +senf::ppi::connector::GenericActiveOutputJack::connector() +{ + return output_; +} + +prefix_ senf::ppi::connector::GenericPassiveInputJack:: +GenericPassiveInputJack(GenericPassiveInput & input) + : input_ (input) +{} + +prefix_ senf::ppi::connector::GenericPassiveInput & +senf::ppi::connector::GenericPassiveInputJack::connector() +{ + return input_; +} + +prefix_ senf::ppi::connector::GenericPassiveOutputJack:: +GenericPassiveOutputJack(GenericPassiveOutput & output) + : output_ (output) +{} + +prefix_ senf::ppi::connector::GenericPassiveOutput & +senf::ppi::connector::GenericPassiveOutputJack::connector() +{ + return output_; +} + +prefix_ void senf::ppi::connect(connector::GenericActiveOutputJack & source, + connector::GenericPassiveInputJack & target) +{ + connect(source.connector(), target.connector()); +} + +prefix_ void senf::ppi::connect(connector::GenericPassiveOutputJack & source, + connector::GenericActiveInputJack & target) +{ + connect(source.connector(), target.connector()); +} + +prefix_ void senf::ppi::connect(connector::GenericActiveOutputJack & source, + connector::GenericPassiveInput & target) +{ + connect(source.connector(), target); +} + +prefix_ void senf::ppi::connect(connector::GenericPassiveOutputJack & source, + connector::GenericActiveInput & target) +{ + connect(source.connector(), target); +} + +prefix_ void senf::ppi::connect(connector::GenericActiveOutput & source, + connector::GenericPassiveInputJack & target) +{ + connect(source, target.connector()); +} + +prefix_ void senf::ppi::connect(connector::GenericPassiveOutput & source, + connector::GenericActiveInputJack & target) +{ + connect(source, target.connector()); +} + +///////////////////////////////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/Jack.cti b/PPI/Jack.cti new file mode 100644 index 0000000..220df86 --- /dev/null +++ b/PPI/Jack.cti @@ -0,0 +1,145 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// 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 Jack inline template implementation */ + +//#include "Jack.ih" + +// Custom includes +#include "Setup.hh" + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +template +prefix_ senf::ppi::connector::ActiveInputJack:: +ActiveInputJack(ActiveInput & input) + : GenericActiveInputJack (input) +{} + +template +prefix_ +senf::ppi::connector::ActiveInputJack::ActiveInputJack(ActiveInput<> & input) + : GenericActiveInputJack (input) +{} + +prefix_ senf::ppi::connector::ActiveInputJack::ActiveInputJack(ActiveInput<> & input) + : GenericActiveInputJack (input) +{} + +template +prefix_ senf::ppi::connector::ActiveOutputJack:: +ActiveOutputJack(ActiveOutput & output) + : GenericActiveOutputJack (output) +{} + +template +prefix_ +senf::ppi::connector::ActiveOutputJack::ActiveOutputJack(ActiveOutput<> & output) + : GenericActiveOutputJack (output) +{} + +prefix_ +senf::ppi::connector::ActiveOutputJack::ActiveOutputJack(ActiveOutput<> & output) + : GenericActiveOutputJack (output) +{} + +template +prefix_ senf::ppi::connector::PassiveInputJack:: +PassiveInputJack(PassiveInput & input) + : GenericPassiveInputJack (input) +{} + +template +prefix_ +senf::ppi::connector::PassiveInputJack::PassiveInputJack(PassiveInput<> & input) + : GenericPassiveInputJack (input) +{} + +prefix_ +senf::ppi::connector::PassiveInputJack::PassiveInputJack(PassiveInput<> & input) + : GenericPassiveInputJack (input) +{} + +template +prefix_ senf::ppi::connector::PassiveOutputJack:: +PassiveOutputJack(PassiveOutput & output) + : GenericPassiveOutputJack (output) +{} + +template +prefix_ senf::ppi::connector::PassiveOutputJack:: +PassiveOutputJack(PassiveOutput<> & output) + : GenericPassiveOutputJack (output) +{} + +prefix_ +senf::ppi::connector::PassiveOutputJack::PassiveOutputJack(PassiveOutput<> & output) + : GenericPassiveOutputJack (output) +{} + +template +prefix_ void +senf::ppi::connect(connector::GenericActiveOutputJack & source, T & target, + typename boost::disable_if< boost::is_base_of >::type *) +{ + connect(source.connector(), target); +} + +template +prefix_ void +senf::ppi::connect(connector::GenericPassiveOutputJack & source, T & target, + typename boost::disable_if< boost::is_base_of >::type *) +{ + connect(source.connector(), target); +} + +template +prefix_ void +senf::ppi::connect(T & source, connector::GenericActiveInputJack & target, + typename boost::disable_if< boost::is_base_of >::type *) +{ + connect(source, target.connector()); +} + +template +prefix_ void +senf::ppi::connect(T & source, connector::GenericPassiveInputJack & target, + typename boost::disable_if< boost::is_base_of >::type *) +{ + connect(source, target.connector()); +} + +///////////////////////////////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/Jack.hh b/PPI/Jack.hh new file mode 100644 index 0000000..5cfbc12 --- /dev/null +++ b/PPI/Jack.hh @@ -0,0 +1,227 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// 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 Jack public header */ + +#ifndef HH_SENF_PPI_Jack_ +#define HH_SENF_PPI_Jack_ 1 + +// Custom includes +#include +#include +#include "Connectors.hh" + +//#include "Jack.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { +namespace ppi { +namespace connector { + + class Jack + : private boost::noncopyable + {}; + + class GenericActiveInputJack + : public Jack + { + public: + explicit GenericActiveInputJack(GenericActiveInput & input); + + GenericActiveInput & connector(); + + private: + GenericActiveInput & input_; + }; + + class GenericActiveOutputJack + : public Jack + { + public: + explicit GenericActiveOutputJack(GenericActiveOutput & output); + + GenericActiveOutput & connector(); + + private: + GenericActiveOutput & output_; + }; + + class GenericPassiveInputJack + : public Jack + { + public: + explicit GenericPassiveInputJack(GenericPassiveInput & input); + + GenericPassiveInput & connector(); + + private: + GenericPassiveInput & input_; + }; + + class GenericPassiveOutputJack + : public Jack + { + public: + explicit GenericPassiveOutputJack(GenericPassiveOutput & output); + + GenericPassiveOutput & connector(); + + private: + GenericPassiveOutput & output_; + }; + + template + class ActiveInputJack + : public GenericActiveInputJack + { + public: + explicit ActiveInputJack(ActiveInput & input); + explicit ActiveInputJack(ActiveInput<> & input); + }; + +#ifndef DOXYGEN + + template <> + class ActiveInputJack + : public GenericActiveInputJack + { + public: + explicit ActiveInputJack(ActiveInput<> & input); + }; + +#endif + + template + class ActiveOutputJack + : public GenericActiveOutputJack + { + public: + explicit ActiveOutputJack(ActiveOutput & output); + explicit ActiveOutputJack(ActiveOutput<> & output); + }; + +#ifndef DOXYGEN + + template <> + class ActiveOutputJack + : public GenericActiveOutputJack + { + public: + explicit ActiveOutputJack(ActiveOutput<> & output); + }; + +#endif + + template + class PassiveInputJack + : public GenericPassiveInputJack + { + public: + explicit PassiveInputJack(PassiveInput & input); + explicit PassiveInputJack(PassiveInput<> & input); + }; + +#ifndef DOXYGEN + + template <> + class PassiveInputJack + : public GenericPassiveInputJack + { + public: + explicit PassiveInputJack(PassiveInput<> & input); + }; + +#endif + + template + class PassiveOutputJack + : public GenericPassiveOutputJack + { + public: + explicit PassiveOutputJack(PassiveOutput & output); + explicit PassiveOutputJack(PassiveOutput<> & output); + }; + +#ifndef DOXYGEN + + template <> + class PassiveOutputJack + : public GenericPassiveOutputJack + { + public: + explicit PassiveOutputJack(PassiveOutput<> & output); + }; + +#endif +} + +#ifndef DOXYGEN + + template + void connect(connector::GenericActiveOutputJack & source, T & target, + typename boost::disable_if< boost::is_base_of >::type * = 0); + template + void connect(connector::GenericPassiveOutputJack & source, T & target, + typename boost::disable_if< boost::is_base_of >::type * = 0); + + template + void connect(T & source, connector::GenericActiveInputJack & target, + typename boost::disable_if< boost::is_base_of >::type * = 0); + template + void connect(T & source, connector::GenericPassiveInputJack & target, + typename boost::disable_if< boost::is_base_of >::type * = 0); + + void connect(connector::GenericActiveOutputJack & source, + connector::GenericPassiveInputJack & target); + void connect(connector::GenericPassiveOutputJack & source, + connector::GenericActiveInputJack & target); + + void connect(connector::GenericActiveOutputJack & source, + connector::GenericPassiveInput & target); + void connect(connector::GenericPassiveOutputJack & source, + connector::GenericActiveInput & target); + + void connect(connector::GenericActiveOutput & source, + connector::GenericPassiveInputJack & target); + void connect(connector::GenericPassiveOutput & source, + connector::GenericActiveInputJack & target); + +#endif +}} + +///////////////////////////////hh.e//////////////////////////////////////// +#include "Jack.cci" +//#include "Jack.ct" +#include "Jack.cti" +#endif + + +// 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/Jack.test.cc b/PPI/Jack.test.cc new file mode 100644 index 0000000..939d485 --- /dev/null +++ b/PPI/Jack.test.cc @@ -0,0 +1,147 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// 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 Jack.test unit tests */ + +//#include "Jack.test.hh" +//#include "Jack.test.ih" + +// Custom includes +#include "PPI.hh" + +#include "../Utils/auto_unit_test.hh" +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +namespace { + + class ActiveDummyForward + : public senf::ppi::module::Module + { + SENF_PPI_MODULE(ActiveDummyForward); + public: + senf::ppi::connector::ActiveInput<> input; + senf::ppi::connector::PassiveOutput<> output; + + ActiveDummyForward() + { route(input, output); output.onRequest(&ActiveDummyForward::request); } + + private: + void request() + { output(input()); } + }; + + class PassiveDummyForward + : public senf::ppi::module::Module + { + SENF_PPI_MODULE(PassiveDummyForward); + public: + senf::ppi::connector::PassiveInput<> input; + senf::ppi::connector::ActiveOutput<> output; + + PassiveDummyForward() + { route(input, output); input.onRequest(&PassiveDummyForward::request); } + + private: + void request() + { output(input()); } + }; + + class ActiveGroup + { + public: + senf::ppi::connector::ActiveInputJack<> input; + senf::ppi::connector::PassiveOutputJack<> output; + + ActiveGroup() + : input (forward.input), output (forward.output) {} + + private: + ActiveDummyForward forward; + }; + + class PassiveGroup + { + public: + senf::ppi::connector::PassiveInputJack<> input; + senf::ppi::connector::ActiveOutputJack<> output; + + PassiveGroup() + : input (forward.input), output (forward.output) {} + + private: + PassiveDummyForward forward; + }; + +} + +BOOST_AUTO_UNIT_TEST(jacks) +{ + { + ActiveGroup group; + senf::ppi::module::debug::PassiveSource source; + senf::ppi::module::debug::ActiveSink sink; + + senf::ppi::connect(source, group); + senf::ppi::connect(group, sink); + + senf::ppi::init(); + + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + + BOOST_CHECK(p == sink.request()); + } + + { + PassiveGroup group; + senf::ppi::module::debug::ActiveSource source; + senf::ppi::module::debug::PassiveSink sink; + + senf::ppi::connect(source, group); + senf::ppi::connect(group, sink); + + senf::ppi::init(); + + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + + BOOST_CHECK(p == sink.front()); + } +} + +///////////////////////////////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: diff --git a/PPI/Setup.cti b/PPI/Setup.cti index 30c7ae6..f18f8b4 100644 --- a/PPI/Setup.cti +++ b/PPI/Setup.cti @@ -36,7 +36,8 @@ template prefix_ void senf::ppi:: connect(T & source, C & target, typename boost::disable_if< boost::is_base_of >::type *, - typename boost::enable_if< boost::is_base_of >::type *) + typename boost::enable_if< boost::is_base_of >::type *, + typename boost::disable_if< boost::is_base_of >:: type *) { connect(source.output, target); } @@ -45,7 +46,8 @@ template prefix_ void senf::ppi:: connect(C & source, T & target, typename boost::enable_if< boost::is_base_of >::type *, - typename boost::disable_if< boost::is_base_of >::type *) + typename boost::disable_if< boost::is_base_of >::type *, + typename boost::disable_if< boost::is_base_of >:: type *) { connect(source, target.input); } @@ -54,7 +56,9 @@ template prefix_ void senf::ppi:: connect(T1 & source, T2 & target, typename boost::disable_if< boost::is_base_of >::type *, - typename boost::disable_if< boost::is_base_of >::type *) + typename boost::disable_if< boost::is_base_of >::type *, + typename boost::disable_if< boost::is_base_of >:: type *, + typename boost::disable_if< boost::is_base_of >:: type *) { connect(source.output, target.input); } diff --git a/PPI/Setup.hh b/PPI/Setup.hh index 1c42c0e..7ca5068 100644 --- a/PPI/Setup.hh +++ b/PPI/Setup.hh @@ -76,17 +76,21 @@ namespace ppi { template void connect(T & source, C & target, typename boost::disable_if< boost::is_base_of >::type * = 0, - typename boost::enable_if< boost::is_base_of >::type * = 0); + typename boost::enable_if< boost::is_base_of >::type * = 0, + typename boost::disable_if< boost::is_base_of >:: type * = 0); template void connect(C & source, T & target, typename boost::enable_if< boost::is_base_of >::type * = 0, - typename boost::disable_if< boost::is_base_of >::type * = 0); + typename boost::disable_if< boost::is_base_of >::type * = 0, + typename boost::disable_if< boost::is_base_of >:: type * = 0); template void connect(T1 & source, T2 & target, typename boost::disable_if< boost::is_base_of >::type * = 0, - typename boost::disable_if< boost::is_base_of >::type * = 0); + typename boost::disable_if< boost::is_base_of >::type * = 0, + typename boost::disable_if< boost::is_base_of >:: type * = 0, + typename boost::disable_if< boost::is_base_of >:: type * = 0); #endif diff --git a/PPI/predecl.hh b/PPI/predecl.hh index 81094eb..e5b1091 100644 --- a/PPI/predecl.hh +++ b/PPI/predecl.hh @@ -90,6 +90,8 @@ namespace ppi { template class ActiveInput; template class ActiveOutput; + class Jack; + #ifndef DOXYGEN namespace detail {