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.cci

Go to the documentation of this file.
00001 // $Id: ModuleManager.cci 1770 2011-02-14 10:36:53Z 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 // Custom includes
00027 #include <algorithm>
00028 
00029 #define prefix_ inline
00030 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00031 
00032 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00033 // senf::ppi::ModuleManager
00034 
00035 prefix_ senf::ppi::ModuleManager & senf::ppi::ModuleManager::instance()
00036 {
00037     static ModuleManager manager;
00038     return manager;
00039 }
00040 
00041 prefix_ void senf::ppi::ModuleManager::registerModule(module::Module & module)
00042 {
00043     moduleRegistry_.push_back(&module);
00044 }
00045 
00046 prefix_ void senf::ppi::ModuleManager::unregisterModule(module::Module & module)
00047 {
00048     moduleRegistry_.erase(
00049         std::remove(moduleRegistry_.begin(), moduleRegistry_.end(), & module),
00050         moduleRegistry_.end());
00051 }
00052 
00053 prefix_ void senf::ppi::ModuleManager::registerInitializable(Initializable & i)
00054 {
00055     initQueue_.push_back(&i);
00056     initRunner_.enable();
00057     // This call ensures, that the senf::ppi::init() handler is called as next handler
00058     // after this handler returns (this works since the senf::ppi::init() handler is registered as
00059     // PRE hook and thus has very high priority)
00060     senf::scheduler::yield();
00061 }
00062 
00063 prefix_ void senf::ppi::ModuleManager::unregisterInitializable(Initializable & i)
00064 {
00065     initQueue_.erase(
00066         std::remove(initQueue_.begin(), initQueue_.end(), & i),
00067         initQueue_.end());
00068     if (initQueue_.empty())
00069         initRunner_.disable();
00070 }
00071 
00072 prefix_ bool senf::ppi::ModuleManager::initializableRegistered(Initializable const & i)
00073     const
00074 {
00075     return std::find(initQueue_.begin(), initQueue_.end(), &i) != initQueue_.end();
00076 }
00077 
00078 prefix_ bool senf::ppi::ModuleManager::running()
00079     const
00080 {
00081     return running_;
00082 }
00083 
00084 prefix_ senf::console::DirectoryNode & senf::ppi::ModuleManager::consoleDir()
00085     const
00086 {
00087     return consoleDir_.node();
00088 }
00089 
00090 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00091 // senf::ppi::ModuleManager::Initializable
00092 
00093 prefix_ senf::ppi::ModuleManager::Initializable::Initializable()
00094 {
00095     enqueueInitializable();
00096 }
00097 
00098 prefix_ senf::ppi::ModuleManager::Initializable::~Initializable()
00099 {
00100     dequeueInitializable();
00101 }
00102 
00103 prefix_ void senf::ppi::ModuleManager::Initializable::enqueueInitializable()
00104 {
00105     moduleManager().registerInitializable(*this);
00106 }
00107 
00108 prefix_ void senf::ppi::ModuleManager::Initializable::dequeueInitializable()
00109 {
00110     moduleManager().unregisterInitializable(*this);
00111 }
00112 
00113 prefix_ bool senf::ppi::ModuleManager::Initializable::initializationScheduled()
00114     const
00115 {
00116     return moduleManager().initializableRegistered(*this);
00117 }
00118 
00119 prefix_ senf::ppi::ModuleManager & senf::ppi::ModuleManager::Initializable::moduleManager()
00120     const
00121 {
00122     return ModuleManager::instance();
00123 }
00124 
00125 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00126 #undef prefix_
00127 
00128 
00129 // Local Variables:
00130 // mode: c++
00131 // fill-column: 100
00132 // comment-column: 40
00133 // c-file-style: "senf"
00134 // indent-tabs-mode: nil
00135 // ispell-local-dictionary: "american"
00136 // compile-command: "scons -u test"
00137 // End:

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