From: g0dil Date: Mon, 17 Dec 2007 12:07:11 +0000 (+0000) Subject: Utils/Exception: Allow to disable ErrnoExceptions via SENF_NO_ERRNOEXC X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=28275a1a9075ae42dc29aaadc5bc78e6fa204e26;p=senf.git Utils/Exception: Allow to disable ErrnoExceptions via SENF_NO_ERRNOEXC PPI: Allow access to source/sink helper in (Active|Passive)Socket(Source|Sink) git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@570 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/Setup.hh b/PPI/Setup.hh index ae9c743..c73102d 100644 --- a/PPI/Setup.hh +++ b/PPI/Setup.hh @@ -37,11 +37,27 @@ namespace senf { namespace ppi { -#ifndef DOXYGEN + /** \brief Connect modules + + senf::ppi::connect() establishes a connection between two modules or, to be more precise, + between two connectors. It will connect any input to any output connector as long as one is + active and the other passive. + If a module has an output connector called \c output, the module may be directly specified + as \a source argument. In the same way, if a module has an input connector called \c input, + the module may be given directly as \a target argument. This simplifies the most common case + of a module with one input and one output connector. + + \see \ref ppi_connections + */ void connect(connector::ActiveOutput & source, connector::PassiveInput & target); + + /** \brief Connect modules + \see connect() */ void connect(connector::PassiveOutput & source, connector::ActiveInput & target); - + +#ifndef DOXYGEN + template void connect(T & source, C & target, typename boost::disable_if< boost::is_base_of >::type * = 0, @@ -57,27 +73,6 @@ namespace ppi { typename boost::disable_if< boost::is_base_of >::type * = 0, typename boost::disable_if< boost::is_base_of >::type * = 0); -#else - - /** \brief Connect modules - - senf::ppi::connect() establishes a connection between two modules or, to be more precise, - between two connectors. It will connect any input to any output connector as long as one is - active and the other passive. - - If a module has an output connector called \c output, the module may be directly specified - as \a source argument. In the same way, if a module has an input connector called \c input, - the module may be given directly as \a target argument. This simplifies the most common case - of a module with one input and one output connector. - - \see \ref ppi_connections - */ - void connect(connector::ActiveInput & source, connector::PassiveOutput & target); - - /** \brief Connect modules - \see connect() */ - void connect(connector::PassiveInput & source, connector::ActiveOutput & target); - #endif /** \brief Start the network diff --git a/PPI/SocketSink.ct b/PPI/SocketSink.ct index ba7fffc..a2dcc66 100644 --- a/PPI/SocketSink.ct +++ b/PPI/SocketSink.ct @@ -41,6 +41,15 @@ prefix_ senf::ppi::module::ActiveSocketSink::ActiveSocketSink(Handle handl route(input, event_); } +template +prefix_ senf::ppi::module::ActiveSocketSink::ActiveSocketSink(Handle handle, + Sink const & sink) + : handle_(handle), event_(handle_, IOEvent::Write), writer_(sink) +{ + registerEvent( event_, &ActiveSocketSink::write ); + route(input, event_); +} + //////////////////////////////////////// // private members @@ -61,6 +70,15 @@ prefix_ senf::ppi::module::PassiveSocketSink::PassiveSocketSink(Handle han input.onRequest(&PassiveSocketSink::write); } +template +prefix_ senf::ppi::module::PassiveSocketSink::PassiveSocketSink(Handle handle, + Sink const & sink) + : handle_(handle), writer_(sink) +{ + noroute(input); + input.onRequest(&PassiveSocketSink::write); +} + //////////////////////////////////////// // private members diff --git a/PPI/SocketSink.cti b/PPI/SocketSink.cti new file mode 100644 index 0000000..9d58da1 --- /dev/null +++ b/PPI/SocketSink.cti @@ -0,0 +1,63 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer NETwork research (NET) +// 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 SocketSink inline template implementation */ + +//#include "SocketSink.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::ActiveSocketSink + +template +prefix_ Sink & senf::ppi::module::ActiveSocketSink::sink() +{ + return writer_; +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PassiveSocketSink + +template +prefix_ Sink & senf::ppi::module::PassiveSocketSink::sink() +{ + return writer_; +} + +///////////////////////////////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/SocketSink.hh b/PPI/SocketSink.hh index 29b77c1..b101a6d 100644 --- a/PPI/SocketSink.hh +++ b/PPI/SocketSink.hh @@ -82,7 +82,10 @@ namespace module { { public: typedef unspecified Handle; // type of handle requested - SomeSink(); // default constructible + + SomeSink(); // EITHER default constructible OR + SomeSink(SomeSink const & other); // copy constructible + void operator()(Handle handle, Packet packet); // insertion function }; \endcode @@ -102,7 +105,18 @@ namespace module { ActiveSocketSink(Handle handle); ///< Create new writer for the given handle /**< Data will be written to \a handle using \a Sink. + \pre Requires \a Sink to be default constructible \param[in] handle Handle to write data to */ + ActiveSocketSink(Handle handle, Sink const & sink); + ///< Create new writer for the given handle + /**< Data will be written to \a handle using \a Sink. + \pre Requires \a Sink to be copy constructible + \param[in] handle Handle to write data to + \param[in] sink Sink helper writing packet date to the + socket */ + + Sink & sink(); ///< Access the sink helper + private: void write(); @@ -128,7 +142,10 @@ namespace module { { public: typedef unspecified Handle; // type of handle requested - SomeSink(); // default constructible + + SomeSink(); // EITHER default constructible + SomeSink(SomeSink const & other); // OR copy constructible + void operator()(Handle handle, Packet packet); // insertion function }; \endcode @@ -148,7 +165,15 @@ namespace module { PassiveSocketSink(Handle handle); ///< Create new writer for the given handle /**< Data will be written to \a handle using \a Sink. + \pre Requires \a Sink to be default constructible \param[in] handle Handle to write data to */ + PassiveSocketSink(Handle handle, Sink const & sink); + ///< Create new writer for the given handle + /**< Data will be written to \a handle using \a Sink. + \pre Requires \a Sink to be copy constructible + \param[in] handle Handle to write data to */ + + Sink & sink(); ///< Access the sink helper private: void write(); @@ -163,7 +188,7 @@ namespace module { ///////////////////////////////hh.e//////////////////////////////////////// #include "SocketSink.cci" #include "SocketSink.ct" -//#include "SocketSink.cti" +#include "SocketSink.cti" #endif diff --git a/PPI/SocketSource.ct b/PPI/SocketSource.ct index f38f045..1b9dd57 100644 --- a/PPI/SocketSource.ct +++ b/PPI/SocketSource.ct @@ -53,6 +53,15 @@ ActiveSocketSource(Handle handle) route(event_, output); } +template +prefix_ senf::ppi::module::ActiveSocketSource::ActiveSocketSource(Handle handle, + Source source) + : handle_(handle), event_(handle_, IOEvent::Read), reader_(source) +{ + registerEvent( event_, &ActiveSocketSource::read ); + route(event_, output); +} + //////////////////////////////////////// // private members diff --git a/PPI/SocketSource.cti b/PPI/SocketSource.cti new file mode 100644 index 0000000..cb0d8f0 --- /dev/null +++ b/PPI/SocketSource.cti @@ -0,0 +1,54 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer NETwork research (NET) +// 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 SocketSource inline template implementation */ + +//#include "SocketSource.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::ActiveSocketSource + +template +prefix_ Source & senf::ppi::module::ActiveSocketSource::source() +{ + return reader_; +} + +///////////////////////////////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/SocketSource.hh b/PPI/SocketSource.hh index de4dbe6..cb91adc 100644 --- a/PPI/SocketSource.hh +++ b/PPI/SocketSource.hh @@ -87,9 +87,12 @@ namespace module { class SomeSource { public: - typedef unspecified_type Handle; // type of handle requested - SomeSource(); // default constructible - Packet operator()(Handle handle); // extraction function + typedef unspecified_type Handle; // type of handle requested + + SomeSource(); // EITHER default constructible + SomeSource(SomeSource const & other); // OR copy constructible + + Packet operator()(Handle handle); // extraction function }; \endcode Whenever the FileHandle object is ready for reading, the \a Source's \c operator() is called @@ -111,8 +114,17 @@ namespace module { ActiveSocketSource(Handle handle); ///< Create new reader for the given handle /**< Data will be read from \a handle and be parsed by \a Source. + \pre Requires \a Source to be default constructible + \param[in] handle Handle to read data from */ + ActiveSocketSource(Handle handle, Source source); + ///< Create new reader for the given handle + /**< Data will be read from \a handle and be parsed by \a + Source. + \pre Requires \a Source to be copy constructible \param[in] handle Handle to read data from */ + Source & source(); ///< Access source helper + private: void read(); @@ -126,7 +138,7 @@ namespace module { ///////////////////////////////hh.e//////////////////////////////////////// //#include "SocketSource.cci" #include "SocketSource.ct" -//#include "SocketSource.cti" +#include "SocketSource.cti" #endif diff --git a/SConstruct b/SConstruct index b501151..c02b7cc 100644 --- a/SConstruct +++ b/SConstruct @@ -112,6 +112,7 @@ debsrc Build debian source package debbin Build debian binary package linklint Check links of doxygen documentation with 'linklint' fixlinks Fix broken links in doxygen documentation +valgrind Run all tests under valgrind/memcheck """) if os.environ.get('debian_build'): diff --git a/Utils/Exception.cc b/Utils/Exception.cc index 2185643..86eaef1 100644 --- a/Utils/Exception.cc +++ b/Utils/Exception.cc @@ -35,6 +35,7 @@ prefix_ void senf::throwErrno(std::string const & where, int code) { +#ifndef SENF_NO_ERRNOEXC switch (code) { // BOOST_PP_REPEAT is limited to 256 repetitions. The max errno value I found in any header file @@ -61,6 +62,9 @@ prefix_ void senf::throwErrno(std::string const & where, int code) default: throw SystemException(where, code); } +#else + throw SystemException(where, code); +#endif } ///////////////////////////////cc.e////////////////////////////////////////