X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=PPI%2FSocketSource.hh;h=3c78d5851fc9b74b1dc29a7b9d4245cb7d8a848a;hb=b8ca4a544cce3e6023bb56b712a03d6362f2bb79;hp=de4dbe670d9e1f867123941579d71f82701f77f5;hpb=88b7af123f3faced1235041a506573caded251e8;p=senf.git diff --git a/PPI/SocketSource.hh b/PPI/SocketSource.hh index de4dbe6..3c78d58 100644 --- a/PPI/SocketSource.hh +++ b/PPI/SocketSource.hh @@ -1,6 +1,8 @@ -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -21,8 +23,8 @@ /** \file \brief SocketSource public header */ -#ifndef HH_SocketSource_ -#define HH_SocketSource_ 1 +#ifndef HH_SENF_PPI_SocketSource_ +#define HH_SENF_PPI_SocketSource_ 1 // Custom includes #include "../Packets/Packets.hh" @@ -40,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 @@ -48,9 +50,10 @@ namespace ppi { into a packet data structure. */ template - class PacketSource + class DgramReader { public: + typedef Packet PacketType; typedef senf::ClientSocketHandle< senf::MakeSocketPolicy< senf::ReadablePolicy, senf::DatagramFramingPolicy >::policy > Handle; @@ -74,51 +77,75 @@ 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. + declares a \a reader module reading senf::EthernetPacket'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(); // default constructible - Packet operator()(Handle handle); // extraction function + typedef unspecified_type Handle; // type of handle requested + typedef unspecified_type PacketType // type of packet returned + + SomeReader(); // EITHER default constructible + SomeReader(SomeReader const & other); // OR copy constructible + + PacketType 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 + connector::ActiveOutput output; + ///< Output connector to which the data received is written - ActiveSocketSource(Handle handle); ///< Create new reader for the given handle + ActiveSocketSource(); ///< Create non-connected reader + /**< The reader will be disabled until a socket is set + \pre Requires \a Reader to be default constructible */ + explicit ActiveSocketSource(Reader reader); ///< Create non-connected reader + /**< The reader will be disabled until a socket is set + \pre Requires \a Reader to be copy constructible */ + explicit ActiveSocketSource(Handle handle); ///< Create new reader for the given handle /**< Data will be read from \a handle and be parsed by \a - Source. + Reader. + \pre Requires \a Reader to be default constructible + \param[in] handle Handle to read data from */ + ActiveSocketSource(Handle handle, Reader reader); + ///< Create new reader for the given handle + /**< Data will be read from \a handle and be parsed by \a + Reader. + \pre Requires \a Reader to be copy constructible \param[in] handle Handle to read data from */ + Reader & reader(); ///< Access Reader helper + 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. */ + private: void read(); Handle handle_; IOEvent event_; - Source reader_; + Reader reader_; }; }}} @@ -126,7 +153,7 @@ namespace module { ///////////////////////////////hh.e//////////////////////////////////////// //#include "SocketSource.cci" #include "SocketSource.ct" -//#include "SocketSource.cti" +#include "SocketSource.cti" #endif