Back to index

nordugrid-arc-nox  1.1.0~rc6
ModuleManager.h
Go to the documentation of this file.
00001 #ifndef __ARC_MODULEMANAGER_H__
00002 #define __ARC_MODULEMANAGER_H__
00003 
00004 #include <string>
00005 #include <map>
00006 #include <vector>
00007 #include <glibmm/module.h>
00008 #include <arc/XMLNode.h>
00009 #include <arc/Thread.h>
00010 #include <arc/Logger.h>
00011 
00012 namespace Arc {
00013 
00014 class LoadableModuleDesciption {
00015  private:
00016   Glib::Module* module;
00017   int count;
00018   std::string path;
00019  public:
00020   LoadableModuleDesciption(void):module(NULL),count(0) { };
00021   LoadableModuleDesciption(Glib::Module* m):module(m),count(0) { };
00022   LoadableModuleDesciption& operator=(Glib::Module* m) {
00023     module=m;
00024     return *this;
00025   }; 
00026   operator Glib::Module*(void) { return module; };
00027   bool operator==(Glib::Module* m) { return (module==m); }; 
00028   int load(void) { ++count; return count; };
00029   int unload(void) {
00030     --count;
00031     if(count <= 0) {
00032       if(module) delete module;
00033       module=NULL;
00034     }
00035     return count;
00036   };
00037   void makePersistent(void) { if(module) module->make_resident(); };
00038 };
00039 typedef std::map<std::string, LoadableModuleDesciption> plugin_cache_t;
00040 
00042 
00046 class ModuleManager
00047 {
00048     private:
00049         static Logger logger;
00050         std::vector<std::string> plugin_dir; 
00051         plugin_cache_t plugin_cache; 
00052     public:
00056         ModuleManager(XMLNode cfg);
00057         ~ModuleManager();
00060         Glib::Module* load(const std::string& name,bool probe = false /*,bool reload = false*/ );
00063         std::string find(const std::string& name);
00068         Glib::Module* reload(Glib::Module* module);
00070         void unload(Glib::Module* module);
00072         void unload(const std::string& name);
00074         std::string findLocation(const std::string& name);
00076         bool makePersistent(Glib::Module* module);
00078         bool makePersistent(const std::string& name);
00081         void setCfg (XMLNode cfg);
00082 };
00083 
00084 } // namespace Arc
00085 
00086 #endif /* __ARC_MODULEMANAGER_H__ */