Add new file-variable 'comment-column'
[senf.git] / PPI / SocketWriter.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 SocketWriter public header */
23
24 #ifndef HH_SocketWriter_
25 #define HH_SocketWriter_ 1
26
27 // Custom includes
28 #include "Packets/Packet.hh"
29 #include "Module.hh"
30 #include "Connector.hh"
31
32 //#include "SocketWriter.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36 namespace ppi {
37
38     /** \brief Write helper for module::ActiveSocketWriter / module::PassiveSocketWriter
39         
40         This write helper will write the packets completely as datagrams to the given socket.
41      */
42     class PacketWriter
43     {
44     public:
45         typedef senf::ClientSocketHandle<
46             senf::MakeSocketPolicy< senf::WriteablePolicy,
47                                     senf::DatagramFramingPolicy > > Handle;
48                                         ///< Handle type supported by this writer
49         
50         void operator()(Handle handle, Packet::ptr packet);
51                                         ///< Write \a packet to \a handle
52                                         /**< Write the complete \a packet as a datagram to \a
53                                              handle.
54                                              \param[in] handle Handle to write data to
55                                              \param[in] packet Packet to write */
56     };
57
58 }}
59
60 namespace senf {
61 namespace ppi {
62 namespace module {
63
64     /** \brief Output module writing data to arbitrary FileHandle
65         
66         This output module will write data to a FileHandle object using a given \a Writer. This
67         output module is active. This requires the file handle to be able to signal its readiness to
68         accept more data via the Scheduler.
69
70         The \a Writer must fulfill the following interface:
71         \code
72           class SomeWriter
73           {
74           public:
75               typedef unspecified Handle;                          // type of handle requested
76               SomeWriter();                                        // default constructible
77               void operator()(Handle handle, Packet::ptr packet);  // insertion function
78           };
79         \endcode
80      */
81     template <class Writer=PacketWriter>
82     class ActiveSocketWriter : public Module
83     {
84     public:
85         typedef typename Writer:Handle Handle; ///< Handle type requested by writer
86
87         connector::ActiveInput input; ///< Input connector from which data is received
88         
89         ActiveSocketWriter(Handle handle); ///< Create new writer for the given handle
90                                         /**< Data will be written to \a handle using \a Writer.
91                                              \param[in] handle Handle to write data to */
92     };
93
94     /** \brief Output module writing data to arbitrary FileHandle
95         
96         This output module will write data to a FileHandle object using a given \a Writer. This
97         output module is passive. This implies, that the output handle may not block. This also
98         implies, that data will probably get lost if written to fast for the underlying transport
99         mechanism. Either this is desired (like for a UDP socket) or some additional bandwidth
100         shaping needs to be used.
101
102         The \a Writer must fulfill the following interface:
103         \code
104           class SomeWriter
105           {
106           public:
107               typedef unspecified Handle;                          // type of handle requested
108               SomeWriter();                                        // default constructible
109               void operator()(Handle handle, Packet::ptr packet);  // insertion function
110           };
111         \endcode
112      */
113     template <class Writer=PacketWriter>
114     class PassiveSocketWriter : public Module
115     {
116     public:
117         typedef typename Writer:Handle Handle; ///< Handle type requested by writer
118
119         connector::PassiveInput input; ///< Input connector from which data is received
120         
121         ActiveSocketWriter(Handle handle); ///< Create new writer for the given handle
122                                         /**< Data will be written to \a handle using \a Writer.
123                                              \param[in] handle Handle to write data to */
124     };
125
126 }}}
127
128
129 ///////////////////////////////hh.e////////////////////////////////////////
130 //#include "SocketWriter.cci"
131 //#include "SocketWriter.ct"
132 //#include "SocketWriter.cti"
133 #endif
134
135 \f
136 // Local Variables:
137 // mode: c++
138 // fill-column: 100
139 // c-file-style: "senf"
140 // indent-tabs-mode: nil
141 // ispell-local-dictionary: "american"
142 // compile-command: "scons -u test"
143 // comment-column: 40
144 // End: