Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Private Attributes
Arc::ClassLoader Class Reference

#include <ClassLoader.h>

Inheritance diagram for Arc::ClassLoader:
Inheritance graph
[legend]
Collaboration diagram for Arc::ClassLoader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

LoadableClassInstance (const std::string &classId, XMLNode *arg=NULL, const std::string &className="")
LoadableClassInstance (XMLNode *arg=NULL, const std::string &className="")
 ~ClassLoader ()
bool load (const std::string &name)
 These methods load module named lib'name' and check if it contains ARC plugin(s) of specified 'kind' and 'name'.
bool load (const std::string &name, const std::string &kind)
bool load (const std::string &name, const std::string &kind, const std::string &pname)
bool load (const std::string &name, const std::list< std::string > &kinds)
bool load (const std::list< std::string > &names, const std::string &kind)
bool load (const std::list< std::string > &names, const std::string &kind, const std::string &pname)
bool load (const std::list< std::string > &names, const std::list< std::string > &kinds)
Glib::Module * load (const std::string &name, bool probe=false)
 Finds module 'name' in cache or loads corresponding loadable module.
void TryLoad (bool v=true)
 These methods load module named lib'name', locate plugin constructor functions of specified 'kind' and 'name' (if specified) and call it.
bool TryLoad (void)
Pluginget_instance (const std::string &kind, PluginArgument *arg, bool search=true)
Pluginget_instance (const std::string &kind, int version, PluginArgument *arg, bool search=true)
Pluginget_instance (const std::string &kind, int min_version, int max_version, PluginArgument *arg, bool search=true)
Pluginget_instance (const std::string &kind, const std::string &name, PluginArgument *arg, bool search=true)
Pluginget_instance (const std::string &kind, const std::string &name, int version, PluginArgument *arg, bool search=true)
Pluginget_instance (const std::string &kind, const std::string &name, int min_version, int max_version, PluginArgument *arg, bool search=true)
bool scan (const std::string &name, ModuleDesc &desc)
 Collect information about plugins stored in module(s) with specified names.
bool scan (const std::list< std::string > &names, std::list< ModuleDesc > &descs)
void report (std::list< ModuleDesc > &descs)
 Provides information about currently loaded modules and plugins.
template<class P >
P * GetInstance (const std::string &kind, PluginArgument *arg, bool search=true)
template<class P >
P * GetInstance (const std::string &kind, const std::string &name, PluginArgument *arg, bool search=true)
std::string find (const std::string &name)
 Finds loadable module by 'name' looking in same places as load() does, but does not load it.
Glib::Module * reload (Glib::Module *module)
 Reload module previously loaded in probe mode.
void unload (Glib::Module *module)
 Unload module by its identifier.
void unload (const std::string &name)
 Unload module by its name.
std::string findLocation (const std::string &name)
 Finds shared library corresponding to module 'name' and returns path to it.
bool makePersistent (Glib::Module *module)
 Make sure this module is never unloaded.
bool makePersistent (const std::string &name)
 Make sure this module is never unloaded.
void setCfg (XMLNode cfg)
 Input the configuration subtree, and trigger the module loading (do almost the same as the Constructor); It is function desgined for ClassLoader to adopt the singleton pattern.

Static Public Member Functions

static ClassLoadergetClassLoader (Config *cfg=NULL)

Protected Member Functions

 ClassLoader (Config *cfg=NULL)
void load_all_instances (Config *cfg)

Static Private Attributes

static Logger logger
static ClassLoader_instance = NULL

Detailed Description

Definition at line 21 of file ClassLoader.h.


Constructor & Destructor Documentation

Arc::ClassLoader::ClassLoader ( Config cfg = NULL) [protected]

Definition at line 27 of file ClassLoader.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

!if(!id_map.empty()) ! id_map.clear();

Definition at line 32 of file ClassLoader.cpp.

                         {
  // Delete the list (do not delete the element), gurantee the caller 
  // will not need to delete the elements. If the list is automatically 
  // deleted by caller (e.g. main function), there will be "double free 
  // or corruption (fasttop)", because ModuleManager also deletes the 
  // same memory space of the element.
}

Member Function Documentation

std::string Arc::ModuleManager::find ( const std::string &  name) [inherited]

