9e890b7f12ffea15a196d2195aab3422409f81ea
[senf.git] / PPI / ModuleManager.cc
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 ModuleManager non-inline non-template implementation */
25
26 #include "ModuleManager.hh"
27 //#include "ModuleManager.ih"
28
29 // Custom includes
30 #include "../Scheduler/Scheduler.hh"
31 #include "../Utils/membind.hh"
32 #include "Module.hh"
33 #include "../Utils/Console/Console.hh"
34
35 //#include "ModuleManager.mpp"
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 ///////////////////////////////////////////////////////////////////////////
40 // senf::ppi::ModuleManager
41
42 prefix_ void senf::ppi::ModuleManager::init()
43 {
44     while (! initQueue_.empty()) {
45         initQueue_.front()->v_init();
46         initQueue_.pop_front();
47     }
48     initRunner_.disable();
49 }
50
51 #ifndef DOXYGEN
52
53 struct senf::ppi::ModuleManager::RunGuard
54 {
55     RunGuard(ModuleManager & m) : manager(m) { manager.running_ = true; }
56     ~RunGuard() { manager.running_ = false; }
57     ModuleManager & manager;
58 };
59
60 #endif
61
62 prefix_ void senf::ppi::ModuleManager::run()
63 {
64     init();
65     RunGuard guard (*this);
66     scheduler::process();
67 }
68
69 ////////////////////////////////////////
70 // private members
71
72 prefix_ senf::ppi::ModuleManager::ModuleManager()
73     : running_(false), terminate_(false), 
74       initRunner_ ("senf::ppi::init", membind(&ModuleManager::init, this),
75                    scheduler::EventHook::PRE, false)
76 {
77     senf::console::sysdir().add("ppi", consoleDir_);
78
79     consoleDir_
80         .add("dump", senf::membind(&ModuleManager::dumpModules, this))
81         .doc("Dump complete PPI structure\n"
82              "The dump will contain one paragraph for each module. The first line gives module\n"
83              "information, additional lines list all connectors and their peers (if connected).");
84 }
85
86 prefix_ void senf::ppi::ModuleManager::dumpModules(std::ostream & os)
87 {
88     for (ModuleRegistry::const_iterator i (moduleRegistry_.begin()), i_end (moduleRegistry_.end());
89          i != i_end; ++i) {
90         os << *i << " " << prettyName(typeid(**i)) << "\n";
91         for (module::Module::ConnectorRegistry::iterator j ((*i)->connectorRegistry_.begin()),
92                  j_end ((*i)->connectorRegistry_.end()); j != j_end; ++j) {
93             os << "  " << *j << " " << prettyName(typeid(**j));
94             if ((**j).connected())
95                 os << " " << & (*j)->peer();
96             os << "\n";
97         }
98         os << "\n";
99     }
100 }
101
102 ///////////////////////////////cc.e////////////////////////////////////////
103 #undef prefix_
104 //#include "ModuleManager.mpp"
105
106 \f
107 // Local Variables:
108 // mode: c++
109 // fill-column: 100
110 // comment-column: 40
111 // c-file-style: "senf"
112 // indent-tabs-mode: nil
113 // ispell-local-dictionary: "american"
114 // compile-command: "scons -u test"
115 // End: