00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }
00268
00269
00270
00271 #endif