Finds loadable module by 'name' looking in same places as load() does, but does not load it.

Definition at line 88 of file ModuleManager.cpp.

{
  return findLocation(name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

std::string Arc::ModuleManager::findLocation ( const std::string &  name) [inherited]

Finds shared library corresponding to module 'name' and returns path to it.

Definition at line 46 of file ModuleManager.cpp.

{
  std::string path;
  std::vector<std::string>::const_iterator i = plugin_dir.begin();
  for (; i != plugin_dir.end(); i++) {
    path = Glib::Module::build_path(*i, name);
    // Loader::logger.msg(VERBOSE, "Try load %s", path);
    FILE *file = fopen(path.c_str(), "r");
    if (file == NULL) {
      continue;
    } else {
      fclose(file);
      break;
    }
  }
  if(i == plugin_dir.end()) path="";
  return path;
}

Here is the caller graph for this function:

Plugin * Arc::PluginsFactory::get_instance ( const std::string &  kind,
PluginArgument arg,
bool  search = true 
) [inherited]

Definition at line 206 of file Plugin.cpp.

                                                                                            {
    return get_instance(kind,0,INT_MAX,arg,search);
  }

Here is the caller graph for this function:

Plugin * Arc::PluginsFactory::get_instance ( const std::string &  kind,
int  version,
PluginArgument arg,
bool  search = true 
) [inherited]

Definition at line 210 of file Plugin.cpp.

                                                                                                        {
    return get_instance(kind,version,version,arg,search);
  }

Here is the call graph for this function:

Plugin * Arc::PluginsFactory::get_instance ( const std::string &  kind,
int  min_version,
int  max_version,
PluginArgument arg,
bool  search = true 
) [inherited]

Definition at line 214 of file Plugin.cpp.

                                                                                                                            {
    if(arg) arg->set_factory(this);
    Glib::Mutex::Lock lock(lock_);
    descriptors_t_::iterator i = descriptors_.begin();
    for(;i != descriptors_.end();++i) {
      PluginDescriptor* desc = i->second;
      for(;;) {
        desc=find_constructor(desc,kind,min_version,max_version);
        if(!desc) break;
        if(arg) {
          modules_t_::iterator m = modules_.find(i->first);
          if(m != modules_.end()) {
            arg->set_module(m->second);
          } else {
            arg->set_module(NULL);
          };
        };
        lock.release();
        Plugin* plugin = desc->instance(arg);
        if(plugin) return plugin;
        lock.acquire();
        ++desc;
      };
    };
    if(!search) return NULL;
    // Try to load module of plugin
    std::string mname = kind;
    ARCModuleDescriptor* mdesc = probe_descriptor(mname,*this);
    if(mdesc) {
      if(!mdesc->contains(kind)) {
        delete mdesc;
        return NULL;
      };
      delete mdesc;
      mdesc = NULL;
    };
    // Descriptor not found or indicates presence of requested kinds.
    if(!try_load_) {
      logger.msg(ERROR, "Could not find loadable module descriptor by name %s",kind);
      return NULL;
    };
    // Now try to load module directly
    Glib::Module* module = probe_module(kind,*this);
    if (module == NULL) {
      logger.msg(ERROR, "Could not find loadable module by name %s (%s)",kind,strip_newline(Glib::Module::get_last_error()));
      return NULL;
    };
    // Identify table of descriptors
    void *ptr = NULL;
    if(!module->get_symbol(plugins_table_name,ptr)) {
      logger.msg(VERBOSE, "Module %s is not an ARC plugin (%s)",kind,strip_newline(Glib::Module::get_last_error()));
      unload_module(module,*this);
      return NULL;
    };
    // Try to find plugin in new table
    PluginDescriptor* desc = (PluginDescriptor*)ptr;
    for(;;) {
      desc=find_constructor(desc,kind,min_version,max_version);
      if(!desc) break;
      if(arg) arg->set_module(module);
      lock.release();
      Plugin* plugin = desc->instance(arg);
      lock.acquire();
      if(plugin) {
        // Keep plugin loaded and registered
        Glib::Module* nmodule = reload_module(module,*this);
        if(!nmodule) {
          logger.msg(VERBOSE, "Module %s failed to reload (%s)",mname,strip_newline(Glib::Module::get_last_error()));
          unload_module(module,*this);
          return false;
        };
        descriptors_[mname]=(PluginDescriptor*)ptr;
        modules_[mname]=nmodule;
        //descriptors_.push_back((PluginDescriptor*)ptr);
        //modules_.push_back(module);
        return plugin;
      };
      ++desc;
    };
    unload_module(module,*this);
    return NULL;
  }

Here is the call graph for this function:

Plugin * Arc::PluginsFactory::get_instance ( const std::string &  kind,
const std::string &  name,
PluginArgument arg,
bool  search = true 
) [inherited]

Definition at line 297 of file Plugin.cpp.

                                                                                                                  {
    return get_instance(kind,name,0,INT_MAX,arg,search);
  }

Here is the call graph for this function:

Plugin * Arc::PluginsFactory::get_instance ( const std::string &  kind,
const std::string &  name,
int  version,
PluginArgument arg,
bool  search = true 
) [inherited]

Definition at line 301 of file Plugin.cpp.

                                                                                                                              {
    return get_instance(kind,version,version,arg,search);
  }

Here is the call graph for this function:

Plugin * Arc::PluginsFactory::get_instance ( const std::string &  kind,
const std::string &  name,
int  min_version,
int  max_version,
PluginArgument arg,
bool  search = true 
) [inherited]

Definition at line 305 of file Plugin.cpp.

                                                                                                                                                  {
    if(arg) arg->set_factory(this);
    Glib::Mutex::Lock lock(lock_);
    descriptors_t_::iterator i = descriptors_.begin();
    for(;i != descriptors_.end();++i) {
      PluginDescriptor* desc = find_constructor(i->second,kind,name,min_version,max_version);
      if(arg) {
        modules_t_::iterator m = modules_.find(i->first);
        if(m != modules_.end()) {
          arg->set_module(m->second);
        } else {
          arg->set_module(NULL);
        };
      };
      if(desc) {
        lock.release();
        return desc->instance(arg);
      }
    };
    if(!search) return NULL;
    // Try to load module - first by name of plugin
    std::string mname = name;
    ARCModuleDescriptor* mdesc = probe_descriptor(mname,*this);
    if(mdesc) {
      if(!mdesc->contains(kind,name)) {
        delete mdesc;
        logger.msg(ERROR, "Loadable module %s contains no requested plugin %s of kind %s",mname,name,kind);
        return NULL;
      };
      delete mdesc;
      mdesc = NULL;
    };
    // Descriptor not found or indicates presence of requested kinds.
    // Now try to load module directly
    Glib::Module* module = try_load_?probe_module(name,*this):NULL;
    if (module == NULL) {
      // Then by kind of plugin
      mname=kind;
      mdesc = probe_descriptor(mname,*this);
      if(mdesc) {
        if(!mdesc->contains(kind,name)) {
          delete mdesc;
          logger.msg(ERROR, "Loadable module %s contains no requested plugin %s of kind %s",mname,name,kind);
          return NULL;
        };
        delete mdesc;
        mdesc = NULL;
      };
      if(!try_load_) {
        logger.msg(ERROR, "Could not find loadable module descriptor by names %s and %s",name,kind);
        return NULL;
      };
      // Descriptor not found or indicates presence of requested kinds.
      // Now try to load module directly
      module=probe_module(kind,*this);
      logger.msg(ERROR, "Could not find loadable module by names %s and %s (%s)",name,kind,strip_newline(Glib::Module::get_last_error()));
      return NULL;
    };
    // Identify table of descriptors
    void *ptr = NULL;
    if(!module->get_symbol(plugins_table_name,ptr)) {
      logger.msg(VERBOSE, "Module %s is not an ARC plugin (%s)",mname,strip_newline(Glib::Module::get_last_error()));
      unload_module(module,*this);
      return NULL;
    };
    // Try to find plugin in new table
    PluginDescriptor* desc = find_constructor((PluginDescriptor*)ptr,kind,name,min_version,max_version);
    if(desc) {
      // Keep plugin loaded and registered
      Glib::Module* nmodule = reload_module(module,*this);
      if(!nmodule) {
        logger.msg(VERBOSE, "Module %s failed to reload (%s)",mname,strip_newline(Glib::Module::get_last_error()));
        unload_module(module,*this);
        return false;
      };
      descriptors_[mname]=(PluginDescriptor*)ptr;
      modules_[mname]=nmodule;
      //descriptors_.push_back((PluginDescriptor*)ptr);
      //modules_.push_back(module);
      if(arg) arg->set_module(nmodule);
      lock.release();
      return desc->instance(arg);
    };
    unload_module(module,*this);
    return NULL;
  }

Here is the call graph for this function:

ClassLoader * Arc::ClassLoader::getClassLoader ( Config cfg = NULL) [static]

Definition at line 42 of file ClassLoader.cpp.

                                                    {
  if(_instance == NULL && cfg == NULL) {
    std::cout<<"Configuration should not be NULL at the initiation step of singleton ClassLoader"<<std::endl;
    return NULL;
  }
  if(_instance == NULL && cfg != NULL) {
    _instance = new ClassLoader(cfg);
    atexit(freeClassLoader);
  }
  if(_instance != NULL && cfg !=NULL) {
    _instance->setCfg(*cfg);
    _instance->load_all_instances(cfg);
  }
  return _instance;
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class P >
P* Arc::PluginsFactory::GetInstance ( const std::string &  kind,
PluginArgument arg,
bool  search = true 
) [inline, inherited]

Definition at line 176 of file Plugin.h.

                                                                                   {
        Plugin* plugin = get_instance(kind,arg,search);
        if(!plugin) return NULL;
        P* p = dynamic_cast<P*>(plugin);
        if(!p) delete plugin;
        return p;
      };

Here is the call graph for this function:

Here is the caller graph for this function:

template<class P >
P* Arc::PluginsFactory::GetInstance ( const std::string &  kind,
const std::string &  name,
PluginArgument arg,
bool  search = true 
) [inline, inherited]

Definition at line 184 of file Plugin.h.

                                                                                                         {
        Plugin* plugin = get_instance(kind,name,arg,search);
        if(!plugin) return NULL;
        P* p = dynamic_cast<P*>(plugin);
        if(!p) delete plugin;
        return p;
      };

Here is the call graph for this function:

LoadableClass * Arc::ClassLoader::Instance ( const std::string &  classId,
XMLNode arg = NULL,
const std::string &  className = "" 
)

Definition at line 86 of file ClassLoader.cpp.

                                                                                                      {
  /*
  identifier_map_t::iterator it;
  void* ptr;
  for(it=id_map.begin(); it!=id_map.end(); ++it){
    if((!className.empty()) && (className != (*it).first)) continue;
    ptr =(*it).second;
    for(loader_descriptor* desc = (loader_descriptor*)ptr; !((desc->name)==NULL); ++desc) {
      //std::cout<<"size:"<<id_map.size()<<" name:"<<desc->name<<"------classid:"<<classId<<std::endl;
      if(desc->name == classId){ 
        loader_descriptor &descriptor =*desc; 
        LoadableClass * res = NULL;
        res = (*descriptor.get_instance)(arg);
        return res;
      }
    } 
  }
  return NULL;
  */
  ClassLoaderPluginArgument clarg(arg);
  return get_instance(className,classId,&clarg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

LoadableClass * Arc::ClassLoader::Instance ( XMLNode arg = NULL,
const std::string &  className = "" 
)

Definition at line 109 of file ClassLoader.cpp.

                                                                            {
  /*
  identifier_map_t::iterator it;
  void* ptr;
  for(it=id_map.begin(); it!=id_map.end(); ++it){
    if((!className.empty()) && (className != (*it).first)) continue;
    ptr =(*it).second;
    for(loader_descriptor* desc = (loader_descriptor*)ptr; !((desc->name)==NULL); ++desc) {
      loader_descriptor &descriptor =*desc; 
      LoadableClass * res = (*descriptor.get_instance)(arg);
      if(res) return res;
    } 
  }
  return NULL;
  */
  ClassLoaderPluginArgument clarg(arg);
  return get_instance(className,&clarg);
}

Here is the call graph for this function:

Glib::Module * Arc::ModuleManager::load ( const std::string &  name,
bool  probe = false 
) [inherited]

Finds module 'name' in cache or loads corresponding loadable module.

Definition at line 93 of file ModuleManager.cpp.

{
  if (!Glib::Module::get_supported()) {
    return false;
  }
  // find name in plugin_cache 
  {
    plugin_cache_t::iterator p = plugin_cache.find(name);
    if (p != plugin_cache.end()) {
      ModuleManager::logger.msg(DEBUG, "Found %s in cache", name);
      p->second.load();
      return static_cast<Glib::Module*>(p->second);
    }
  }
  std::string path = findLocation(name);
  if(path.empty()) {
    ModuleManager::logger.msg(VERBOSE, "Could not locate module %s in following paths:", name);
    std::vector<std::string>::const_iterator i = plugin_dir.begin();
    for (; i != plugin_dir.end(); i++) {
      ModuleManager::logger.msg(VERBOSE, "\t%s", *i);
    }
    return NULL;
  };
  Glib::ModuleFlags flags = Glib::ModuleFlags(0);
  if(probe) flags|=Glib::MODULE_BIND_LAZY;
  Glib::Module *module = new Glib::Module(path,flags);
  if ((!module) || (!(*module))) {
    ModuleManager::logger.msg(ERROR, strip_newline(Glib::Module::get_last_error()));
    if(module) delete module;
    return NULL;
  }
  ModuleManager::logger.msg(DEBUG, "Loaded %s", path);
  (plugin_cache[name] = module).load();
  return module;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::PluginsFactory::load ( const std::string &  name) [inherited]

These methods load module named lib'name' and check if it contains ARC plugin(s) of specified 'kind' and 'name'.

If there are no specified plugins or module does not contain any ARC plugins it is unloaded. All loaded plugins are also registered in internal list of this instance of PluginsFactory class. Returns true if any plugin was loaded.

Definition at line 392 of file Plugin.cpp.

                                                 {
    std::list<std::string> kinds;
    return load(name,kinds);
  }

Here is the call graph for this function:

bool Arc::PluginsFactory::load ( const std::string &  name,
const std::string &  kind 
) [inherited]

Definition at line 397 of file Plugin.cpp.

                                                                       {
    std::list<std::string> kinds;
    kinds.push_back(kind);
    return load(name,kinds);
  }

Here is the call graph for this function:

bool Arc::PluginsFactory::load ( const std::string &  name,
const std::string &  kind,
const std::string &  pname 
) [inherited]
bool Arc::PluginsFactory::load ( const std::string &  name,
const std::list< std::string > &  kinds 
) [inherited]

Definition at line 403 of file Plugin.cpp.

                                                                                 {
    std::list<std::string> pnames;
    return load(name,kinds,pnames);
  }

Here is the call graph for this function:

bool Arc::PluginsFactory::load ( const std::list< std::string > &  names,
const std::string &  kind 
) [inherited]

Definition at line 485 of file Plugin.cpp.

                                                                                 {
    std::list<std::string> kinds;
    kinds.push_back(kind);
    return load(names,kinds);
  }

Here is the call graph for this function:

bool Arc::PluginsFactory::load ( const std::list< std::string > &  names,
const std::string &  kind,
const std::string &  pname 
) [inherited]

Definition at line 491 of file Plugin.cpp.

                                                                                                        {
    bool r = false;
    std::list<std::string> kinds;
    std::list<std::string> pnames;
    kinds.push_back(kind);
    pnames.push_back(pname);
    for(std::list<std::string>::const_iterator name = names.begin();
                                name != names.end();++name) {
      if(load(*name,kinds,pnames)) r=true;
    }
    return r;
  }

Here is the call graph for this function:

bool Arc::PluginsFactory::load ( const std::list< std::string > &  names,
const std::list< std::string > &  kinds 
) [inherited]

Definition at line 504 of file Plugin.cpp.

                                                                                           {
    bool r = false;
    for(std::list<std::string>::const_iterator name = names.begin();
                                name != names.end();++name) {
      if(load(*name,kinds)) r=true;
    }
    return r;
  }

Here is the call graph for this function:

void Arc::ClassLoader::load_all_instances ( Config cfg) [protected]

Definition at line 58 of file ClassLoader.cpp.

                                               {
  XMLNode root = (*cfg).GetRoot();

  if(!root) return;
  if(!MatchXMLName(root,"ArcConfig")) return;
  for (int i = 0;;++i) {
    XMLNode plugins = root["Plugins"][i];
    if (!plugins) {
      break;
    }
    std::string share_lib_name = (std::string)(plugins.Attribute("Name"));
    
    for(int j = 0;;++j){
      XMLNode plugin = plugins.Child(j);
      if(!plugin){
        break;
      }
      if (MatchXMLName(plugin, "Plugin")) {
        std::string plugin_name = (std::string)(plugin.Attribute("Name"));
        if(!load(share_lib_name,plugin_name)) {
          //std::cout<<"There is no " << plugin_name <<" type plugin"<<std::endl;
        }
      }
    }
  }

}

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::ModuleManager::makePersistent ( Glib::Module *  module) [inherited]

Make sure this module is never unloaded.

Even if unload() is called.

Definition at line 190 of file ModuleManager.cpp.

                                                     {
  for(plugin_cache_t::iterator p = plugin_cache.begin();
                               p!=plugin_cache.end();++p) {
    if(p->second == module) {
      ModuleManager::logger.msg(DEBUG, "%s made persistent", p->first);
      p->second.makePersistent();
      return true;
    }
  }
  ModuleManager::logger.msg(DEBUG, "Specified module not found in cache");
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::ModuleManager::makePersistent ( const std::string &  name) [inherited]

Make sure this module is never unloaded.

Even if unload() is called.

Definition at line 173 of file ModuleManager.cpp.

                                                        {
  if (!Glib::Module::get_supported()) {
    return false;
  }
  // find name in plugin_cache
  {
    plugin_cache_t::iterator p = plugin_cache.find(name);
    if (p != plugin_cache.end()) {
      p->second.makePersistent();
      ModuleManager::logger.msg(DEBUG, "%s made persistent", name);
      return true;
    }
  }
  ModuleManager::logger.msg(DEBUG, "Not found %s in cache", name);
  return false;
}

Here is the call graph for this function:

Glib::Module * Arc::ModuleManager::reload ( Glib::Module *  module) [inherited]

Reload module previously loaded in probe mode.

New module is loaded with all symbols resolved and old module handler is unloaded. In case of error old module is not unloaded.

Definition at line 129 of file ModuleManager.cpp.

{
  plugin_cache_t::iterator p = plugin_cache.begin();
  for(;p!=plugin_cache.end();++p) {
    if(p->second == omodule) break;
  }
  if(p==plugin_cache.end()) return NULL;
  Glib::ModuleFlags flags = Glib::ModuleFlags(0);
  //flags|=Glib::MODULE_BIND_LOCAL;
  Glib::Module *module = new Glib::Module(omodule->get_name(),flags);
  if ((!module) || (!(*module))) {
    ModuleManager::logger.msg(ERROR, strip_newline(Glib::Module::get_last_error()));
    if(module) delete module;
    return NULL;
  }
  p->second=module;
  delete omodule;
  return module; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::PluginsFactory::report ( std::list< ModuleDesc > &  descs) [inherited]

Provides information about currently loaded modules and plugins.

Definition at line 559 of file Plugin.cpp.

                                                        {
    for(descriptors_t_::iterator ds = descriptors_.begin();
               ds != descriptors_.end(); ++ds) {
      PluginDescriptor* d = ds->second;
      if(!d) continue;
      ModuleDesc md;
      md.name = ds->first;
      for(;(d->kind) && (d->name);++d) {
        PluginDesc pd;
        pd.name = d->name;
        pd.kind = d->kind;
        pd.version = d->version;
        md.plugins.push_back(pd);
      };
      descs.push_back(md);
    }
  }
bool Arc::PluginsFactory::scan ( const std::string &  name,
ModuleDesc desc 
) [inherited]

Collect information about plugins stored in module(s) with specified names.

Returns true if any of specified modules has plugins.

Definition at line 513 of file Plugin.cpp.

                                                                   {
    ARCModuleDescriptor* mod = probe_descriptor(name,*this);
    if(mod) {
      desc.name = name;
      mod->get(desc.plugins);
      return true;
    }
    // Descriptor not found
    if(!try_load_) return false;
    // Now try to load module directly
    Glib::Module* module = probe_module(name,*this);
    if (module == NULL) return false;
    // Identify table of descriptors
    void *ptr = NULL;
    if(!module->get_symbol(plugins_table_name,ptr)) {
      unload_module(module,*this);
      return false;
    };
    PluginDescriptor* d = (PluginDescriptor*)ptr;
    if(!d) {
      unload_module(module,*this);
      return false;
    };
    for(;(d->kind) && (d->name);++d) {
      PluginDesc pd;
      pd.name = d->name;
      pd.kind = d->kind;
      pd.version = d->version;
      desc.plugins.push_back(pd);
    };
    return true;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::PluginsFactory::scan ( const std::list< std::string > &  names,
std::list< ModuleDesc > &  descs 
) [inherited]

Definition at line 546 of file Plugin.cpp.

                                                                                       {
    bool r = false;
    ModuleDesc desc;
    for(std::list<std::string>::const_iterator name = names.begin();
                                name != names.end();++name) {
      if(scan(*name,desc)) {
        r=true;
        descs.push_back(desc);
      }
    }
    return r;
  }

Here is the call graph for this function:

void Arc::ModuleManager::setCfg ( XMLNode  cfg) [inherited]

Input the configuration subtree, and trigger the module loading (do almost the same as the Constructor); It is function desgined for ClassLoader to adopt the singleton pattern.

Definition at line 149 of file ModuleManager.cpp.

                                       {
  if(!cfg) return;
  ModuleManager::logger.msg(INFO, "Module Manager Init by ModuleManager::setCfg");

  if(!MatchXMLName(cfg,"ArcConfig")) return;
  XMLNode mm = cfg["ModuleManager"];
  for (int n = 0;;++n) {
    XMLNode path = mm.Child(n);
    if (!path) {
      break;
    }
    if (MatchXMLName(path, "Path")) {
      //std::cout<<"Size:"<<plugin_dir.size()<<"plugin cache size:"<<plugin_cache.size()<<std::endl;
      std::vector<std::string>::const_iterator it;
      for( it = plugin_dir.begin(); it != plugin_dir.end(); it++){
        //std::cout<<(std::string)path<<"*********"<<(*it)<<std::endl;
        if(((*it).compare((std::string)path)) == 0)break;
      }
      if(it == plugin_dir.end())
        plugin_dir.push_back((std::string)path);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::PluginsFactory::TryLoad ( bool  v = true) [inline, inherited]

These methods load module named lib'name', locate plugin constructor functions of specified 'kind' and 'name' (if specified) and call it.

Supplied argument affects way plugin instance is created in plugin-specific way. If name of plugin is not specified then all plugins of specified kind are tried with supplied argument till valid instance is created. All loaded plugins are also registered in internal list of this instance of PluginsFactory class. If search is set to false then no attempt is made to find plugins in loadable modules. Only plugins already loaded with previous calls to get_instance() and load() are checked. Returns created instance or NULL if failed. Specifies if loadable module may be loaded while looking for analyzing its content. If set to false only *.apd files are checked. Modules without corresponding *.apd will be ignored. Default is true;

Definition at line 145 of file Plugin.h.

{ try_load_ = v; };
bool Arc::PluginsFactory::TryLoad ( void  ) [inline, inherited]

Definition at line 146 of file Plugin.h.

{ return try_load_; };
void Arc::ModuleManager::unload ( Glib::Module *  module) [inherited]

Unload module by its identifier.

Definition at line 65 of file ModuleManager.cpp.

{
  for(plugin_cache_t::iterator p = plugin_cache.begin();
                               p!=plugin_cache.end();++p) {
    if(p->second == module) {
      if(p->second.unload() <= 0) {
        plugin_cache.erase(p);
      }      
      break;
    }
  }
}

Here is the caller graph for this function:

void Arc::ModuleManager::unload ( const std::string &  name) [inherited]

Unload module by its name.

Definition at line 78 of file ModuleManager.cpp.

{
  plugin_cache_t::iterator p = plugin_cache.find(name);
  if (p != plugin_cache.end()) {
    if(p->second.unload() <= 0) {
      plugin_cache.erase(p);
    }
  }
}

Member Data Documentation

ClassLoader * Arc::ClassLoader::_instance = NULL [static, private]

Definition at line 37 of file ClassLoader.h.

Logger Arc::ClassLoader::logger [static, private]

Reimplemented from Arc::PluginsFactory.

Definition at line 36 of file ClassLoader.h.


The documentation for this class was generated from the following files: