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