2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 // Stefan Bund <g0dil@berlios.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief SocketSource public header */
24 #ifndef HH_SocketSource_
25 #define HH_SocketSource_ 1
28 #include "../Packets/Packets.hh"
29 #include "../Socket/ClientSocketHandle.hh"
30 #include "../Socket/SocketPolicy.hh"
31 #include "../Socket/ReadWritePolicy.hh"
32 #include "../Socket/FramingPolicy.hh"
34 #include "Connectors.hh"
37 //#include "SocketSource.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
43 /** \brief Read helper for module::ActiveSocketSource
45 This read helper will read a datagram from a datagram socket. This datagram will then be
46 interpreted as a packet of type \a Packet as defined in the packet library. \a Packet
47 defaults to DataPacket (type DataPacketType), which will place the data uninterpreted
48 into a packet data structure.
50 template <class Packet=DataPacket>
54 typedef senf::ClientSocketHandle<
55 senf::MakeSocketPolicy< senf::ReadablePolicy,
56 senf::DatagramFramingPolicy >::policy > Handle;
57 ///< Handle type supported by this reader
59 Packet operator()(Handle handle);
60 ///< Read packet from \a handle
61 /**< Read a datagram from \a handle and interpret is as
62 packet of type \c Packet.
63 \param[in] handle Handle to read data from
64 \returns Pointer to new packet instance or 0, if no
65 packet could be read */
74 /** \brief Input module reading data from an arbitrary FileHandle
76 This input module will read data from a FileHandle object and parse the data according to
77 the \a Source. The default reader is senf::ppi::PacketSource <> which reads the data into a
78 senf::DataPacket. To parse the data according to some other packet type, pass that packet
79 type to senf::ppi::PacketSource:
81 senf::ppi::module::ActiveSocketSource< senf::ppi::PacketSource<senf::EthernetPacket> > reader;
83 declares a \a reader module reading senf::EthrtnetPacket's.
85 A \a Source must fulfill the following interface:
90 typedef unspecified_type Handle; // type of handle requested
92 SomeSource(); // EITHER default constructible
93 SomeSource(SomeSource const & other); // OR copy constructible
95 Packet operator()(Handle handle); // extraction function
98 Whenever the FileHandle object is ready for reading, the \a Source's \c operator() is called
103 template <class Source=PacketSource<> >
104 class ActiveSocketSource
107 SENF_PPI_MODULE(ActiveSocketSource);
110 typedef typename Source::Handle Handle; ///< Handle type requested by the reader
112 connector::ActiveOutput output; ///< Output connector to which the data received is written
114 ActiveSocketSource(Handle handle); ///< Create new reader for the given handle
115 /**< Data will be read from \a handle and be parsed by \a
117 \pre Requires \a Source to be default constructible
118 \param[in] handle Handle to read data from */
119 ActiveSocketSource(Handle handle, Source source);
120 ///< Create new reader for the given handle
121 /**< Data will be read from \a handle and be parsed by \a
123 \pre Requires \a Source to be copy constructible
124 \param[in] handle Handle to read data from */
126 Source & source(); ///< Access source helper
138 ///////////////////////////////hh.e////////////////////////////////////////
139 //#include "SocketSource.cci"
140 #include "SocketSource.ct"
141 #include "SocketSource.cti"
148 // c-file-style: "senf"
149 // indent-tabs-mode: nil
150 // ispell-local-dictionary: "american"
151 // compile-command: "scons -u test"
152 // comment-column: 40