From: dw6 Date: Tue, 8 Jan 2008 16:06:22 +0000 (+0000) Subject: adding a function to replace the socket handle int the SocketSource / SocketSink. X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=ed0e2329281a50f80be8425938c17515fa70661b;p=senf.git adding a function to replace the socket handle int the SocketSource / SocketSink. renaming the "write helper" / "read helper" classes (formerly named "Sink" / "Source") to Writer and Reader git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@587 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/SocketSink.cci b/PPI/SocketSink.cci index ea9be20..c5c5800 100644 --- a/PPI/SocketSink.cci +++ b/PPI/SocketSink.cci @@ -24,18 +24,34 @@ \brief SocketSink inline non-template implementation */ // Custom includes +#include "SocketSink.hh" #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// -// senf::ppi::PacketSink +// senf::ppi::ConnectedDgramWriter -prefix_ void senf::ppi::PacketSink::operator()(Handle handle, Packet packet) +prefix_ void senf::ppi::ConnectedDgramWriter::operator()(Handle handle, Packet packet) { handle.write(packet.data()); } +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PassiveSocketSink + +template +prefix_ void senf::ppi::module::PassiveSocketSink::replaceHandle(Handle handle) +{ + handle_ = handle; +} + +template +prefix_ void senf::ppi::module::ActiveSocketSink::replaceHandle(Handle handle) +{ + handle_ = handle; +} + ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ diff --git a/PPI/SocketSink.ct b/PPI/SocketSink.ct index ae118be..b6509c2 100644 --- a/PPI/SocketSink.ct +++ b/PPI/SocketSink.ct @@ -31,20 +31,20 @@ ///////////////////////////////ct.p//////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// -// senf::ppi::module::ActiveSocketSink +// senf::ppi::module::ActiveSocketSink -template -prefix_ senf::ppi::module::ActiveSocketSink::ActiveSocketSink(Handle handle) +template +prefix_ senf::ppi::module::ActiveSocketSink::ActiveSocketSink(Handle handle) : handle_(handle), event_(handle_, IOEvent::Write), writer_() { registerEvent( event_, &ActiveSocketSink::write ); route(input, event_); } -template -prefix_ senf::ppi::module::ActiveSocketSink::ActiveSocketSink(Handle handle, - Sink const & sink) - : handle_(handle), event_(handle_, IOEvent::Write), writer_(sink) +template +prefix_ senf::ppi::module::ActiveSocketSink::ActiveSocketSink(Handle handle, + Writer const & writer) + : handle_(handle), event_(handle_, IOEvent::Write), writer_(writer) { registerEvent( event_, &ActiveSocketSink::write ); route(input, event_); @@ -53,27 +53,27 @@ prefix_ senf::ppi::module::ActiveSocketSink::ActiveSocketSink(Handle handl //////////////////////////////////////// // private members -template -prefix_ void senf::ppi::module::ActiveSocketSink::write() +template +prefix_ void senf::ppi::module::ActiveSocketSink::write() { writer_(handle_,input()); } /////////////////////////////////////////////////////////////////////////// -// senf::ppi::module::PassiveSocketSink +// senf::ppi::module::PassiveSocketSink -template -prefix_ senf::ppi::module::PassiveSocketSink::PassiveSocketSink(Handle handle) +template +prefix_ senf::ppi::module::PassiveSocketSink::PassiveSocketSink(Handle handle) : handle_(handle), writer_() { noroute(input); input.onRequest(&PassiveSocketSink::write); } -template -prefix_ senf::ppi::module::PassiveSocketSink::PassiveSocketSink(Handle handle, - Sink const & sink) - : handle_(handle), writer_(sink) +template +prefix_ senf::ppi::module::PassiveSocketSink::PassiveSocketSink(Handle handle, + Writer const & writer) + : handle_(handle), writer_(writer) { noroute(input); input.onRequest(&PassiveSocketSink::write); @@ -82,8 +82,8 @@ prefix_ senf::ppi::module::PassiveSocketSink::PassiveSocketSink(Handle han //////////////////////////////////////// // private members -template -prefix_ void senf::ppi::module::PassiveSocketSink::write() +template +prefix_ void senf::ppi::module::PassiveSocketSink::write() { writer_(handle_,input()); } diff --git a/PPI/SocketSink.cti b/PPI/SocketSink.cti index fd4fda8..0c24c9f 100644 --- a/PPI/SocketSink.cti +++ b/PPI/SocketSink.cti @@ -31,19 +31,19 @@ ///////////////////////////////cti.p/////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// -// senf::ppi::module::ActiveSocketSink +// senf::ppi::module::ActiveSocketSink -template -prefix_ Sink & senf::ppi::module::ActiveSocketSink::sink() +template +prefix_ Writer & senf::ppi::module::ActiveSocketSink::writer() { return writer_; } /////////////////////////////////////////////////////////////////////////// -// senf::ppi::module::PassiveSocketSink +// senf::ppi::module::PassiveSocketSink -template -prefix_ Sink & senf::ppi::module::PassiveSocketSink::sink() +template +prefix_ Writer & senf::ppi::module::PassiveSocketSink::writer() { return writer_; } diff --git a/PPI/SocketSink.hh b/PPI/SocketSink.hh index e92b0ea..ed74d9b 100644 --- a/PPI/SocketSink.hh +++ b/PPI/SocketSink.hh @@ -42,11 +42,11 @@ namespace senf { namespace ppi { - /** \brief Write helper for module::ActiveSocketSink / module::PassiveSocketSink + /** \brief Writer for module::ActiveSocketSink / module::PassiveSocketSink - This write helper will write the packets completely as datagrams to the given socket. + This writer will write the packets completely as datagrams to the given socket which must be connected. */ - class PacketSink + class ConnectedDgramWriter { public: typedef senf::ClientSocketHandle< @@ -69,119 +69,125 @@ namespace senf { namespace ppi { namespace module { - /** \brief Output module writing data to arbitrary FileHandle + /** \brief Output module writing data to a FileHandle using the provided Writer. + If using the default ConnectedDgramWriter the filehandle must be writable, connected and + able to handle complete datagrams. - This output module will write data to a FileHandle object using a given \a Sink. This + This output module will write data to a FileHandle object using a given \a Writer. This output module is active. This requires the file handle to be able to signal its readiness to accept more data via the Scheduler. - The default \a Sink is senf::ppi::PacketSink which will write out the complete packet to + The default \a Writer is senf::ppi::ConnectedDgramWriter which will write out the complete packet to the file handle. - A \a Sink must fulfill the following interface: + A \a Writer must fulfill the following interface: \code - class SomeSink + class SomeWriter { public: typedef unspecified Handle; // type of handle requested - SomeSink(); // EITHER default constructible OR - SomeSink(SomeSink const & other); // copy constructible + SomeWriter(); // EITHER default constructible OR + SomeWriter(SomeWriter const & other); // copy constructible void operator()(Handle handle, Packet packet); // insertion function }; \endcode - Whenever a packet is received for sending, the \a Sink's \c operator() is called. + Whenever a packet is received for sending, the \a Writer's \c operator() is called. \ingroup io_modules */ - template + template class ActiveSocketSink : public Module { SENF_PPI_MODULE(ActiveSocketSink); public: - typedef typename Sink::Handle Handle; ///< Handle type requested by writer + typedef typename Writer::Handle Handle; ///< Handle type requested by writer connector::ActiveInput input; ///< Input connector from which data is received 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 + /**< 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 */ - ActiveSocketSink(Handle handle, Sink const & sink); + ActiveSocketSink(Handle handle, Writer const & writer); ///< 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 + /**< 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] sink Sink helper writing packet date to the + \param[in] writer Writer helper writing packet date to the socket */ - Sink & sink(); ///< Access the sink helper - + Writer & writer(); ///< Access the Writer + void replaceHandle(Handle newHandle); + ///< Replace the handle to which the packets are written private: void write(); Handle handle_; IOEvent event_; - Sink writer_; + Writer writer_; }; - /** \brief Output module writing data to arbitrary FileHandle + /** \brief Output module writing data to a FileHandle using the provided \a Writer. + If using the default ConnectedDgramWriter the filehandle must be writable, connected and + able to handle complete datagrams. - This output module will write data to a FileHandle object using a given \a Sink. This + This output module will write data to a FileHandle object using a given \a Writer. This output module is passive. This implies, that the output handle may not block. This also implies, that data will probably get lost if written to fast for the underlying transport mechanism. Either this is desired (like for a UDP socket) or some additional bandwidth shaping needs to be used. - The default \a Sink is senf::ppi::PacketSink which will write out the complete packet to + The default \a Writer is senf::ppi::ConnectedDgramWriter which will write out the complete packet to the file handle. - The \a Sink must fulfill the following interface: + The \a Writer must fulfill the following interface: \code - class SomeSink + class SomeWriter { public: typedef unspecified Handle; // type of handle requested - SomeSink(); // EITHER default constructible - SomeSink(SomeSink const & other); // OR copy constructible + SomeWriter(); // EITHER default constructible + SomeWriter(SomeWriter const & other); // OR copy constructible void operator()(Handle handle, Packet packet); // insertion function }; \endcode - Whenever a packet is received for sending, the \a Sink's \c operator() is called. + Whenever a packet is received for sending, the \a Writer's \c operator() is called. \ingroup io_modules */ - template + template class PassiveSocketSink : public Module { SENF_PPI_MODULE(PassiveSocketSink); public: - typedef typename Sink::Handle Handle; ///< Handle type requested by writer + typedef typename Writer::Handle Handle; ///< Handle type requested by writer connector::PassiveInput input; ///< Input connector from which data is received 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 + /**< 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 */ - PassiveSocketSink(Handle handle, Sink const & sink); + PassiveSocketSink(Handle handle, Writer const & writer); ///< 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 + /**< 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 */ - Sink & sink(); ///< Access the sink helper - + Writer & writer(); ///< Access the Writer + void replaceHandle(Handle newHandle); + ///< Replace the handle to which the packets are written private: void write(); Handle handle_; - Sink writer_; + Writer writer_; }; }}} diff --git a/PPI/SocketSource.cci b/PPI/SocketSource.cci new file mode 100644 index 0000000..0e60dc3 --- /dev/null +++ b/PPI/SocketSource.cci @@ -0,0 +1,36 @@ +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum NETwork research (NET) +// David Wagner +// + +/** \file + \brief SocketSource inline non-template implementation */ + +// Custom includes +#include "SocketSource.hh" + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::ActiveSocketSource + +template +prefix_ void senf::ppi::module::ActiveSocketSource::replaceHandle(Handle handle) +{ + handle_ = handle; +} +///////////////////////////////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/SocketSource.ct b/PPI/SocketSource.ct index d4d7035..1ee66f3 100644 --- a/PPI/SocketSource.ct +++ b/PPI/SocketSource.ct @@ -31,10 +31,10 @@ ///////////////////////////////ct.p//////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// -// senf::ppi::PacketSource +// senf::ppi::DgramReader template -prefix_ Packet senf::ppi::PacketSource::operator()(Handle handle) +prefix_ Packet senf::ppi::DgramReader::operator()(Handle handle) { Packet packet (Packet::create(Packet::noinit)); handle.read(packet.data(),0u); @@ -42,10 +42,10 @@ prefix_ Packet senf::ppi::PacketSource::operator()(Handle handle) } /////////////////////////////////////////////////////////////////////////// -// senf::ppi::module::ActiveSocketSource +// senf::ppi::module::ActiveSocketSource -template -prefix_ senf::ppi::module::ActiveSocketSource:: +template +prefix_ senf::ppi::module::ActiveSocketSource:: ActiveSocketSource(Handle handle) : handle_(handle), event_(handle_, IOEvent::Read), reader_() { @@ -53,10 +53,10 @@ 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) +template +prefix_ senf::ppi::module::ActiveSocketSource::ActiveSocketSource(Handle handle, + Reader reader) + : handle_(handle), event_(handle_, IOEvent::Read), reader_(reader) { registerEvent( event_, &ActiveSocketSource::read ); route(event_, output); @@ -65,8 +65,8 @@ prefix_ senf::ppi::module::ActiveSocketSource::ActiveSocketSource(Handle //////////////////////////////////////// // private members -template -prefix_ void senf::ppi::module::ActiveSocketSource::read() +template +prefix_ void senf::ppi::module::ActiveSocketSource::read() { output(reader_(handle_)); } diff --git a/PPI/SocketSource.cti b/PPI/SocketSource.cti index 0813bc8..53c9fed 100644 --- a/PPI/SocketSource.cti +++ b/PPI/SocketSource.cti @@ -31,10 +31,10 @@ ///////////////////////////////cti.p/////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// -// senf::ppi::module::ActiveSocketSource +// senf::ppi::module::ActiveSocketSource -template -prefix_ Source & senf::ppi::module::ActiveSocketSource::source() +template +prefix_ Reader & senf::ppi::module::ActiveSocketSource::reader() { return reader_; } diff --git a/PPI/SocketSource.hh b/PPI/SocketSource.hh index 7f8d433..b054436 100644 --- a/PPI/SocketSource.hh +++ b/PPI/SocketSource.hh @@ -42,7 +42,7 @@ namespace senf { namespace ppi { - /** \brief Read helper for module::ActiveSocketSource + /** \brief Reader for module::ActiveSocketSource This read helper will read a datagram from a datagram socket. This datagram will then be interpreted as a packet of type \a Packet as defined in the packet library. \a Packet @@ -50,7 +50,7 @@ namespace ppi { into a packet data structure. */ template - class PacketSource + class DgramReader { public: typedef senf::ClientSocketHandle< @@ -76,63 +76,66 @@ namespace module { /** \brief Input module reading data from an arbitrary FileHandle This input module will read data from a FileHandle object and parse the data according to - the \a Source. The default reader is senf::ppi::PacketSource <> which reads the data into a + the \a Reader. The default reader is senf::ppi::DgramReader <> which reads the data into a senf::DataPacket. To parse the data according to some other packet type, pass that packet - type to senf::ppi::PacketSource: + type to senf::ppi::DgramReader: \code - senf::ppi::module::ActiveSocketSource< senf::ppi::PacketSource > reader; + senf::ppi::module::ActiveSocketSource< senf::ppi::DgramReader > source; \endcode declares a \a reader module reading senf::EthrtnetPacket's. - A \a Source must fulfill the following interface: + A \a Reader must fulfill the following interface: \code - class SomeSource + class SomeReader { public: typedef unspecified_type Handle; // type of handle requested - SomeSource(); // EITHER default constructible - SomeSource(SomeSource const & other); // OR copy constructible + SomeReader(); // EITHER default constructible + SomeReader(SomeReader 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 + Whenever the FileHandle object is ready for reading, the \a Reader's \c operator() is called to read a packet. \ingroup io_modules */ - template > + template > class ActiveSocketSource : public Module { SENF_PPI_MODULE(ActiveSocketSource); public: - typedef typename Source::Handle Handle; ///< Handle type requested by the reader + typedef typename Reader::Handle Handle; ///< Handle type requested by the reader connector::ActiveOutput output; ///< Output connector to which the data received is written 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 + Reader. + \pre Requires \a Reader to be default constructible \param[in] handle Handle to read data from */ - ActiveSocketSource(Handle handle, Source source); + ActiveSocketSource(Handle handle, Reader reader); ///< 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 + Reader. + \pre Requires \a Reader to be copy constructible \param[in] handle Handle to read data from */ - Source & source(); ///< Access source helper + Reader & reader(); ///< Access Reader helper + + void replaceHandle(Handle newHandle); + ///< Replace the handle from which the packets are read private: void read(); Handle handle_; IOEvent event_; - Source reader_; + Reader reader_; }; }}}