Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

ModuleManager.cc

Go to the documentation of this file.
00001 // $Id: ModuleManager.cc 1781 2011-04-11 12:10:19Z tho $
00002 //
00003 // Copyright (C) 2007
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #include "ModuleManager.hh"
00027 //#include "ModuleManager.ih"
00028 
00029 // Custom includes
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 //#include "ModuleManager.mpp"
00036 #define prefix_
00037 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00038 
00039 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00040 // senf::ppi::ModuleManager
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 // private members
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 //#include "ModuleManager.mpp"
00118 
00119 
00120 // Local Variables:
00121 // mode: c++
00122 // fill-column: 100
00123 // comment-column: 40
00124 // c-file-style: "senf"
00125 // indent-tabs-mode: nil
00126 // ispell-local-dictionary: "american"
00127 // compile-command: "scons -u test"
00128 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research