Skip to content
Snippets Groups Projects
Commit 7970df7e authored by dw6's avatar dw6
Browse files

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
parent 6e4e6494
No related branches found
No related tags found
No related merge requests found
...@@ -24,18 +24,34 @@ ...@@ -24,18 +24,34 @@
\brief SocketSink inline non-template implementation */ \brief SocketSink inline non-template implementation */
// Custom includes // Custom includes
#include "SocketSink.hh"
#define prefix_ inline #define prefix_ inline
///////////////////////////////cci.p/////////////////////////////////////// ///////////////////////////////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()); handle.write(packet.data());
} }
///////////////////////////////////////////////////////////////////////////
// senf::ppi::module::PassiveSocketSink<Writer>
template <class Writer>
prefix_ void senf::ppi::module::PassiveSocketSink<Writer>::replaceHandle(Handle handle)
{
handle_ = handle;
}
template <class Writer>
prefix_ void senf::ppi::module::ActiveSocketSink<Writer>::replaceHandle(Handle handle)
{
handle_ = handle;
}
///////////////////////////////cci.e/////////////////////////////////////// ///////////////////////////////cci.e///////////////////////////////////////
#undef prefix_ #undef prefix_
......
...@@ -31,20 +31,20 @@ ...@@ -31,20 +31,20 @@
///////////////////////////////ct.p//////////////////////////////////////// ///////////////////////////////ct.p////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// senf::ppi::module::ActiveSocketSink<Sink> // senf::ppi::module::ActiveSocketSink<Writer>
template <class Sink> template <class Writer>
prefix_ senf::ppi::module::ActiveSocketSink<Sink>::ActiveSocketSink(Handle handle) prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Handle handle)
: handle_(handle), event_(handle_, IOEvent::Write), writer_() : handle_(handle), event_(handle_, IOEvent::Write), writer_()
{ {
registerEvent( event_, &ActiveSocketSink::write ); registerEvent( event_, &ActiveSocketSink::write );
route(input, event_); route(input, event_);
} }
template <class Sink> template <class Writer>
prefix_ senf::ppi::module::ActiveSocketSink<Sink>::ActiveSocketSink(Handle handle, prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Handle handle,
Sink const & sink) Writer const & writer)
: handle_(handle), event_(handle_, IOEvent::Write), writer_(sink) : handle_(handle), event_(handle_, IOEvent::Write), writer_(writer)
{ {
registerEvent( event_, &ActiveSocketSink::write ); registerEvent( event_, &ActiveSocketSink::write );
route(input, event_); route(input, event_);
...@@ -53,27 +53,27 @@ prefix_ senf::ppi::module::ActiveSocketSink<Sink>::ActiveSocketSink(Handle handl ...@@ -53,27 +53,27 @@ prefix_ senf::ppi::module::ActiveSocketSink<Sink>::ActiveSocketSink(Handle handl
//////////////////////////////////////// ////////////////////////////////////////
// private members // private members
template <class Sink> template <class Writer>
prefix_ void senf::ppi::module::ActiveSocketSink<Sink>::write() prefix_ void senf::ppi::module::ActiveSocketSink<Writer>::write()
{ {
writer_(handle_,input()); writer_(handle_,input());
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// senf::ppi::module::PassiveSocketSink<Sink> // senf::ppi::module::PassiveSocketSink<Writer>
template <class Sink> template <class Writer>
prefix_ senf::ppi::module::PassiveSocketSink<Sink>::PassiveSocketSink(Handle handle) prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Handle handle)
: handle_(handle), writer_() : handle_(handle), writer_()
{ {
noroute(input); noroute(input);
input.onRequest(&PassiveSocketSink::write); input.onRequest(&PassiveSocketSink::write);
} }
template <class Sink> template <class Writer>
prefix_ senf::ppi::module::PassiveSocketSink<Sink>::PassiveSocketSink(Handle handle, prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Handle handle,
Sink const & sink) Writer const & writer)
: handle_(handle), writer_(sink) : handle_(handle), writer_(writer)
{ {
noroute(input); noroute(input);
input.onRequest(&PassiveSocketSink::write); input.onRequest(&PassiveSocketSink::write);
...@@ -82,8 +82,8 @@ prefix_ senf::ppi::module::PassiveSocketSink<Sink>::PassiveSocketSink(Handle han ...@@ -82,8 +82,8 @@ prefix_ senf::ppi::module::PassiveSocketSink<Sink>::PassiveSocketSink(Handle han
//////////////////////////////////////// ////////////////////////////////////////
// private members // private members
template <class Sink> template <class Writer>
prefix_ void senf::ppi::module::PassiveSocketSink<Sink>::write() prefix_ void senf::ppi::module::PassiveSocketSink<Writer>::write()
{ {
writer_(handle_,input()); writer_(handle_,input());
} }
......
...@@ -31,19 +31,19 @@ ...@@ -31,19 +31,19 @@
///////////////////////////////cti.p/////////////////////////////////////// ///////////////////////////////cti.p///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// senf::ppi::module::ActiveSocketSink<Sink> // senf::ppi::module::ActiveSocketSink<Writer>
template <class Sink> template <class Writer>
prefix_ Sink & senf::ppi::module::ActiveSocketSink<Sink>::sink() prefix_ Writer & senf::ppi::module::ActiveSocketSink<Writer>::writer()
{ {
return writer_; return writer_;
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// senf::ppi::module::PassiveSocketSink<Sink> // senf::ppi::module::PassiveSocketSink<Writer>
template <class Sink> template <class Writer>
prefix_ Sink & senf::ppi::module::PassiveSocketSink<Sink>::sink() prefix_ Writer & senf::ppi::module::PassiveSocketSink<Writer>::writer()
{ {
return writer_; return writer_;
} }
......
...@@ -42,11 +42,11 @@ ...@@ -42,11 +42,11 @@
namespace senf { namespace senf {
namespace ppi { 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: public:
typedef senf::ClientSocketHandle< typedef senf::ClientSocketHandle<
...@@ -69,119 +69,125 @@ namespace senf { ...@@ -69,119 +69,125 @@ namespace senf {
namespace ppi { namespace ppi {
namespace module { 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 output module is active. This requires the file handle to be able to signal its readiness to
accept more data via the Scheduler. 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. the file handle.
A \a Sink must fulfill the following interface: A \a Writer must fulfill the following interface:
\code \code
class SomeSink class SomeWriter
{ {
public: public:
typedef unspecified Handle; // type of handle requested typedef unspecified Handle; // type of handle requested
SomeSink(); // EITHER default constructible OR SomeWriter(); // EITHER default constructible OR
SomeSink(SomeSink const & other); // copy constructible SomeWriter(SomeWriter const & other); // copy constructible
void operator()(Handle handle, Packet packet); // insertion function void operator()(Handle handle, Packet packet); // insertion function
}; };
\endcode \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 \ingroup io_modules
*/ */
template <class Sink=PacketSink> template <class Writer=ConnectedDgramWriter>
class ActiveSocketSink : public Module class ActiveSocketSink : public Module
{ {
SENF_PPI_MODULE(ActiveSocketSink); SENF_PPI_MODULE(ActiveSocketSink);
public: 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 connector::ActiveInput input; ///< Input connector from which data is received
ActiveSocketSink(Handle handle); ///< Create new writer for the given handle ActiveSocketSink(Handle handle); ///< Create new writer for the given handle
/**< Data will be written to \a handle using \a Sink. /**< Data will be written to \a handle using \a Writer.
\pre Requires \a Sink to be default constructible \pre Requires \a Writer to be default constructible
\param[in] handle Handle to write data to */ \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 ///< Create new writer for the given handle
/**< Data will be written to \a handle using \a Sink. /**< Data will be written to \a handle using \a Writer.
\pre Requires \a Sink to be copy constructible \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] sink Sink helper writing packet date to the \param[in] writer Writer helper writing packet date to the
socket */ 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: private:
void write(); void write();
Handle handle_; Handle handle_;
IOEvent event_; 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 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 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 mechanism. Either this is desired (like for a UDP socket) or some additional bandwidth
shaping needs to be used. 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 file handle.
The \a Sink must fulfill the following interface: The \a Writer must fulfill the following interface:
\code \code
class SomeSink class SomeWriter
{ {
public: public:
typedef unspecified Handle; // type of handle requested typedef unspecified Handle; // type of handle requested
SomeSink(); // EITHER default constructible SomeWriter(); // EITHER default constructible
SomeSink(SomeSink const & other); // OR copy constructible SomeWriter(SomeWriter const & other); // OR copy constructible
void operator()(Handle handle, Packet packet); // insertion function void operator()(Handle handle, Packet packet); // insertion function
}; };
\endcode \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 \ingroup io_modules
*/ */
template <class Sink=PacketSink> template <class Writer=ConnectedDgramWriter>
class PassiveSocketSink : public Module class PassiveSocketSink : public Module
{ {
SENF_PPI_MODULE(PassiveSocketSink); SENF_PPI_MODULE(PassiveSocketSink);
public: 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 connector::PassiveInput input; ///< Input connector from which data is received
PassiveSocketSink(Handle handle); ///< Create new writer for the given handle PassiveSocketSink(Handle handle); ///< Create new writer for the given handle
/**< Data will be written to \a handle using \a Sink. /**< Data will be written to \a handle using \a Writer.
\pre Requires \a Sink to be default constructible \pre Requires \a Writer to be default constructible
\param[in] handle Handle to write data to */ \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 ///< Create new writer for the given handle
/**< Data will be written to \a handle using \a Sink. /**< Data will be written to \a handle using \a Writer.
\pre Requires \a Sink to be copy constructible \pre Requires \a Writer to be copy constructible
\param[in] handle Handle to write data to */ \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: private:
void write(); void write();
Handle handle_; Handle handle_;
Sink writer_; Writer writer_;
}; };
}}} }}}
......
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum NETwork research (NET)
// David Wagner <david.wagner@fokus.fraunhofer.de>
//
/** \file
\brief SocketSource inline non-template implementation */
// Custom includes
#include "SocketSource.hh"
#define prefix_ inline
///////////////////////////////cci.p///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// senf::ppi::module::ActiveSocketSource<Reader>
template <class Writer>
prefix_ void senf::ppi::module::ActiveSocketSource<Reader>::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:
...@@ -31,10 +31,10 @@ ...@@ -31,10 +31,10 @@
///////////////////////////////ct.p//////////////////////////////////////// ///////////////////////////////ct.p////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// senf::ppi::PacketSource<Packet> // senf::ppi::DgramReader<Packet>
template <class Packet> template <class Packet>
prefix_ Packet senf::ppi::PacketSource<Packet>::operator()(Handle handle) prefix_ Packet senf::ppi::DgramReader<Packet>::operator()(Handle handle)
{ {
Packet packet (Packet::create(Packet::noinit)); Packet packet (Packet::create(Packet::noinit));
handle.read(packet.data(),0u); handle.read(packet.data(),0u);
...@@ -42,10 +42,10 @@ prefix_ Packet senf::ppi::PacketSource<Packet>::operator()(Handle handle) ...@@ -42,10 +42,10 @@ prefix_ Packet senf::ppi::PacketSource<Packet>::operator()(Handle handle)
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// senf::ppi::module::ActiveSocketSource<Source> // senf::ppi::module::ActiveSocketSource<Reader>
template <class Source> template <class Reader>
prefix_ senf::ppi::module::ActiveSocketSource<Source>:: prefix_ senf::ppi::module::ActiveSocketSource<Reader>::
ActiveSocketSource(Handle handle) ActiveSocketSource(Handle handle)
: handle_(handle), event_(handle_, IOEvent::Read), reader_() : handle_(handle), event_(handle_, IOEvent::Read), reader_()
{ {
...@@ -53,10 +53,10 @@ ActiveSocketSource(Handle handle) ...@@ -53,10 +53,10 @@ ActiveSocketSource(Handle handle)
route(event_, output); route(event_, output);
} }
template <class Source> template <class Reader>
prefix_ senf::ppi::module::ActiveSocketSource<Source>::ActiveSocketSource(Handle handle, prefix_ senf::ppi::module::ActiveSocketSource<Reader>::ActiveSocketSource(Handle handle,
Source source) Reader reader)
: handle_(handle), event_(handle_, IOEvent::Read), reader_(source) : handle_(handle), event_(handle_, IOEvent::Read), reader_(reader)
{ {
registerEvent( event_, &ActiveSocketSource::read ); registerEvent( event_, &ActiveSocketSource::read );
route(event_, output); route(event_, output);
...@@ -65,8 +65,8 @@ prefix_ senf::ppi::module::ActiveSocketSource<Source>::ActiveSocketSource(Handle ...@@ -65,8 +65,8 @@ prefix_ senf::ppi::module::ActiveSocketSource<Source>::ActiveSocketSource(Handle
//////////////////////////////////////// ////////////////////////////////////////
// private members // private members
template <class Source> template <class Reader>
prefix_ void senf::ppi::module::ActiveSocketSource<Source>::read() prefix_ void senf::ppi::module::ActiveSocketSource<Reader>::read()
{ {
output(reader_(handle_)); output(reader_(handle_));
} }
......
...@@ -31,10 +31,10 @@ ...@@ -31,10 +31,10 @@
///////////////////////////////cti.p/////////////////////////////////////// ///////////////////////////////cti.p///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// senf::ppi::module::ActiveSocketSource<Source> // senf::ppi::module::ActiveSocketSource<Reader>
template <class Source> template <class Reader>
prefix_ Source & senf::ppi::module::ActiveSocketSource<Source>::source() prefix_ Reader & senf::ppi::module::ActiveSocketSource<Reader>::reader()
{ {
return reader_; return reader_;
} }
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
namespace senf { namespace senf {
namespace ppi { 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 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 interpreted as a packet of type \a Packet as defined in the packet library. \a Packet
...@@ -50,7 +50,7 @@ namespace ppi { ...@@ -50,7 +50,7 @@ namespace ppi {
into a packet data structure. into a packet data structure.
*/ */
template <class Packet=DataPacket> template <class Packet=DataPacket>
class PacketSource class DgramReader
{ {
public: public:
typedef senf::ClientSocketHandle< typedef senf::ClientSocketHandle<
...@@ -76,63 +76,66 @@ namespace module { ...@@ -76,63 +76,66 @@ namespace module {
/** \brief Input module reading data from an arbitrary FileHandle /** \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 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 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 \code
senf::ppi::module::ActiveSocketSource< senf::ppi::PacketSource<senf::EthernetPacket> > reader; senf::ppi::module::ActiveSocketSource< senf::ppi::DgramReader<senf::EthernetPacket> > source;
\endcode \endcode
declares a \a reader module reading senf::EthrtnetPacket's. 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 \code
class SomeSource class SomeReader
{ {
public: public:
typedef unspecified_type Handle; // type of handle requested typedef unspecified_type Handle; // type of handle requested
SomeSource(); // EITHER default constructible SomeReader(); // EITHER default constructible
SomeSource(SomeSource const & other); // OR copy constructible SomeReader(SomeReader const & other); // OR copy constructible
Packet operator()(Handle handle); // extraction function Packet operator()(Handle handle); // extraction function
}; };
\endcode \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. to read a packet.
\ingroup io_modules \ingroup io_modules
*/ */
template <class Source=PacketSource<> > template <class Reader=DgramReader<> >
class ActiveSocketSource class ActiveSocketSource
: public Module : public Module
{ {
SENF_PPI_MODULE(ActiveSocketSource); SENF_PPI_MODULE(ActiveSocketSource);
public: 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 connector::ActiveOutput output; ///< Output connector to which the data received is written
ActiveSocketSource(Handle handle); ///< Create new reader for the given handle ActiveSocketSource(Handle handle); ///< Create new reader for the given handle
/**< Data will be read from \a handle and be parsed by \a /**< Data will be read from \a handle and be parsed by \a
Source. Reader.
\pre Requires \a Source to be default constructible \pre Requires \a Reader to be default constructible
\param[in] handle Handle to read data from */ \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 ///< Create new reader for the given handle
/**< Data will be read from \a handle and be parsed by \a /**< Data will be read from \a handle and be parsed by \a
Source. Reader.
\pre Requires \a Source to be copy constructible \pre Requires \a Reader to be copy constructible
\param[in] handle Handle to read data from */ \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: private:
void read(); void read();
Handle handle_; Handle handle_;
IOEvent event_; IOEvent event_;
Source reader_; Reader reader_;
}; };
}}} }}}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment