From: g0dil Date: Wed, 18 Mar 2009 11:49:45 +0000 (+0000) Subject: PPI: Allow changing the associated handle of an Active/PassiveSocketSInk X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=fc1ad795c55b8f64bce4926e4ef9194c773342c8;p=senf.git PPI: Allow changing the associated handle of an Active/PassiveSocketSInk git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1158 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/IOEvent.hh b/PPI/IOEvent.hh index 730b66b..b6bb619 100644 --- a/PPI/IOEvent.hh +++ b/PPI/IOEvent.hh @@ -123,7 +123,7 @@ namespace ppi { }} ///////////////////////////////hh.e//////////////////////////////////////// -//#include "IOEvent.cci" +#include "IOEvent.cci" //#include "IOEvent.ct" #include "IOEvent.cti" #endif diff --git a/PPI/SocketSink.ct b/PPI/SocketSink.ct index e578fd0..69726a2 100644 --- a/PPI/SocketSink.ct +++ b/PPI/SocketSink.ct @@ -34,6 +34,21 @@ // senf::ppi::module::ActiveSocketSink template +prefix_ senf::ppi::module::ActiveSocketSink::ActiveSocketSink() +{ + registerEvent( event_, &ActiveSocketSink::write ); + route(input, event_); +} + +template +prefix_ senf::ppi::module::ActiveSocketSink::ActiveSocketSink(Writer const & writer) + : writer_ (writer) +{ + registerEvent( event_, &ActiveSocketSink::write ); + route(input, event_); +} + +template prefix_ senf::ppi::module::ActiveSocketSink::ActiveSocketSink(Handle handle) : handle_(handle), event_(handle_, IOEvent::Write), writer_() { @@ -63,11 +78,29 @@ prefix_ void senf::ppi::module::ActiveSocketSink::write() // senf::ppi::module::PassiveSocketSink template +prefix_ senf::ppi::module::PassiveSocketSink::PassiveSocketSink() +{ + noroute(input); + input.onRequest(&PassiveSocketSink::write); + checkThrottle(); +} + +template +prefix_ senf::ppi::module::PassiveSocketSink::PassiveSocketSink(Writer const & writer) + : writer_ (writer) +{ + noroute(input); + input.onRequest(&PassiveSocketSink::write); + checkThrottle(); +} + +template prefix_ senf::ppi::module::PassiveSocketSink::PassiveSocketSink(Handle handle) : handle_(handle), writer_() { noroute(input); input.onRequest(&PassiveSocketSink::write); + checkThrottle(); } template @@ -77,6 +110,7 @@ prefix_ senf::ppi::module::PassiveSocketSink::PassiveSocketSink(Handle h { noroute(input); input.onRequest(&PassiveSocketSink::write); + checkThrottle(); } //////////////////////////////////////// @@ -88,6 +122,15 @@ prefix_ void senf::ppi::module::PassiveSocketSink::write() writer_(handle_,input()); } +template +prefix_ void senf::ppi::module::PassiveSocketSink::checkThrottle() +{ + if (handle_) + input.unthrottle(); + else + input.throttle(); +} + ///////////////////////////////ct.e//////////////////////////////////////// #undef prefix_ diff --git a/PPI/SocketSink.cti b/PPI/SocketSink.cti index 1ae129b..b7482eb 100644 --- a/PPI/SocketSink.cti +++ b/PPI/SocketSink.cti @@ -39,6 +39,20 @@ prefix_ Writer & senf::ppi::module::ActiveSocketSink::writer() return writer_; } +template +prefix_ typename senf::ppi::module::ActiveSocketSink::Handle +senf::ppi::module::ActiveSocketSink::handle() +{ + return handle_; +} + +template +prefix_ void senf::ppi::module::ActiveSocketSink::handle(Handle handle) +{ + handle_ = handle; + event_.set(handle_, IOEvent::Write); +} + /////////////////////////////////////////////////////////////////////////// // senf::ppi::module::PassiveSocketSink @@ -55,10 +69,20 @@ prefix_ typename Writer::Handle & senf::ppi::module::PassiveSocketSink:: } template -prefix_ void senf::ppi::module::PassiveSocketSink::replaceHandle(Handle handle) +prefix_ void senf::ppi::module::PassiveSocketSink::handle(Handle handle) { handle_ = handle; + checkThrottle(); } + +#ifndef DOXYGEN +template +prefix_ void senf::ppi::module::PassiveSocketSink::replaceHandle(Handle newHandle) +{ + handle(newHandle); +} +#endif + ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/PPI/SocketSink.hh b/PPI/SocketSink.hh index 742e2db..83a1d5f 100644 --- a/PPI/SocketSink.hh +++ b/PPI/SocketSink.hh @@ -166,7 +166,16 @@ namespace module { connector::ActiveInput<> input; ///< Input connector from which data is received - ActiveSocketSink(Handle handle); ///< Create new writer for the given handle + ActiveSocketSink(); ///< Create non-connected writer + /**< The writer will be disabled until a socket is set + \pre Requires \a Writer to be default constructible */ + explicit ActiveSocketSink(Writer const & writer); + ///< Create non-connected writer + /**< The writer will be disabled until a socket is set + \pre Requires \a Writer to be copy constructible + \param[in] writer Writer helper writing packet date to + the socket */ + explicit ActiveSocketSink(Handle handle); ///< Create new writer for the given handle /**< Data will be written to \a handle using \a Writer. \pre Requires \a Writer to be default constructible \param[in] handle Handle to write data to */ @@ -175,10 +184,15 @@ namespace module { /**< Data will be written to \a handle using \a Writer. \pre Requires \a Writer to be copy constructible \param[in] handle Handle to write data to - \param[in] writer Writer helper writing packet date to the - socket */ + \param[in] writer Writer helper writing packet date to + the socket */ + + Writer & writer(); ///< Access the Writer + 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. */ - Writer & writer(); ///< Access the Writer private: void write(); @@ -227,7 +241,16 @@ namespace module { connector::PassiveInput<> input; ///< Input connector from which data is received - PassiveSocketSink(Handle handle); ///< Create new writer for the given handle + PassiveSocketSink(); ///< Create non-connected writer + /**< The writer will be disabled until a socket is set + \pre Requires \a Writer to be default constructible */ + explicit PassiveSocketSink(Writer const & writer); + ///< Create non-connected writer + /**< The writer will be disabled until a socket is set + \pre Requires \a Writer to be copy constructible + \param[in] writer Writer helper writing packet date to + the socket */ + explicit PassiveSocketSink(Handle handle); ///< Create new writer for the given handle /**< Data will be written to \a handle using \a Writer. \pre Requires \a Writer to be default constructible \param[in] handle Handle to write data to */ @@ -235,22 +258,23 @@ namespace module { ///< Create new writer for the given handle /**< Data will be written to \a handle using \a Writer. \pre Requires \a Writer to be copy constructible - \param[in] handle Handle to write data to */ + \param[in] handle Handle to write data to + \param[in] writer Writer helper writing packet date to + the socket */ + + Writer & writer(); ///< Access the Writer + 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. */ - Writer & writer(); ///< Access the Writer - Handle & handle(); /**< Access the handle. This is intendet to be mainly used to reconnect - the underlying socket. */ - /* void reconnect(senf::SocketAddress newAddress); - ///< Reconnect the handle to which the packets are written - */ +#ifndef DOXYGEN void replaceHandle(Handle newHandle); - /**< Replace the handle to which the packets are written - * Normally you should access the handle and call connect with - * the new address. This also works for other - * (active) ConnectedSocketSinks/Sources */ +#endif private: void write(); + void checkThrottle(); Handle handle_; Writer writer_;