4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief SocketSource public header */
26 #ifndef HH_SENF_PPI_SocketSource_
27 #define HH_SENF_PPI_SocketSource_ 1
30 #include "../Packets/Packets.hh"
31 #include "../Socket/ClientSocketHandle.hh"
32 #include "../Socket/SocketPolicy.hh"
33 #include "../Socket/ReadWritePolicy.hh"
34 #include "../Socket/FramingPolicy.hh"
36 #include "Connectors.hh"
39 //#include "SocketSource.mpp"
40 ///////////////////////////////hh.p////////////////////////////////////////
45 /** \brief Reader for module::ActiveSocketSource
47 This read helper will read a datagram from a datagram socket. This datagram will then be
48 interpreted as a packet of type \a Packet as defined in the packet library. \a Packet
49 defaults to DataPacket (type DataPacketType), which will place the data uninterpreted
50 into a packet data structure.
52 template <class Packet=DataPacket>
56 typedef Packet PacketType;
57 typedef senf::ClientSocketHandle<
58 senf::MakeSocketPolicy< senf::ReadablePolicy,
59 senf::DatagramFramingPolicy >::policy > Handle;
60 ///< Handle type supported by this reader
62 Packet operator()(Handle handle);
63 ///< Read packet from \a handle
64 /**< Read a datagram from \a handle and interpret is as
65 packet of type \c Packet.
66 \param[in] handle Handle to read data from
67 \returns Pointer to new packet instance or 0, if no
68 packet could be read */
77 /** \brief Input module reading data from an arbitrary FileHandle
79 This input module will read data from a FileHandle object and parse the data according to
80 the \a Reader. The default reader is senf::ppi::DgramReader <> which reads the data into a
81 senf::DataPacket. To parse the data according to some other packet type, pass that packet
82 type to senf::ppi::DgramReader:
84 senf::ppi::module::ActiveSocketSource< senf::ppi::DgramReader<senf::EthernetPacket> > source;
86 declares a \a reader module reading senf::EthernetPacket's
88 A \a Reader must fulfill the following interface:
93 typedef unspecified_type Handle; // type of handle requested
95 SomeReader(); // EITHER default constructible
96 SomeReader(SomeReader const & other); // OR copy constructible
98 Packet operator()(Handle handle); // extraction function
101 Whenever the FileHandle object is ready for reading, the \a Reader's \c operator() is called
106 template <class Reader=DgramReader<> >
107 class ActiveSocketSource
110 SENF_PPI_MODULE(ActiveSocketSource);
113 typedef typename Reader::Handle Handle; ///< Handle type requested by the reader
115 connector::ActiveOutput<typename Reader::PacketType> output;
116 ///< Output connector to which the data received is written
118 ActiveSocketSource(Handle handle); ///< Create new reader for the given handle
119 /**< Data will be read from \a handle and be parsed by \a
121 \pre Requires \a Reader to be default constructible
122 \param[in] handle Handle to read data from */
123 ActiveSocketSource(Handle handle, Reader reader);
124 ///< Create new reader for the given handle
125 /**< Data will be read from \a handle and be parsed by \a
127 \pre Requires \a Reader to be copy constructible
128 \param[in] handle Handle to read data from */
130 Reader & reader(); ///< Access Reader helper
142 ///////////////////////////////hh.e////////////////////////////////////////
143 //#include "SocketSource.cci"
144 #include "SocketSource.ct"
145 #include "SocketSource.cti"
152 // c-file-style: "senf"
153 // indent-tabs-mode: nil
154 // ispell-local-dictionary: "american"
155 // compile-command: "scons -u test"
156 // comment-column: 40