PPI: Complete connector implementation
[senf.git] / PPI / Connectors.cc
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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 ///////////////////////////////////////////////////////////////////////////
43 // senf::ppi::connector::ActiveConnector
44
45 ////////////////////////////////////////
46 // private members
47
48 prefix_ void senf::ppi::connector::ActiveConnector::notifyThrottle()
49 {
50     if (throttleCallback_)
51         throttleCallback_();
52     NotifyRoutes::const_iterator i (notifyRoutes_.begin());
53     NotifyRoutes::const_iterator const i_end (notifyRoutes_.end());
54     for (; i != i_end; ++i)
55         (*i)->notifyThrottle();
56 }
57
58 prefix_ void senf::ppi::connector::ActiveConnector::notifyUnthrottle()
59 {
60     if (unthrottleCallback_)
61         unthrottleCallback_();
62     NotifyRoutes::const_iterator i (notifyRoutes_.begin());
63     NotifyRoutes::const_iterator const i_end (notifyRoutes_.end());
64     for (; i != i_end; ++i)
65         (*i)->notifyUnthrottle();
66 }
67
68 prefix_ void senf::ppi::connector::ActiveConnector::registerRoute(ForwardingRoute & route)
69 {
70     notifyRoutes_.push_back(&route);
71 }
72
73 ///////////////////////////////////////////////////////////////////////////
74 // senf::ppi::connector::InputConnector
75
76 prefix_ senf::Packet senf::ppi::connector::InputConnector::operator()()
77 {
78     if (empty())
79         v_requestEvent();
80     Packet p;
81     if (! empty()) {
82         p = peek();
83         queue_.pop_back();
84         v_dequeueEvent();
85     }
86     return p;
87 }
88
89 ////////////////////////////////////////
90 // private members
91
92 prefix_ void senf::ppi::connector::InputConnector::v_requestEvent()
93 {}
94
95 prefix_ void senf::ppi::connector::InputConnector::v_enqueueEvent()
96 {}
97
98 prefix_ void senf::ppi::connector::InputConnector::v_dequeueEvent()
99 {}
100
101 ///////////////////////////////////////////////////////////////////////////
102 // senf::ppi::connector::ActiveInput
103
104 ////////////////////////////////////////
105 // private members
106
107 prefix_ void senf::ppi::connector::ActiveInput::v_requestEvent()
108 {
109     request();
110 }
111
112 ///////////////////////////////////////////////////////////////////////////
113 // senf::ppi::connector::PassiveInput
114
115 ////////////////////////////////////////
116 // private members 
117
118 prefix_ void senf::ppi::connector::PassiveInput::v_enqueueEvent()
119 {
120     emit();
121     qdisc_->update(*this, QueueingDiscipline::ENQUEUE);
122 }
123
124 prefix_ void senf::ppi::connector::PassiveInput::v_dequeueEvent()
125 {
126     qdisc_->update(*this, QueueingDiscipline::DEQUEUE);
127 }
128
129 prefix_ void senf::ppi::connector::PassiveInput::v_unthrottleEvent()
130 {
131     size_type n (queueSize());
132     while (n) {
133         emit();
134         size_type nn (queueSize());
135         if (n == nn)
136             break;
137         n = nn;
138     }
139 }
140
141 ///////////////////////////////cc.e////////////////////////////////////////
142 #undef prefix_
143 //#include "Connectors.mpp"
144
145 \f
146 // Local Variables:
147 // mode: c++
148 // fill-column: 100
149 // comment-column: 40
150 // c-file-style: "senf"
151 // indent-tabs-mode: nil
152 // ispell-local-dictionary: "american"
153 // compile-command: "scons -u test"
154 // End: