X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=PPI%2FSocketSource.hh;h=3c78d5851fc9b74b1dc29a7b9d4245cb7d8a848a;hb=5443435c4c2b6e4386c5334b5b8358273f2bae93;hp=cb91adc5242f92576c28be1d12bc55f757c55031;hpb=28275a1a9075ae42dc29aaadc5bc78e6fa204e26;p=senf.git diff --git a/PPI/SocketSource.hh b/PPI/SocketSource.hh index cb91adc..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,63 +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 + typedef unspecified_type PacketType // type of packet returned - 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 + 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. - \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 + 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_; }; }}}