307d3418972fd950d7376276070687c791b8072a
[senf.git] / PPI / Route.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief Route public header */
23
24 #ifndef HH_Route_
25 #define HH_Route_ 1
26
27 // Custom includes
28 #include <boost/type_traits.hpp>
29 #include "predecl.hh"
30
31 //#include "Route.mpp"
32 ///////////////////////////////hh.p////////////////////////////////////////
33
34 namespace senf {
35 namespace ppi {
36
37     /** \brief Routing base class
38
39         Routing information is defined within each module to define the control flow. RouteBase is
40         the generic base class for all routing entries.
41      */
42     class RouteBase
43     {
44     public:
45         virtual ~RouteBase();
46
47     protected:
48         RouteBase(module::Module & module);
49
50     private:
51         module::Module * module_;
52     };
53
54     /** \brief Forwarding route base class
55
56         All routes which may forward control information are based on
57         ForwardingRoute. ForwardingRoute provides methods to control and query the throttling
58         behavior.
59      */
60     class ForwardingRoute
61         : public RouteBase
62     {
63     public:
64         bool autoThrottling() const;    ///< Query current autoThrottling state
65         void autoThrottling(bool state); ///< Change automatic throttle notification forwarding
66                                         /**< By default, throttle notifications are automatically
67                                              forwarded from active to passive connectors. This may
68                                              be disabled by setting the authoThrottling state to \c
69                                              false.
70                                              
71                                              Routing from/to an event to/from a passive connector
72                                              will automatically create throttling notifications on
73                                              the connector whenever the event is disabled. Routing
74                                              form/to an event to/from an active connector will
75                                              disable the event whenever a throttling notification
76                                              comes in. Respective for unthrottle notifications.
77
78                                              \param[in] state New throttle forwarding state */
79
80         bool throttled() const;         ///< \c true, if the route is throttled
81                                         /**< This member checks only the automatic throttling
82                                              state. If autoThrottling() is \c false, this member
83                                              will always return \c false. */
84         
85     protected:
86         ForwardingRoute(module::Module & module);
87
88         // Called to register this route with the connectors forwarding information base
89         template <class T> void registerRoute(T & ob);
90
91         template <class T> void notifyThrottle(T & ob);
92         template <class T> void notifyUnthrottle(T & ob);
93
94     private:
95         // called to forward a throttling notification along the route
96         void notifyThrottle();
97         void notifyUnthrottle();
98
99         // Implemented in the derived classes to forward throttling notifications
100         virtual void v_notifyThrottle() = 0;
101         virtual void v_notifyUnthrottle() = 0;
102         virtual bool v_throttled() const = 0;
103
104         bool autoThrottling_;
105
106         friend class connector::ActiveConnector;
107     };
108
109 }}
110
111 // We need detail::RouteImplementation here ...
112 #include "Route.ih"
113
114 namespace senf {
115 namespace ppi {
116
117     /** \brief Route descriptor
118         
119         Route instances are created by Module::route statements. The Route class provides an
120         interface to manipulate the flow processing.
121
122         The concrete interface provided depends on the type of route. If the route is a forwarding
123         route, it will be based on ForwardingRoute otherwise it will be based directly on
124         RouteBase.
125      */
126     template <class Source, class Target>
127     class Route
128         : public detail::RouteImplementation<Source,Target>
129     {
130     private:
131         typedef detail::RouteImplementation<Source,Target> Base;
132         typedef detail::RouteImplementation<Source,Target> Implementation;
133         
134         Route(module::Module & module, Source & source, Target & target);
135
136         friend class module::Module;
137     };
138
139 }}
140
141 ///////////////////////////////hh.e////////////////////////////////////////
142 #include "Route.cci"
143 #include "Route.ct"
144 #include "Route.cti"
145 #endif
146
147 \f
148 // Local Variables:
149 // mode: c++
150 // fill-column: 100
151 // c-file-style: "senf"
152 // indent-tabs-mode: nil
153 // ispell-local-dictionary: "american"
154 // compile-command: "scons -u test"
155 // comment-column: 40
156 // End: