Back to index

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

Generic ARC plugins loader. More...

#include <Plugin.h>

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

List of all members.

Public Member Functions

 PluginsFactory (XMLNode cfg)
 Constructor - accepts configuration (not yet used) meant to tune loading of modules.
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 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)
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)
Glib::Module * load (const std::string &name, bool probe=false)
 Finds module 'name' in cache or loads corresponding loadable module.
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.

Private Types

typedef std::map< std::string,
PluginDescriptor * > 
descriptors_t_
typedef std::map< std::string,
Glib::Module * > 
modules_t_

Private Member Functions

bool load (const std::string &name, const std::list< std::string > &kinds, const std::list< std::string > &pnames)

Private Attributes

Glib::Mutex lock_
descriptors_t_ descriptors_
modules_t_ modules_
bool try_load_

Static Private Attributes

static Logger logger

Detailed Description

Generic ARC plugins loader.

The instance of this class provides functionality of loading pluggable ARC components stored in shared libraries. For more information please check HED documentation. This class is thread-safe - its methods are proceted from simultatneous use form multiple threads. Current thread protection implementation is suboptimal and will be revised in future.

Definition at line 115 of file Plugin.h.


Member Typedef Documentation

typedef std::map<std::string,PluginDescriptor*> Arc::PluginsFactory::descriptors_t_ [private]

Definition at line 118 of file Plugin.h.

typedef std::map<std::string,Glib::Module*> Arc::PluginsFactory::modules_t_ [private]

Definition at line 119 of file Plugin.h.


Constructor & Destructor Documentation

Constructor - accepts configuration (not yet used) meant to tune loading of modules.

Definition at line 577 of file Plugin.cpp.

                                           : ModuleManager(cfg),
                                               try_load_(true) {
  }

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 
)

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 
)

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 
)

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 
)

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 
)

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 
)

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:

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

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]

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:

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,
const std::list< std::string > &  kinds,
const std::list< std::string > &  pnames 
) [private]

Definition at line 408 of file Plugin.cpp.

                                                                                                                  {
    // In real use-case all combinations of kinds and pnames
    // have no sense. So normally if both are defined each contains
    // only onr item.
    if(name.empty()) return false;
    Glib::Module* module = NULL;
    PluginDescriptor* desc = NULL;
    void *ptr = NULL;
    std::string mname;
    Glib::Mutex::Lock lock(lock_);
    // Check if module already loaded
    descriptors_t_::iterator d = descriptors_.find(name);
    if(d != descriptors_.end()) {
      desc = d->second;
      if(!desc) return false;
    } else {
      // Try to load module by specified name
      mname = name;
      // First try to find descriptor of module
      ARCModuleDescriptor* mdesc = probe_descriptor(mname,*this);
      if(mdesc) {
        if(!mdesc->contains(kinds)) {
          //logger.msg(VERBOSE, "Module %s does not contain plugin(s) of specified kind(s)",mname);
          delete mdesc;
          return false;
        };
        delete mdesc;
        mdesc = NULL;
      };
      if(!try_load_) {
        logger.msg(ERROR, "Could not find loadable module descriptor by name %s",name);
        return NULL;
      };
      // Descriptor not found or indicates presence of requested kinds.
      // Descriptor not found or indicates presence of requested kinds.
      // Now try to load module directly
      module = probe_module(mname,*this);
      if (module == NULL) {
        logger.msg(ERROR, "Could not find loadable module by name %s (%s)",name,strip_newline(Glib::Module::get_last_error()));
        return false;
      };
      // Identify table of descriptors
      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 false;
      };
      desc = (PluginDescriptor*)ptr;
    };
    if(kinds.size() > 0) {
      for(std::list<std::string>::const_iterator kind = kinds.begin();
          kind != kinds.end(); ++kind) {
        if(kind->empty()) continue;
        desc=find_constructor(desc,*kind,0,INT_MAX);
        if(desc) break;
      };
      if(!desc) {
        //logger.msg(VERBOSE, "Module %s does not contain plugin(s) of specified kind(s)",mname);
        if(module) unload_module(module,*this);
        return false;
      };
    };
    if(!mname.empty()) {
      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 true;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::PluginsFactory::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'.

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 
)

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 
)
bool Arc::PluginsFactory::load ( const std::string &  name,
const std::list< std::string > &  kinds 
)

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 
)

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 
)

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 
)

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:

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)

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 
)

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 
)

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]

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]

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

Definition at line 120 of file Plugin.h.

Glib::Mutex Arc::PluginsFactory::lock_ [private]

Definition at line 117 of file Plugin.h.

Reimplemented from Arc::ModuleManager.

Reimplemented in Arc::ClassLoader.

Definition at line 123 of file Plugin.h.

Definition at line 121 of file Plugin.h.

Definition at line 122 of file Plugin.h.


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