00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #include "ModuleManager.hh"
00027
00028
00029
00030 #include <senf/Utils/membind.hh>
00031 #include <senf/Utils/Console/ParsedCommand.hh>
00032 #include <senf/Utils/Console/Sysdir.hh>
00033 #include "Module.hh"
00034
00035
00036 #define prefix_
00037
00038
00039
00040
00041
00042 prefix_ void senf::ppi::ModuleManager::init()
00043 {
00044 while (! initQueue_.empty()) {
00045 initQueue_.front()->v_init();
00046 initQueue_.pop_front();
00047 }
00048 initRunner_.disable();
00049 }
00050
00051 #ifndef DOXYGEN
00052
00053 struct senf::ppi::ModuleManager::RunGuard
00054 {
00055 RunGuard(ModuleManager & m) : manager(m) { manager.running_ = true; }
00056 ~RunGuard() { manager.running_ = false; }
00057 ModuleManager & manager;
00058 };
00059
00060 #endif
00061
00062 prefix_ void senf::ppi::ModuleManager::run()
00063 {
00064 init();
00065 RunGuard guard (*this);
00066 scheduler::process();
00067 }
00068
00069
00070
00071
00072 prefix_ senf::ppi::ModuleManager::ModuleManager()
00073 : running_(false), terminate_(false),
00074 initRunner_ ("senf::ppi::init", membind(&ModuleManager::init, this),
00075 scheduler::EventHook::PRE, false)
00076 {
00077 console::sysdir().add("ppi", consoleDir_);
00078
00079 consoleDir_
00080 .add("dump", console::factory::Command(
00081 senf::membind(&ModuleManager::dumpModules, this))
00082 .doc("Dump complete PPI structure\n"
00083 "The dump will contain one paragraph for each module. The first line gives module\n"
00084 "information, additional lines list all connectors and their peers (if connected).\n"
00085 "\n"
00086 "This information can be processed by 'tools/drawmodules.py' and 'dot' (from the\n"
00087 "graphviz package) to generate a graphic representation of the module structure:\n"
00088 "\n"
00089 " $ echo /sys/ppi/dump | nc -q1 <host> <port> \\\n"
00090 " | python tools/drawmodules.py | dot -Tpng /dev/fd/0 >modules.png\n")
00091 );
00092 }
00093
00094 prefix_ void senf::ppi::ModuleManager::dumpModules(std::ostream & os)
00095 const
00096 {
00097 for (ModuleRegistry::const_iterator i (moduleRegistry_.begin()), i_end (moduleRegistry_.end());
00098 i != i_end; ++i) {
00099 os << *i << " " << prettyName(typeid(**i)) << "\n";
00100 for (module::Module::ConnectorRegistry::iterator j ((*i)->connectorRegistry_.begin()),
00101 j_end ((*i)->connectorRegistry_.end()); j != j_end; ++j) {
00102 os << " " << *j << " " << prettyName(typeid(**j));
00103 if ((**j).connected()) {
00104 os << " " << & (*j)->peer();
00105 connector::PassiveConnector * pc (dynamic_cast<connector::PassiveConnector *>(*j));
00106 if (pc && pc->throttled())
00107 os << " throttled";
00108 }
00109 os << "\n";
00110 }
00111 os << "\n";
00112 }
00113 }
00114
00115
00116 #undef prefix_
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128