manager.h

Go to the documentation of this file.
00001 /* Gotta load 'em all.
00002  *
00003  * PegSoft modules subsystem library (c) 2005 PegSoft
00004  * Contact us at pegsoft@pegsoft.net
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License version 2 as
00008  * published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this software (the COPYING file); if not, write to the
00017  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
00018  * USA.
00019  *
00020  */
00021 
00027 #ifndef MODULES_MANAGER_H
00028 #define MODULES_MANAGER_H
00029 
00030 /*************************************************************************/
00031 
00032 #include <list>
00033 #include <string>
00034 
00035 /*************************************************************************/
00036 
00037 namespace conf { class ConfGlobalQ; }
00038 
00039 /*************************************************************************/
00040 
00041 namespace modules
00042 {
00043 
00044 /*************************************************************************/
00045 
00046 class Module;
00047 
00048 class Core;
00049 
00050 class ConfModuleA;
00051 class LoadModule;
00052 
00053 /*************************************************************************/
00054 
00056 
00060 class ModManager
00061 {
00062     public:
00064         typedef std::list<Module *> list_type;
00065     
00067 
00073         ModManager(Core &core, ConfModuleA const &confmodule);
00075         ~ModManager();
00076         
00078 
00091         void broadcast(int state, Module &sender, int msg, void *arg);
00092         
00094 
00107         void broadcast_reverse(int state, Module &sender, int msg, void *arg);
00108         
00110 
00114         Module *find(std::string const &name);
00115         
00117 
00123         Module *find(std::string const &name, int state);
00124         
00126 
00142         bool load(std::string const &name);
00143         
00145 
00151         bool load(LoadModule const &lm);
00152         
00154 
00157         bool reload();
00158         
00160 
00166         void start();
00167         
00169 
00172         void stop();
00173         
00175 
00184         bool unload(Module &module);
00185         
00187         Core &core() const { return *m_core; }
00188         
00190 
00195         std::string const &error() const { return m_error; }
00196         
00198         enum
00199         {
00201             errSuccess = 0,
00203             errOpen = 1,
00205             errLookup = 2,
00207             errUnavailable = 3,
00209             errConfig = 4,
00211             errLoad = 5,
00213             errCore = 6,
00215             errNonZeroRefs = 7,
00217             errStop = 8
00218         };
00219         
00221 
00226         int error_code() const { return m_errorcode; }
00227         
00229 
00232         void global(conf::ConfGlobalQ &global) { m_global = &global; }
00233         
00235 
00238         list_type const &modules() const { return m_modules; }
00239         
00241         bool started() const { return m_started; }
00242     private:
00243         list_type m_modules;
00244     
00245         Core *m_core;
00246         
00247         std::string m_error;
00248         int m_errorcode;
00249         
00250         ConfModuleA const *m_confmodule;
00251         conf::ConfGlobalQ *m_global;
00252         
00253         bool m_started;
00254     
00255         ModManager(ModManager const &);
00256         ModManager &operator=(ModManager const &);
00257         
00258         std::string confblock(std::string const &name);
00259         void errorf(int code, const char *fmt, ...) FORMAT(printf, 3, 4);
00260         void feed(Module &recipient, int state, int msg, void *arg);
00261         void feed_reverse(Module &recipient, int state, int msg, void *arg);
00262         void start(Module &module);
00263 };
00264 
00265 /*************************************************************************/
00266 
00267 } /* namespace modules */
00268 
00269 /*************************************************************************/
00270 
00271 #endif /* MODULES_MANAGER_H */

Generated on Sun May 20 21:32:14 2007 for Epona API by  doxygen 1.4.6