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) 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 }
00286
00287
00288
00289 #endif