69d24e0d6b96f0de599fcbb1d7c0394f4563a48a
[senf.git] / senf / PPI / Joins.hh
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 Joins public header */
30
31 #ifndef HH_SENF_PPI_Joins_
32 #define HH_SENF_PPI_Joins_ 1
33
34 // Custom includes
35 #include <boost/ptr_container/ptr_vector.hpp>
36 #include "predecl.hh"
37 #include "Connectors.hh"
38 #include "Module.hh"
39 #include "MultiConnectorMixin.hh"
40
41 //#include "Joins.mpp"
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43
44 namespace senf {
45 namespace ppi {
46
47 namespace module {
48
49     /** \brief Join multiple packet streams with passive inputs
50
51         The PassiveJoin will combine any number of packet streams. You may connect any number of
52         ActiveOutput<>'s  to the PassiveJoin instance. The combined stream is then provided on the
53         ActiveOutput<> \a output.
54
55         Since PassiveJoin allows any number of incoming packet streams, the input connectors are
56         dynamically managed. A special senf::ppi::connect() overload is used to dynamically create
57         the needed input connectors. This hides this extra functionality from the user.
58         \code
59         senf::ppi::module::PassiveJoin join;
60
61         ppi::connect(module1,join);             // Connect first module to join's input
62         ppi::connect(module2.some_output,join); // Connect another module to join's input
63         ppi::connect(join,module3);             // Forward combined stream to module3
64         \endcode
65
66         \ingroup routing_modules
67      */
68     class PassiveJoin
69         : public Module,
70           public MultiConnectorMixin<PassiveJoin, connector::PassiveInput<> >
71     {
72         SENF_PPI_MODULE(PassiveJoin);
73     public:
74         connector::ActiveOutput<> output;
75
76         PassiveJoin();
77
78     private:
79         void connectorSetup(connector::PassiveInput<> & conn);
80         void request(connector::GenericPassiveInput & input);
81         void onThrottle();
82         void onUnthrottle();
83
84         friend class MultiConnectorMixin<PassiveJoin, connector::PassiveInput<> >;
85     };
86
87     /** \brief Join multiple packet streams with active inputs
88
89         The PriorityJoin will combine any number of packet streams. You may connect any number of
90         PassiveInput<>'s  to the PassiveJoin instance. The combined stream is then provided on the
91         PassiveOutput<> \a output.
92
93         When a packet request is received on Priorityjoin's \a output, The request will be serviced
94         from the first unthrottled input. The order, in which connectors are connected to the
95         PriorityJoin's input is important: The earlier connected peer has the higher priority and
96         will be serviced first.
97
98         Since PriorityJoin allows any number of incoming packet streams, the input connectors are
99         dynamically managed. A special senf::ppi::connect() overload is used to dynamically create
100         the needed input connectors. This hides this extra functionality from the user.
101         \code
102         senf::ppi::module::PriorityJoin join;
103
104         ppi::connect(module1,join);             // Connect first module to join's input
105         ppi::connect(module2.some_output,join); // Connect another module to join's input
106         ppi::connect(join,module3);             // Forward combined stream to module3
107         \endcode
108         Here, \a module1 has higher priority than \a module2 which will only be queried if \a
109         module1 is throttled.
110
111         \ingroup routing_modules
112      */
113     class PriorityJoin
114         : public Module,
115           public MultiConnectorMixin<PriorityJoin, connector::ActiveInput<> >
116     {
117         SENF_PPI_MODULE(PriorityJoin);
118     public:
119         connector::PassiveOutput<> output;
120
121         PriorityJoin();
122
123     private:
124         void connectorSetup(PriorityJoin::ConnectorType & conn, int priority=-1);
125         void request();
126         void onThrottle();
127         void onUnthrottle();
128
129         friend class MultiConnectorMixin<PriorityJoin, connector::ActiveInput<> >;
130     };
131
132 }}}
133
134 //-/////////////////////////////////////////////////////////////////////////////////////////////////
135 #include "Joins.cci"
136 //#include "Joins.ct"
137 //#include "Joins.cti"
138 #endif
139
140 \f
141 // Local Variables:
142 // mode: c++
143 // fill-column: 100
144 // comment-column: 40
145 // c-file-style: "senf"
146 // indent-tabs-mode: nil
147 // ispell-local-dictionary: "american"
148 // compile-command: "scons -u test"
149 // End: