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) const;
00115         
00117 
00123         Module *find(std::string const &name, int state) const;
00124             
00126 
00136         Interface *find_interface(PSIID iid, Module **from = NULL) const;
00137         
00139 
00159         bool load(std::string const &name);
00160         
00162 
00168         bool load(LoadModule const &lm);
00169         
00171 
00174         bool reload();
00175         
00177 
00183         void start();
00184         
00186 
00189         void stop();
00190         
00192 
00201         bool unload(Module &module);
00202         
00204         Core &core() const { return *m_core; }
00205         
00207 
00212         std::string const &error() const { return m_error; }
00213         
00215         enum
00216         {
00218             errSuccess = 0,
00220             errOpen = 1,
00222             errLookup = 2,
00224             errUnavailable = 3,
00226             errConfig = 4,
00228             errLoad = 5,
00230             errCore = 6,
00232             errNonZeroRefs = 7,
00234             errStop = 8
00235         };
00236         
00238 
00243         int error_code() const { return m_errorcode; }
00244         
00246 
00249         void global(conf::ConfGlobalQ &global) { m_global = &global; }
00250         
00252 
00255         list_type const &modules() const { return m_modules; }
00256         
00258         bool started() const { return m_started; }
00259     private:
00260         list_type m_modules;
00261     
00262         Core *m_core;
00263         
00264         std::string m_error;
00265         int m_errorcode;
00266         
00267         ConfModuleA const *m_confmodule;
00268         conf::ConfGlobalQ *m_global;
00269         
00270         bool m_started;
00271     
00272         ModManager(ModManager const &);
00273         ModManager &operator=(ModManager const &);
00274         
00275         std::string confblock(std::string const &name);
00276         void errorf(int code, const char *fmt, ...) FORMAT(printf, 3, 4);
00277         void feed(Module &recipient, int state, int msg, void *arg);
00278         void feed_reverse(Module &recipient, int state, int msg, void *arg);
00279         bool load_deps(std::string const &path);
00280         void start(Module &module);
00281 };
00282 
00283 /*************************************************************************/
00284 
00285 } /* namespace modules */
00286 
00287 /*************************************************************************/
00288 
00289 #endif /* MODULES_MANAGER_H */

Generated on Fri Apr 18 22:03:27 2008 for Epona API by  doxygen 1.5.3