4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief SocketSource public header */
31 #ifndef HH_SENF_PPI_SocketSource_
32 #define HH_SENF_PPI_SocketSource_ 1
35 #include <senf/Packets/Packets.hh>
36 #include <senf/Socket/ClientSocketHandle.hh>
37 #include <senf/Socket/SocketPolicy.hh>
38 #include <senf/Socket/ReadWritePolicy.hh>
39 #include <senf/Socket/FramingPolicy.hh>
41 #include "Connectors.hh"
44 //#include "SocketSource.mpp"
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
50 /** \brief Reader for module::ActiveSocketSource
52 This read helper will read a datagram from a datagram socket. This datagram will then be
53 interpreted as a packet of type \a Packet as defined in the packet library. \a Packet
54 defaults to DataPacket (type DataPacketType), which will place the data uninterpreted
55 into a packet data structure.
57 template <class Packet=DataPacket, unsigned MaxSize=0u>
61 typedef Packet PacketType;
62 typedef senf::ClientSocketHandle<
63 senf::MakeSocketPolicy< senf::ReadablePolicy,
64 senf::DatagramFramingPolicy >::policy > Handle;
65 ///< Handle type supported by this reader
67 Packet operator()(Handle & handle);
68 ///< Read packet from \a handle
69 /**< Read a datagram from \a handle and interpret is as
70 packet of type \c Packet.
71 \param[in] handle Handle to read data from
72 \returns Pointer to new packet instance or 0, if no
73 packet could be read */
82 /** \brief Input module reading data from an arbitrary FileHandle
84 This input module will read data from a FileHandle object and parse the data according to
85 the \a Reader. The default reader is senf::ppi::DgramReader <> which reads the data into a
86 senf::DataPacket. To parse the data according to some other packet type, pass that packet
87 type to senf::ppi::DgramReader:
89 senf::ppi::module::ActiveSocketSource< senf::ppi::DgramReader<senf::EthernetPacket> > source;
91 declares a \a reader module reading senf::EthernetPacket's
93 A \a Reader must fulfill the following interface:
98 typedef unspecified_type Handle; // type of handle requested
99 typedef unspecified_type PacketType // type of packet returned
101 SomeReader(); // EITHER default constructible
102 SomeReader(SomeReader const & other); // OR copy constructible
104 PacketType operator()(Handle handle); // extraction function
107 Whenever the FileHandle object is ready for reading, the \a Reader's \c operator() is called
112 template <class Reader=DgramReader<> >
113 class ActiveSocketSource
116 SENF_PPI_MODULE(ActiveSocketSource);
119 typedef typename Reader::Handle Handle; ///< Handle type requested by the reader
121 connector::ActiveOutput<typename Reader::PacketType> output;
122 ///< Output connector to which the data received is written
124 ActiveSocketSource(); ///< Create non-connected reader
125 /**< The reader will be disabled until a socket is set
126 \pre Requires \a Reader to be default constructible */
127 explicit ActiveSocketSource(Reader reader); ///< Create non-connected reader
128 /**< The reader will be disabled until a socket is set
129 \pre Requires \a Reader to be copy constructible */
130 explicit ActiveSocketSource(Handle const & handle);
131 ///< Create new reader for the given handle
132 /**< Data will be read from \a handle and be parsed by \a
134 \pre Requires \a Reader to be default constructible
135 \param[in] handle Handle to read data from */
136 ActiveSocketSource(Handle const & handle, Reader reader);
137 ///< Create new reader for the given handle
138 /**< Data will be read from \a handle and be parsed by \a
140 \pre Requires \a Reader to be copy constructible
141 \param[in] handle Handle to read data from */
143 Reader & reader(); ///< Access Reader helper
144 Handle handle(); ///< Access handle
145 void handle(Handle const & handle);
147 /**< Assigning an empty or in-valid() handle will disable
148 the module until a new, valid handle is assigned. */
159 template <class Reader=DgramReader<> >
160 class ActiveBurstSocketSource
163 SENF_PPI_MODULE(ActiveBurstSocketSource);
166 typedef typename Reader::Handle Handle; ///< Handle type requested by the reader
168 connector::ActiveOutput<typename Reader::PacketType> output;
169 ///< Output connector to which the data received is written
171 ActiveBurstSocketSource(unsigned max_burst=0);
172 explicit ActiveBurstSocketSource(Reader reader, unsigned max_burst=0);
173 explicit ActiveBurstSocketSource(Handle const & handle, unsigned max_burst=0);
174 ActiveBurstSocketSource(Handle const & handle, Reader reader, unsigned max_burst=0);
176 Reader & reader(); ///< Access Reader helper
177 Handle handle(); ///< Access handle
178 void handle(Handle const & handle);
180 /**< Assigning an empty or in-valid() handle will disable
181 the module until a new, valid handle is assigned. */
183 unsigned maxBurst() const;
184 void maxBurst(unsigned max_burst);
199 //-/////////////////////////////////////////////////////////////////////////////////////////////////
200 //#include "SocketSource.cci"
201 #include "SocketSource.ct"
202 #include "SocketSource.cti"
209 // c-file-style: "senf"
210 // indent-tabs-mode: nil
211 // ispell-local-dictionary: "american"
212 // compile-command: "scons -u test"
213 // comment-column: 40