From de87ee0d328204c3191f020595d49b3daec71047 Mon Sep 17 00:00:00 2001 From: g0dil <g0dil@wiback.org> Date: Tue, 17 Mar 2009 18:00:32 +0000 Subject: [PATCH] PPI: Allow to change the IOEvent handle/event mask PPI: Allow initialization of jacks from another jack PPI: Allow changing the associated handle of an ActiveSocketSource --- PPI/IOEvent.cc | 6 ++-- PPI/IOEvent.cci | 50 ++++++++++++++++++++++++++ PPI/IOEvent.cti | 13 +++++++ PPI/IOEvent.hh | 5 +++ PPI/Jack.cti | 85 +++++++++++++++++++++++++++++++++++++++----- PPI/Jack.hh | 16 +++++++++ PPI/SocketSource.ct | 11 +++++- PPI/SocketSource.cti | 14 ++++++++ PPI/SocketSource.hh | 12 ++++++- SConstruct | 5 --- 10 files changed, 200 insertions(+), 17 deletions(-) create mode 100644 PPI/IOEvent.cci diff --git a/PPI/IOEvent.cc b/PPI/IOEvent.cc index f63288d4c..ea70efcdd 100644 --- a/PPI/IOEvent.cc +++ b/PPI/IOEvent.cc @@ -41,12 +41,14 @@ prefix_ void senf::ppi::IOEvent::v_enable() { - event_.enable(); + if (fd_ != -1) + event_.enable(); } prefix_ void senf::ppi::IOEvent::v_disable() { - event_.disable(); + if (fd_ != -1) + event_.disable(); } prefix_ void senf::ppi::IOEvent::cb(int event) diff --git a/PPI/IOEvent.cci b/PPI/IOEvent.cci new file mode 100644 index 000000000..54b1c86ff --- /dev/null +++ b/PPI/IOEvent.cci @@ -0,0 +1,50 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund <g0dil@berlios.de> +// +// 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 IOEvent inline non-template implementation */ + +//#include "IOEvent.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +prefix_ senf::ppi::IOEvent::IOEvent() + : fd_ (-1), + event_ ("senf::ppi::IOEvent", boost::bind(&IOEvent::cb,this,_1)) +{} + +///////////////////////////////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/IOEvent.cti b/PPI/IOEvent.cti index 7372e360b..5f36a060e 100644 --- a/PPI/IOEvent.cti +++ b/PPI/IOEvent.cti @@ -40,6 +40,19 @@ prefix_ senf::ppi::IOEvent::IOEvent(Handle handle, unsigned events) event_ ("senf::ppi::IOEvent", boost::bind(&IOEvent::cb,this,_1), fd_, events, false) {} +template <class Handle> +prefix_ void senf::ppi::IOEvent::set(Handle handle, unsigned events) +{ + if (handle) { + fd_ = senf::scheduler::get_descriptor(handle); + event_.events(events).handle(fd_); + } + else { + event_.disable(); + fd_ = -1; + } +} + ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/PPI/IOEvent.hh b/PPI/IOEvent.hh index 7b3bf4818..730b66bcf 100644 --- a/PPI/IOEvent.hh +++ b/PPI/IOEvent.hh @@ -88,12 +88,17 @@ namespace ppi { ///\name Structors and default members ///@{ + IOEvent(); + template <class Handle> IOEvent(Handle handle, unsigned events); ///@} /////////////////////////////////////////////////////////////////////////// + template <class Handle> + void set(Handle handle, unsigned events); + /** \brief Unhandled error condition */ struct ErrorException : public senf::Exception { ErrorException() : senf::Exception("senf::ppi::IOEvent::ErrorException"){} }; diff --git a/PPI/Jack.cti b/PPI/Jack.cti index 220df862a..2266a570d 100644 --- a/PPI/Jack.cti +++ b/PPI/Jack.cti @@ -43,8 +43,26 @@ senf::ppi::connector::ActiveInputJack<PacketType>::ActiveInputJack(ActiveInput<> : GenericActiveInputJack (input) {} -prefix_ senf::ppi::connector::ActiveInputJack<senf::Packet>::ActiveInputJack(ActiveInput<> & input) - : GenericActiveInputJack (input) +template <class PacketType> +prefix_ +senf::ppi::connector::ActiveInputJack<PacketType>::ActiveInputJack(ActiveInputJack & input) + : GenericActiveInputJack (input.connector()) +{} + +template <class PacketType> +prefix_ +senf::ppi::connector::ActiveInputJack<PacketType>::ActiveInputJack(ActiveInputJack<> & input) + : GenericActiveInputJack (input.connector()) +{} + +prefix_ +senf::ppi::connector::ActiveInputJack<senf::Packet>::ActiveInputJack(ActiveInput<> & input) + : GenericActiveInputJack (input) +{} + +prefix_ +senf::ppi::connector::ActiveInputJack<senf::Packet>::ActiveInputJack(ActiveInputJack & input) + : GenericActiveInputJack (input.connector()) {} template <class PacketType> @@ -59,9 +77,26 @@ senf::ppi::connector::ActiveOutputJack<PacketType>::ActiveOutputJack(ActiveOutpu : GenericActiveOutputJack (output) {} -prefix_ -senf::ppi::connector::ActiveOutputJack<senf::Packet>::ActiveOutputJack(ActiveOutput<> & output) - : GenericActiveOutputJack (output) +template <class PacketType> +prefix_ senf::ppi::connector::ActiveOutputJack<PacketType>:: +ActiveOutputJack(ActiveOutputJack & output) + : GenericActiveOutputJack (output.connector()) +{} + +template <class PacketType> +prefix_ senf::ppi::connector::ActiveOutputJack<PacketType>:: +ActiveOutputJack(ActiveOutputJack<> & output) + : GenericActiveOutputJack (output.connector()) +{} + +prefix_ senf::ppi::connector::ActiveOutputJack<senf::Packet>:: +ActiveOutputJack(ActiveOutput<> & output) + : GenericActiveOutputJack (output) +{} + +prefix_ senf::ppi::connector::ActiveOutputJack<senf::Packet>:: +ActiveOutputJack(ActiveOutputJack & output) + : GenericActiveOutputJack (output.connector()) {} template <class PacketType> @@ -76,11 +111,28 @@ senf::ppi::connector::PassiveInputJack<PacketType>::PassiveInputJack(PassiveInpu : GenericPassiveInputJack (input) {} +template <class PacketType> +prefix_ +senf::ppi::connector::PassiveInputJack<PacketType>::PassiveInputJack(PassiveInputJack & input) + : GenericPassiveInputJack (input.connector()) +{} + +template <class PacketType> +prefix_ senf::ppi::connector::PassiveInputJack<PacketType>:: +PassiveInputJack(PassiveInputJack<> & input) + : GenericPassiveInputJack (input.connector()) +{} + prefix_ senf::ppi::connector::PassiveInputJack<senf::Packet>::PassiveInputJack(PassiveInput<> & input) : GenericPassiveInputJack (input) {} +prefix_ senf::ppi::connector::PassiveInputJack<senf::Packet>:: +PassiveInputJack(PassiveInputJack & input) + : GenericPassiveInputJack (input.connector()) +{} + template <class PacketType> prefix_ senf::ppi::connector::PassiveOutputJack<PacketType>:: PassiveOutputJack(PassiveOutput<PacketType> & output) @@ -93,9 +145,26 @@ PassiveOutputJack(PassiveOutput<> & output) : GenericPassiveOutputJack (output) {} -prefix_ -senf::ppi::connector::PassiveOutputJack<senf::Packet>::PassiveOutputJack(PassiveOutput<> & output) - : GenericPassiveOutputJack (output) +template <class PacketType> +prefix_ senf::ppi::connector::PassiveOutputJack<PacketType>:: +PassiveOutputJack(PassiveOutputJack & output) + : GenericPassiveOutputJack (output.connector()) +{} + +template <class PacketType> +prefix_ senf::ppi::connector::PassiveOutputJack<PacketType>:: +PassiveOutputJack(PassiveOutputJack<> & output) + : GenericPassiveOutputJack (output.connector()) +{} + +prefix_ senf::ppi::connector::PassiveOutputJack<senf::Packet>:: +PassiveOutputJack(PassiveOutput<> & output) + : GenericPassiveOutputJack (output) +{} + +prefix_ senf::ppi::connector::PassiveOutputJack<senf::Packet>:: +PassiveOutputJack(PassiveOutputJack & output) + : GenericPassiveOutputJack (output.connector()) {} template <class T> diff --git a/PPI/Jack.hh b/PPI/Jack.hh index 5cfbc12fe..83657ba7a 100644 --- a/PPI/Jack.hh +++ b/PPI/Jack.hh @@ -97,6 +97,9 @@ namespace connector { public: explicit ActiveInputJack(ActiveInput<PacketType> & input); explicit ActiveInputJack(ActiveInput<> & input); + + explicit ActiveInputJack(ActiveInputJack & input); + explicit ActiveInputJack(ActiveInputJack<> & input); }; #ifndef DOXYGEN @@ -107,6 +110,7 @@ namespace connector { { public: explicit ActiveInputJack(ActiveInput<> & input); + explicit ActiveInputJack(ActiveInputJack & input); }; #endif @@ -118,6 +122,9 @@ namespace connector { public: explicit ActiveOutputJack(ActiveOutput<PacketType> & output); explicit ActiveOutputJack(ActiveOutput<> & output); + + explicit ActiveOutputJack(ActiveOutputJack & output); + explicit ActiveOutputJack(ActiveOutputJack<> & output); }; #ifndef DOXYGEN @@ -128,6 +135,7 @@ namespace connector { { public: explicit ActiveOutputJack(ActiveOutput<> & output); + explicit ActiveOutputJack(ActiveOutputJack & output); }; #endif @@ -139,6 +147,9 @@ namespace connector { public: explicit PassiveInputJack(PassiveInput<PacketType> & input); explicit PassiveInputJack(PassiveInput<> & input); + + explicit PassiveInputJack(PassiveInputJack & input); + explicit PassiveInputJack(PassiveInputJack<> & input); }; #ifndef DOXYGEN @@ -149,6 +160,7 @@ namespace connector { { public: explicit PassiveInputJack(PassiveInput<> & input); + explicit PassiveInputJack(PassiveInputJack & input); }; #endif @@ -160,6 +172,9 @@ namespace connector { public: explicit PassiveOutputJack(PassiveOutput<PacketType> & output); explicit PassiveOutputJack(PassiveOutput<> & output); + + explicit PassiveOutputJack(PassiveOutputJack & output); + explicit PassiveOutputJack(PassiveOutputJack<> & output); }; #ifndef DOXYGEN @@ -170,6 +185,7 @@ namespace connector { { public: explicit PassiveOutputJack(PassiveOutput<> & output); + explicit PassiveOutputJack(PassiveOutputJack & output); }; #endif diff --git a/PPI/SocketSource.ct b/PPI/SocketSource.ct index eb69a5d93..7ea550697 100644 --- a/PPI/SocketSource.ct +++ b/PPI/SocketSource.ct @@ -44,10 +44,19 @@ prefix_ Packet senf::ppi::DgramReader<Packet>::operator()(Handle handle) /////////////////////////////////////////////////////////////////////////// // senf::ppi::module::ActiveSocketSource<Reader> +template <class Reader> +prefix_ senf::ppi::module::ActiveSocketSource<Reader>::ActiveSocketSource() +{} + +template <class Reader> +prefix_ senf::ppi::module::ActiveSocketSource<Reader>::ActiveSocketSource(Reader reader) + : reader_(reader) +{} + template <class Reader> prefix_ senf::ppi::module::ActiveSocketSource<Reader>:: ActiveSocketSource(Handle handle) - : handle_(handle), event_(handle_, IOEvent::Read), reader_() + : handle_(handle), event_(handle_, IOEvent::Read) { registerEvent( event_, &ActiveSocketSource::read ); route(event_, output); diff --git a/PPI/SocketSource.cti b/PPI/SocketSource.cti index 90e89e0a1..8bb2e7c17 100644 --- a/PPI/SocketSource.cti +++ b/PPI/SocketSource.cti @@ -39,6 +39,20 @@ prefix_ Reader & senf::ppi::module::ActiveSocketSource<Reader>::reader() return reader_; } +template <class Reader> +prefix_ typename senf::ppi::module::ActiveSocketSource<Reader>::Handle +senf::ppi::module::ActiveSocketSource<Reader>::handle() +{ + return handle_; +} + +template <class Reader> +prefix_ void senf::ppi::module::ActiveSocketSource<Reader>::handle(Handle handle) +{ + handle_ = handle; + event_.set(handle_, IOEvent::Read); +} + ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/PPI/SocketSource.hh b/PPI/SocketSource.hh index 44368fb52..3c78d5851 100644 --- a/PPI/SocketSource.hh +++ b/PPI/SocketSource.hh @@ -116,7 +116,13 @@ namespace module { connector::ActiveOutput<typename Reader::PacketType> output; ///< Output connector to which the data received is written - ActiveSocketSource(Handle handle); ///< Create new reader for the given handle + ActiveSocketSource(); ///< Create non-connected reader + /**< The reader will be disabled until a socket is set + \pre Requires \a Reader to be default constructible */ + explicit ActiveSocketSource(Reader reader); ///< Create non-connected reader + /**< The reader will be disabled until a socket is set + \pre Requires \a Reader to be copy constructible */ + explicit ActiveSocketSource(Handle handle); ///< Create new reader for the given handle /**< Data will be read from \a handle and be parsed by \a Reader. \pre Requires \a Reader to be default constructible @@ -129,6 +135,10 @@ namespace module { \param[in] handle Handle to read data from */ Reader & reader(); ///< Access Reader helper + Handle handle(); ///< Access handle + void handle(Handle handle); ///< Set handle + /**< Assigning an empty or in-valid() handle will disable + the module until a new, valid handle is assigned. */ private: void read(); diff --git a/SConstruct b/SConstruct index 2acf3d79e..5fe796bae 100644 --- a/SConstruct +++ b/SConstruct @@ -183,11 +183,6 @@ if not env.GetOption('clean') and not os.path.exists(".prepare-stamp") \ env.Clean('all', '.prepare-stamp') -# Not nice, but until we get to fixing the dependency jungle -# concerning generated sources ... -scripts = [] -dependencies = [] - SConscript(glob.glob("*/SConscript")) SENFSCons.StandardTargets(env) -- GitLab