switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / PPI / Setup.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 Setup public header */
30
31 #ifndef HH_SENF_PPI_Setup_
32 #define HH_SENF_PPI_Setup_ 1
33
34 // Custom includes
35 #include <boost/type_traits.hpp>
36 #include <boost/utility/enable_if.hpp>
37 #include "predecl.hh"
38
39 //#include "Setup.mpp"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41
42 namespace senf {
43 namespace ppi {
44
45 namespace detail {
46     struct DisableStandardInput {};
47     struct DisableStandardOutput {};
48     struct DisableStandardConnect : public DisableStandardInput, public DisableStandardOutput {};
49 }
50
51 #ifdef DOXYGEN
52
53     /** \brief Connect modules
54
55         senf::ppi::connect() establishes a connection between two modules or, to be more precise,
56         between two connectors. It will connect any input to any output connector as long as one is
57         active and the other passive.
58
59         If a module has an output connector called \c output, the module may be directly specified
60         as \a source argument. In the same way, if a module has an input connector called \c input,
61         the module may be given directly as \a target argument. This simplifies the most common case
62         of a module with one input and one output connector.
63
64         The connect call will check at runtime, whether the two connectors are type-compatible:
65         \li Either or both of the connectors are untyped (they accept/send arbitrary senf::Packet's)
66         \li Both connectors send/accept the exactly same packet type.
67
68         Depending on the type of input or output, the connect call may require additional
69         arguments. See the respective module documentation for more information
70
71         \throws connector::IncompatibleConnectorsException if the two connectors are not type
72             compatible.
73
74         \see \ref ppi_connections
75      */
76     void connect(connector::OutputConnector & source, connector::InputConnector & target, ...);
77
78 #else
79
80     void connect(connector::GenericActiveOutput & source, connector::GenericPassiveInput & target);
81     void connect(connector::GenericPassiveOutput & source, connector::GenericActiveInput & target);
82
83 #endif
84
85 #ifndef DOXYGEN
86
87     template <class T, class C>
88     void connect(T & source, C & target,
89                  typename boost::disable_if< boost::is_base_of<connector::Connector, T> >::type * = 0,
90                  typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type * = 0,
91                  typename boost::disable_if< boost::is_base_of<detail::DisableStandardOutput, T> >::type * = 0);
92
93     template <class C, class T>
94     void connect(C & source, T & target,
95                  typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type * = 0,
96                  typename boost::disable_if< boost::is_base_of<connector::Connector,T> >::type * = 0,
97                  typename boost::disable_if< boost::is_base_of<detail::DisableStandardInput, T> >::type * = 0);
98
99     template <class T1, class T2>
100     void connect(T1 & source, T2 & target,
101                  typename boost::disable_if< boost::is_base_of<connector::Connector, T1> >::type * = 0,
102                  typename boost::disable_if< boost::is_base_of<connector::Connector, T2> >::type * = 0,
103                  typename boost::disable_if< boost::is_base_of<detail::DisableStandardOutput, T1> >:: type * = 0,
104                  typename boost::disable_if< boost::is_base_of<detail::DisableStandardInput, T2> >:: type * = 0);
105
106 #endif
107
108     /** \brief Start the network
109
110         Calling senf::ppi::run() will start processing the network. The main event loop is managed
111         by the Scheduler. Before starting the Scheduler main loop, all Module init() members are
112         called.
113
114         senf::ppi::run() will return when no more work is to be done, that is when no events are
115         enabled (Since the events are enabled and disabled by the throttle notifications which
116         depend among other things on the packet queues, this is the same as checking for packets in
117         any queue). It is Ok to call senf::ppi::run() multiple times during the program lifetime.
118
119         \see \ref ppi_run
120      */
121     void run();
122
123     /** \brief Manually initialize the network
124
125         For debugging purposes, it is sometimes simpler to not use senf::ppi::run() but instead
126         drive the network via explicit calls using the debug modules. However, it is still necessary
127         to initialize the network. This operation is performed by senf::ppi::init().
128      */
129     void init();
130
131 }}
132
133 //-/////////////////////////////////////////////////////////////////////////////////////////////////
134 #include "Setup.cci"
135 //#include "Setup.ct"
136 #include "Setup.cti"
137 #endif
138
139 \f
140 // Local Variables:
141 // mode: c++
142 // fill-column: 100
143 // comment-column: 40
144 // c-file-style: "senf"
145 // indent-tabs-mode: nil
146 // ispell-local-dictionary: "american"
147 // compile-command: "scons -u test"
148 // End: