switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / PPI / SocketSink.ct
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
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
10 //
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.
14 //
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.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
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.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief SocketSink non-inline template implementation  */
30
31 //#include "SocketSink.ih"
32
33 // Custom includes
34
35 #define prefix_
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::ppi::module::ActiveSocketSink<Writer>
40
41 template <class Writer>
42 prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink()
43 {
44     registerEvent( event_, &ActiveSocketSink::write );
45     route(input, event_);
46 }
47
48 template <class Writer>
49 prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Writer const & writer)
50     : writer_ (writer)
51 {
52     registerEvent( event_, &ActiveSocketSink::write );
53     route(input, event_);
54 }
55
56 template <class Writer>
57 prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Handle const &  handle)
58     : handle_(handle), event_(handle_, IOEvent::Write), writer_()
59 {
60     registerEvent( event_, &ActiveSocketSink::write );
61     route(input, event_);
62 }
63
64 template <class Writer>
65 prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Handle const & handle,
66                                                                     Writer const & writer)
67     : handle_(handle), event_(handle_, IOEvent::Write), writer_(writer)
68 {
69     registerEvent( event_, &ActiveSocketSink::write );
70     route(input, event_);
71 }
72
73 //-/////////////////////////////////////////////////////////////////////////////////////////////////
74 // private members
75
76 template <class Writer>
77 prefix_ void senf::ppi::module::ActiveSocketSink<Writer>::write()
78 {
79     writer_(handle_,input());
80 }
81
82 //-/////////////////////////////////////////////////////////////////////////////////////////////////
83 // senf::ppi::module::PassiveSocketSink<Writer>
84
85 template <class Writer>
86 prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink()
87 {
88     noroute(input);
89     input.onRequest(&PassiveSocketSink::write);
90     checkThrottle();
91 }
92
93 template <class Writer>
94 prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Writer const & writer)
95     : writer_ (writer)
96 {
97     noroute(input);
98     input.onRequest(&PassiveSocketSink::write);
99     checkThrottle();
100 }
101
102 template <class Writer>
103 prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Handle const & handle)
104     : handle_(handle), writer_()
105 {
106     noroute(input);
107     input.onRequest(&PassiveSocketSink::write);
108     checkThrottle();
109 }
110
111 template <class Writer>
112 prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Handle const & handle,
113                                                                       Writer const & writer)
114     : handle_(handle), writer_(writer)
115 {
116     noroute(input);
117     input.onRequest(&PassiveSocketSink::write);
118     checkThrottle();
119 }
120
121 //-/////////////////////////////////////////////////////////////////////////////////////////////////
122 // private members
123
124 template <class Writer>
125 prefix_ void senf::ppi::module::PassiveSocketSink<Writer>::write()
126 {
127     writer_(handle_,input());
128 }
129
130 template <class Writer>
131 prefix_ void senf::ppi::module::PassiveSocketSink<Writer>::checkThrottle()
132 {
133     if (handle_.valid())
134         input.unthrottle();
135     else
136         input.throttle();
137 }
138
139 //-/////////////////////////////////////////////////////////////////////////////////////////////////
140 #undef prefix_
141
142 \f
143 // Local Variables:
144 // mode: c++
145 // fill-column: 100
146 // comment-column: 40
147 // c-file-style: "senf"
148 // indent-tabs-mode: nil
149 // ispell-local-dictionary: "american"
150 // compile-command: "scons -u test"
151 // End: