\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<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///////////////////////////////////////
#undef prefix_
///////////////////////////////ct.p////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
-// senf::ppi::module::ActiveSocketSink<Sink>
+// senf::ppi::module::ActiveSocketSink<Writer>
-template <class Sink>
-prefix_ senf::ppi::module::ActiveSocketSink<Sink>::ActiveSocketSink(Handle handle)
+template <class Writer>
+prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Handle handle)
: handle_(handle), event_(handle_, IOEvent::Write), writer_()
{
registerEvent( event_, &ActiveSocketSink::write );
route(input, event_);
}
-template <class Sink>
-prefix_ senf::ppi::module::ActiveSocketSink<Sink>::ActiveSocketSink(Handle handle,
- Sink const & sink)
- : handle_(handle), event_(handle_, IOEvent::Write), writer_(sink)
+template <class Writer>
+prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Handle handle,
+ Writer const & writer)
+ : handle_(handle), event_(handle_, IOEvent::Write), writer_(writer)
{
registerEvent( event_, &ActiveSocketSink::write );
route(input, event_);
////////////////////////////////////////
// private members
-template <class Sink>
-prefix_ void senf::ppi::module::ActiveSocketSink<Sink>::write()
+template <class Writer>
+prefix_ void senf::ppi::module::ActiveSocketSink<Writer>::write()
{
writer_(handle_,input());
}
///////////////////////////////////////////////////////////////////////////
-// senf::ppi::module::PassiveSocketSink<Sink>
+// senf::ppi::module::PassiveSocketSink<Writer>
-template <class Sink>
-prefix_ senf::ppi::module::PassiveSocketSink<Sink>::PassiveSocketSink(Handle handle)
+template <class Writer>
+prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Handle handle)
: handle_(handle), writer_()
{
noroute(input);
input.onRequest(&PassiveSocketSink::write);
}
-template <class Sink>
-prefix_ senf::ppi::module::PassiveSocketSink<Sink>::PassiveSocketSink(Handle handle,
- Sink const & sink)
- : handle_(handle), writer_(sink)
+template <class Writer>
+prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Handle handle,
+ Writer const & writer)
+ : handle_(handle), writer_(writer)
{
noroute(input);
input.onRequest(&PassiveSocketSink::write);
////////////////////////////////////////
// private members
-template <class Sink>
-prefix_ void senf::ppi::module::PassiveSocketSink<Sink>::write()
+template <class Writer>
+prefix_ void senf::ppi::module::PassiveSocketSink<Writer>::write()
{
writer_(handle_,input());
}
///////////////////////////////cti.p///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
-// senf::ppi::module::ActiveSocketSink<Sink>
+// senf::ppi::module::ActiveSocketSink<Writer>
-template <class Sink>
-prefix_ Sink & senf::ppi::module::ActiveSocketSink<Sink>::sink()
+template <class Writer>
+prefix_ Writer & senf::ppi::module::ActiveSocketSink<Writer>::writer()
{
return writer_;
}
///////////////////////////////////////////////////////////////////////////
-// senf::ppi::module::PassiveSocketSink<Sink>
+// senf::ppi::module::PassiveSocketSink<Writer>
-template <class Sink>
-prefix_ Sink & senf::ppi::module::PassiveSocketSink<Sink>::sink()
+template <class Writer>
+prefix_ Writer & senf::ppi::module::PassiveSocketSink<Writer>::writer()
{
return writer_;
}
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<
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 <class Sink=PacketSink>
+ template <class Writer=ConnectedDgramWriter>
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 <class Sink=PacketSink>
+ template <class Writer=ConnectedDgramWriter>
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_;
};
}}}
--- /dev/null
+// 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_
+
+\f
+// 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:
///////////////////////////////ct.p////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
-// senf::ppi::PacketSource<Packet>
+// senf::ppi::DgramReader<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));
handle.read(packet.data(),0u);
}
///////////////////////////////////////////////////////////////////////////
-// senf::ppi::module::ActiveSocketSource<Source>
+// senf::ppi::module::ActiveSocketSource<Reader>
-template <class Source>
-prefix_ senf::ppi::module::ActiveSocketSource<Source>::
+template <class Reader>
+prefix_ senf::ppi::module::ActiveSocketSource<Reader>::
ActiveSocketSource(Handle handle)
: handle_(handle), event_(handle_, IOEvent::Read), reader_()
{
route(event_, output);
}
-template <class Source>
-prefix_ senf::ppi::module::ActiveSocketSource<Source>::ActiveSocketSource(Handle handle,
- Source source)
- : handle_(handle), event_(handle_, IOEvent::Read), reader_(source)
+template <class Reader>
+prefix_ senf::ppi::module::ActiveSocketSource<Reader>::ActiveSocketSource(Handle handle,
+ Reader reader)
+ : handle_(handle), event_(handle_, IOEvent::Read), reader_(reader)
{
registerEvent( event_, &ActiveSocketSource::read );
route(event_, output);
////////////////////////////////////////
// private members
-template <class Source>
-prefix_ void senf::ppi::module::ActiveSocketSource<Source>::read()
+template <class Reader>
+prefix_ void senf::ppi::module::ActiveSocketSource<Reader>::read()
{
output(reader_(handle_));
}
///////////////////////////////cti.p///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
-// senf::ppi::module::ActiveSocketSource<Source>
+// senf::ppi::module::ActiveSocketSource<Reader>
-template <class Source>
-prefix_ Source & senf::ppi::module::ActiveSocketSource<Source>::source()
+template <class Reader>
+prefix_ Reader & senf::ppi::module::ActiveSocketSource<Reader>::reader()
{
return reader_;
}
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
into a packet data structure.
*/
template <class Packet=DataPacket>
- class PacketSource
+ class DgramReader
{
public:
typedef senf::ClientSocketHandle<
/** \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<senf::EthernetPacket> > reader;
+ senf::ppi::module::ActiveSocketSource< senf::ppi::DgramReader<senf::EthernetPacket> > 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 <class Source=PacketSource<> >
+ template <class Reader=DgramReader<> >
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_;
};
}}}