Add new file-variable 'comment-column'
[senf.git] / PPI / SocketReader.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
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.
10 //
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.
15 //
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.
20
21 /** \file
22     \brief SocketReader public header */
23
24 #ifndef HH_SocketReader_
25 #define HH_SocketReader_ 1
26
27 // Custom includes
28 #include "Packets/Packet.hh"
29 #include "Packets/DataPacket.hh"
30 #include "Module.hh"
31 #include "Connector.hh"
32
33 //#include "SocketReader.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 namespace senf {
37 namespace ppi {
38
39     /** \brief Read helper for module::ActiveSocketReader
40
41         This read helper will read a datagram from a datagram socket. This datagram will then be
42         interpreted as a packet of type \a Packet as defined in the packet library. \a Packet
43         defaults to \ref DataPacket, which will place the data uninterpreted into a packet data
44         structure.
45      */
46     template <class Packet=DataPacket>
47     class PacketReader
48     {
49     public:
50         typedef senf::ClientSocketHandle<
51             senf::MakeSocketPolicy< senf::ReadablePolicy,
52                                     senf::DatagramFramingPolicy > > Handle;
53                                         ///< Handle type supported by this reader
54
55         Packet::ptr operator()(Handle handle);
56                                         ///< Read packet from \a handle
57                                         /**< Read a datagram from \a handle and interpret is as
58                                              packet of type \c Packet.
59                                              \param[in] handle Handle to read data from
60                                              \returns Pointer to new packet instance or 0, if no
61                                                  packet could be read */
62     };
63
64 }}
65
66 namespace senf {
67 namespace ppi {
68 namespace module {
69
70     /** \brief Input module reading data from an arbitrary FileHandle
71
72         This input module will read data from a FileHandle object and parse the data according to
73         the \a Reader.
74         
75         The \a Reader must fulfill the following interface:
76         \code
77           class SomeReader
78           {
79           public:
80               typedef unspecified_type Handle;        // type of handle requested
81               SomeReader();                           // default constructible
82               Packet::ptr operator()(Handle handle);  // extraction function
83           };
84         \endcode
85      */
86     template <class Reader=PacketReader<> >
87     class ActiveSocketReader : public Module
88     {
89     public:
90         typedef typename Reader::Handle Handle; ///< Handle type requested by the reader
91
92         connector::ActiveOutput output; ///< Output connector to which the data received is written
93         
94         ActiveSocketReader(Handle handle); ///< Create new reader for the given handle
95                                         /**< Data will be read from \a handle and be parsed by \a
96                                              Reader.
97                                              \param[in] handle Handle to read data from */
98     };
99
100 }}}
101
102 ///////////////////////////////hh.e////////////////////////////////////////
103 //#include "SocketReader.cci"
104 //#include "SocketReader.ct"
105 //#include "SocketReader.cti"
106 #endif
107
108 \f
109 // Local Variables:
110 // mode: c++
111 // fill-column: 100
112 // c-file-style: "senf"
113 // indent-tabs-mode: nil
114 // ispell-local-dictionary: "american"
115 // compile-command: "scons -u test"
116 // comment-column: 40
117 // End: