switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / PPI / ModuleManager.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 ModuleManager public header */
30
31 #ifndef HH_SENF_PPI_ModuleManager_
32 #define HH_SENF_PPI_ModuleManager_ 1
33
34 // Custom includes
35 #include <vector>
36 #include <deque>
37 #include "predecl.hh"
38 #include <senf/Scheduler/Scheduler.hh>
39 #include <senf/Utils/Console/ScopedDirectory.hh>
40
41 //#include "ModuleManager.mpp"
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43
44 namespace senf {
45 namespace ppi {
46
47     /** \brief Internal: Module management
48
49         Every module is registered with the ModuleManager. The ModuleManager controls module
50         initialization and execution of the network.
51       */
52     class ModuleManager
53     {
54     public:
55         //-////////////////////////////////////////////////////////////////////////
56         // Types
57
58         struct Initializable
59         {
60             Initializable();
61             virtual ~Initializable();
62             ModuleManager & moduleManager() const;
63             void enqueueInitializable();
64             void dequeueInitializable();
65             bool initializationScheduled() const;
66
67             virtual void v_init() = 0;
68         };
69
70         //-////////////////////////////////////////////////////////////////////////
71         ///\name Structors and default members
72         //\{
73
74         static ModuleManager & instance();
75
76         // default default constructor
77         // default copy constructor
78         // default copy assignment
79         // default destructor
80
81         // no conversion constructors
82
83         //\}
84         //-////////////////////////////////////////////////////////////////////////
85
86         void init();                    ///< Called by senf::ppi::init()
87         void run();                     ///< Called by senf::ppi::run()
88
89         bool running() const;           ///< \c true, if the network is running
90
91         senf::console::DirectoryNode & consoleDir() const;
92
93     private:
94         ModuleManager();
95
96         void registerModule(module::Module & module);
97         void unregisterModule(module::Module & module);
98
99         void registerInitializable(Initializable & i);
100         void unregisterInitializable(Initializable & i);
101         bool initializableRegistered(Initializable const & i) const;
102
103         void dumpModules(std::ostream & os) const;
104
105         typedef std::vector<module::Module *> ModuleRegistry;
106         typedef std::deque<Initializable *> InitQueue;
107
108 #ifndef DOXYGEN
109         struct RunGuard;
110         friend class RunGuard;
111 #endif
112
113         ModuleRegistry moduleRegistry_;
114         bool running_;
115         bool terminate_;
116
117         InitQueue initQueue_;
118
119         scheduler::EventHook initRunner_;
120
121         senf::console::ScopedDirectory<> consoleDir_;
122
123         friend class module::Module;
124         friend class Initializable;
125     };
126
127 }}
128
129 //-/////////////////////////////////////////////////////////////////////////////////////////////////
130 #include "ModuleManager.cci"
131 //#include "ModuleManager.ct"
132 //#include "ModuleManager.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: