PPI: output throttle state on ppi-dump
[senf.git] / senf / 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 <senf/Scheduler/Scheduler.hh>
31 #include <senf/Utils/membind.hh>
32 #include "Module.hh"
33 #include <senf/Utils/Console/ParsedCommand.hh>
34 #include <senf/Utils/Console/Sysdir.hh>
35
36 //#include "ModuleManager.mpp"
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 ///////////////////////////////////////////////////////////////////////////
41 // senf::ppi::ModuleManager
42
43 prefix_ void senf::ppi::ModuleManager::init()
44 {
45     while (! initQueue_.empty()) {
46         initQueue_.front()->v_init();
47         initQueue_.pop_front();
48     }
49     initRunner_.disable();
50 }
51
52 #ifndef DOXYGEN
53
54 struct senf::ppi::ModuleManager::RunGuard
55 {
56     RunGuard(ModuleManager & m) : manager(m) { manager.running_ = true; }
57     ~RunGuard() { manager.running_ = false; }
58     ModuleManager & manager;
59 };
60
61 #endif
62
63 prefix_ void senf::ppi::ModuleManager::run()
64 {
65     init();
66     RunGuard guard (*this);
67     scheduler::process();
68 }
69
70 ////////////////////////////////////////
71 // private members
72
73 prefix_ senf::ppi::ModuleManager::ModuleManager()
74     : running_(false), terminate_(false),
75       initRunner_ ("senf::ppi::init", membind(&ModuleManager::init, this),
76                    scheduler::EventHook::PRE, false)
77 {
78     senf::console::sysdir().add("ppi", consoleDir_);
79
80     consoleDir_
81         .add("dump", senf::console::factory::Command(
82                  senf::membind(&ModuleManager::dumpModules, this))
83              .doc("Dump complete PPI structure\n"
84                   "The dump will contain one paragraph for each module. The first line gives module\n"
85                   "information, additional lines list all connectors and their peers (if connected).\n"
86                   "\n"
87                   "This information can be processed by 'tools/drawmodules.py' and 'dot' (from the\n"
88                   "graphviz package) to generate a graphic representation of the module structure:\n"
89                   "\n"
90                   "    $ echo /sys/ppi/dump | nc -q1 <host> <port> \\\n"
91                   "          | python tools/drawmodules.py | dot -Tpng /dev/fd/0 >modules.png\n")
92             );
93 }
94
95 prefix_ void senf::ppi::ModuleManager::dumpModules(std::ostream & os)
96     const
97 {
98     for (ModuleRegistry::const_iterator i (moduleRegistry_.begin()), i_end (moduleRegistry_.end());
99          i != i_end; ++i) {
100         os << *i << " " << prettyName(typeid(**i)) << "\n";
101         for (module::Module::ConnectorRegistry::iterator j ((*i)->connectorRegistry_.begin()),
102                  j_end ((*i)->connectorRegistry_.end()); j != j_end; ++j) {
103             os << "  " << *j << " " << prettyName(typeid(**j));
104             if ((**j).connected()) {
105                 os << " " << & (*j)->peer();
106                 connector::PassiveConnector * pc (dynamic_cast<connector::PassiveConnector *>(*j));
107                 if (pc && pc->throttled())
108                     os << " throttled";
109             }
110             os << "\n";
111         }
112         os << "\n";
113     }
114 }
115
116 ///////////////////////////////cc.e////////////////////////////////////////
117 #undef prefix_
118 //#include "ModuleManager.mpp"
119
120 \f
121 // Local Variables:
122 // mode: c++
123 // fill-column: 100
124 // comment-column: 40
125 // c-file-style: "senf"
126 // indent-tabs-mode: nil
127 // ispell-local-dictionary: "american"
128 // compile-command: "scons -u test"
129 // End: