NEW FILE HEADER / COPYRIGHT FORMAT
[senf.git] / PPI / Connectors.cc
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY 
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Connectors non-inline non-template implementation */
25
26 #include "Connectors.hh"
27 //#include "Connectors.ih"
28
29 // Custom includes
30 #include "Route.hh"
31
32 //#include "Connectors.mpp"
33 #define prefix_
34 ///////////////////////////////cc.p////////////////////////////////////////
35
36 ///////////////////////////////////////////////////////////////////////////
37 // senf::ppi::connector::PassiveConnector
38
39 ////////////////////////////////////////
40 // private members
41
42 prefix_ void senf::ppi::connector::PassiveConnector::notifyUnthrottle()
43 {
44     if (throttled() && !nativeThrottled_) {
45         Routes::const_iterator i (routes_.begin());
46         Routes::const_iterator const i_end (routes_.end());
47         for (; i != i_end; ++i)
48             if ((*i)->throttled())
49                 break;
50         if (i == i_end) {
51             remoteThrottled_ = false;
52             emitUnthrottle();
53         }
54     } 
55     else
56         remoteThrottled_ = false;
57 }
58
59 ///////////////////////////////////////////////////////////////////////////
60 // senf::ppi::connector::ActiveConnector
61
62 ////////////////////////////////////////
63 // private members
64
65 prefix_ void senf::ppi::connector::ActiveConnector::notifyThrottle()
66 {
67     if (throttleCallback_)
68         throttleCallback_();
69     NotifyRoutes::const_iterator i (notifyRoutes_.begin());
70     NotifyRoutes::const_iterator const i_end (notifyRoutes_.end());
71     for (; i != i_end; ++i)
72         (*i)->notifyThrottle();
73 }
74
75 prefix_ void senf::ppi::connector::ActiveConnector::notifyUnthrottle()
76 {
77     if (unthrottleCallback_)
78         unthrottleCallback_();
79     NotifyRoutes::const_iterator i (notifyRoutes_.begin());
80     NotifyRoutes::const_iterator const i_end (notifyRoutes_.end());
81     for (; i != i_end; ++i)
82         (*i)->notifyUnthrottle();
83 }
84
85 prefix_ void senf::ppi::connector::ActiveConnector::registerRoute(ForwardingRoute & route)
86 {
87     notifyRoutes_.push_back(&route);
88 }
89
90 ///////////////////////////////////////////////////////////////////////////
91 // senf::ppi::connector::InputConnector
92
93 prefix_ senf::Packet senf::ppi::connector::InputConnector::operator()()
94 {
95     if (empty())
96         v_requestEvent();
97     Packet p;
98     if (! empty()) {
99         p = peek();
100         queue_.pop_back();
101         v_dequeueEvent();
102     }
103     return p;
104 }
105
106 ////////////////////////////////////////
107 // private members
108
109 prefix_ void senf::ppi::connector::InputConnector::v_requestEvent()
110 {}
111
112 prefix_ void senf::ppi::connector::InputConnector::v_enqueueEvent()
113 {}
114
115 prefix_ void senf::ppi::connector::InputConnector::v_dequeueEvent()
116 {}
117
118 ///////////////////////////////////////////////////////////////////////////
119 // senf::ppi::connector::ActiveInput
120
121 ////////////////////////////////////////
122 // private members
123
124 prefix_ void senf::ppi::connector::ActiveInput::v_requestEvent()
125 {
126     request();
127 }
128
129 ///////////////////////////////////////////////////////////////////////////
130 // senf::ppi::connector::PassiveInput
131
132 ////////////////////////////////////////
133 // private members 
134
135 prefix_ void senf::ppi::connector::PassiveInput::v_enqueueEvent()
136 {
137     emit();
138     qdisc_->update(*this, QueueingDiscipline::ENQUEUE);
139 }
140
141 prefix_ void senf::ppi::connector::PassiveInput::v_dequeueEvent()
142 {
143     qdisc_->update(*this, QueueingDiscipline::DEQUEUE);
144 }
145
146 prefix_ void senf::ppi::connector::PassiveInput::v_unthrottleEvent()
147 {
148     size_type n (queueSize());
149     while (n) {
150         emit();
151         size_type nn (queueSize());
152         if (n == nn)
153             break;
154         n = nn;
155     }
156 }
157
158 ///////////////////////////////cc.e////////////////////////////////////////
159 #undef prefix_
160 //#include "Connectors.mpp"
161
162 \f
163 // Local Variables:
164 // mode: c++
165 // fill-column: 100
166 // comment-column: 40
167 // c-file-style: "senf"
168 // indent-tabs-mode: nil
169 // ispell-local-dictionary: "american"
170 // compile-command: "scons -u test"
171 // End: