| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Gaudi::PluginService::Details::Registry Class Reference

In-memory database of the loaded factories. More...

`#include <PluginServiceDetails.h>`

Collaboration diagram for Gaudi::PluginService::Details::Registry:
[legend]

## Classes
struct | FactoryInfo

## Public Types
typedef std::string | KeyType
typedef std::map< KeyType, std::string > | Properties
| Type used for the properties implementation.
typedef std::map< KeyType, FactoryInfo > | FactoryMap
| Type used for the database implementation.

## Public Member Functions
template<typename F , typename T , typename I >
FactoryInfo & | add (const I &id, typename F::FuncType ptr)
| Add a factory to the database.
void * | get (const std::string &id, const std::string &type) const
| Retrieve the factory for the given id.
const FactoryInfo & | getInfo (const std::string &id) const
| Retrieve the FactoryInfo object for an id.
Registry & | addProperty (const std::string &id, const std::string &k, const std::string &v)
| Add a property to an already existing FactoryInfo object (via its id.)
std::set< KeyType > | loadedFactories () const
| Return a list of all the known and loaded factories.
const FactoryMap & | factories () const
| Return the known factories (loading the list if not yet done).

## Static Public Member Functions
static Registry & | instance ()
| Retrieve the singleton instance of Registry.

## Private Member Functions
| Registry ()
| Private constructor for the singleton pattern.
| Registry (const Registry &)
| Private copy constructor for the singleton pattern.
FactoryInfo & | add (const std::string &id, void *factory, const std::string &type, const std::string &rtype, const std::string &className, const Properties &props=Properties())
| Add a factory to the database.
FactoryMap & | factories ()
| Return the known factories (loading the list if not yet done).
void | initialize ()
| Initialize the registry loading the list of factories from the .component files in the library search path.

## Private Attributes
bool | m_initialized
| Flag recording if the registry has been initialized or not.
FactoryMap | m_factories
| Internal storage for factories.

## Detailed Description

In-memory database of the loaded factories.

Definition at line 116 of file PluginServiceDetails.h.

## Member Typedef Documentation

typedef std::map<KeyType, FactoryInfo> Gaudi::PluginService::Details::Registry::FactoryMap

Type used for the database implementation.

Definition at line 145 of file PluginServiceDetails.h.

typedef std::string Gaudi::PluginService::Details::Registry::KeyType

Definition at line 118 of file PluginServiceDetails.h.

typedef std::map<KeyType, std::string> Gaudi::PluginService::Details::Registry::Properties

Type used for the properties implementation.

Definition at line 121 of file PluginServiceDetails.h.

## Constructor & Destructor Documentation

Gaudi::PluginService::Details::Registry::Registry | ( |  | ) |
| private

Private constructor for the singleton pattern.

At construction time, the internal database of known factories is filled with the name of the libraries containing them, using the ".components" files in the LD_LIBRARY_PATH.

Definition at line 129 of file PluginService.cpp.

: m_initialized(false) {}

Gaudi::PluginService::Details::Registry::Registry | ( | const Registry & |  | ) |
| inline private

Private copy constructor for the singleton pattern.

Definition at line 191 of file PluginServiceDetails.h.

: m_initialized(false) {}

## Member Function Documentation

template<typename F , typename T , typename I >

FactoryInfo& Gaudi::PluginService::Details::Registry::add | ( | const I & | id,
|  | typename F::FuncType | ptr
| ) |  |
| inline

Add a factory to the database.

Definition at line 152 of file PluginServiceDetails.h.

{
union { typename F::FuncType src; void* dst; } p2p;
p2p.src = ptr;
std::ostringstream o; o << id;
return add(o.str(), p2p.dst,
typeid(typename F::FuncType).name(),
typeid(typename F::ReturnType).name(),
demangle<T>());
}

Registry::FactoryInfo & Gaudi::PluginService::Details::Registry::add | ( | const std::string & | id,
|  | void * | factory,
|  | const std::string & | type,
|  | const std::string & | rtype,
|  | const std::string & | className,
|  | const Properties & | props = `Properties()`
| ) |  |
| private

Add a factory to the database.

Definition at line 225 of file PluginService.cpp.

{
REG_SCOPE_LOCK
FactoryMap &facts = factories();
FactoryMap::iterator entry = facts.find(id);
if (entry == facts.end())
{
// this factory was not known yet
entry = facts.insert(std::make_pair(id,
FactoryInfo("unknown", factory,
type, rtype, className, props))).first;
} else {
// do not replace an existing factory with a new one
if (!entry->second.ptr) {
entry->second.ptr = factory;
}
factoryInfoSetHelper(entry->second.type, type, "type", id);
factoryInfoSetHelper(entry->second.rtype, rtype, "return type", id);
factoryInfoSetHelper(entry->second.className, className, "class", id);
}
#ifdef GAUDI_REFLEX_COMPONENT_ALIASES
// add an alias for the factory using the Reflex convention
std::string old_name = old_style_name(id);
if (id != old_name)
add(old_name, factory, type, rtype, className, props)
.properties["ReflexName"] = "true";
#endif
return entry->second;
}

Registry & Gaudi::PluginService::Details::Registry::addProperty | ( | const std::string & | id,
|  | const std::string & | k,
|  | const std::string & | v
| ) |  |

Add a property to an already existing FactoryInfo object (via its id.)

Definition at line 303 of file PluginService.cpp.

{
REG_SCOPE_LOCK
FactoryMap &facts = factories();
FactoryMap::iterator f = facts.find(id);
if (f != facts.end())
{
f->second.properties[k] = v;
}
return *this;
}

const FactoryMap& Gaudi::PluginService::Details::Registry::factories | ( |  | ) | const
| inline

Return the known factories (loading the list if not yet done).

Definition at line 178 of file PluginServiceDetails.h.

{
if (!m_initialized) const_cast<Registry*>(this)->initialize();
return m_factories;
}

FactoryMap& Gaudi::PluginService::Details::Registry::factories | ( |  | ) |
| inline private

Return the known factories (loading the list if not yet done).

Definition at line 201 of file PluginServiceDetails.h.

{
if (!m_initialized) initialize();
return m_factories;
}

void * Gaudi::PluginService::Details::Registry::get | ( | const std::string & | id,
|  | const std::string & | type
| ) |  | const

Retrieve the factory for the given id.

Definition at line 257 of file PluginService.cpp.

{
REG_SCOPE_LOCK
const FactoryMap &facts = factories();
FactoryMap::const_iterator f = facts.find(id);
if (f != facts.end())
{
#ifdef GAUDI_REFLEX_COMPONENT_ALIASES
const Properties& props = f->second.properties;
if (props.find("ReflexName") != props.end())
logger().warning("requesting factory via old name '" + id + "'"
"use '" + f->second.className + "' instead");
#endif
if (!f->second.ptr) {
if (!dlopen(f->second.library.c_str(), RTLD_LAZY | RTLD_GLOBAL)) {
logger().warning("cannot load " + f->second.library +
" for factory " + id);
char *dlmsg = dlerror();
if (dlmsg)
logger().warning(dlmsg);
return 0;
}
f = facts.find(id); // ensure that the iterator is valid
}
if (f->second.type == type) {
return f->second.ptr;
} else {
logger().warning("found factory " + id + ", but of wrong type: " +
f->second.type + " instead of " + type);
}
}
return 0; // factory not found
}

const Registry::FactoryInfo & Gaudi::PluginService::Details::Registry::getInfo | ( | const std::string & | id | ) | const

Retrieve the FactoryInfo object for an id.

Definition at line 290 of file PluginService.cpp.

{
REG_SCOPE_LOCK
static FactoryInfo unknown("unknown");
const FactoryMap &facts = factories();
FactoryMap::const_iterator f = facts.find(id);
if (f != facts.end())
{
return f->second;
}
return unknown; // factory not found
}

void Gaudi::PluginService::Details::Registry::initialize | ( |  | ) |
| private

Initialize the registry loading the list of factories from the .component files in the library search path.

Definition at line 131 of file PluginService.cpp.

{
REG_SCOPE_LOCK
if (m_initialized) return;
m_initialized = true;
#ifdef WIN32
const char* envVar = "PATH";
const char sep = ';';
#else
const char* envVar = "LD_LIBRARY_PATH";
const char sep = ':';
#endif
char *search_path = ::getenv(envVar);
if (search_path) {
logger().debug(std::string("searching factories in ") + envVar);
std::string path(search_path);
std::string::size_type pos = 0;
std::string::size_type newpos = 0;
while (pos != std::string::npos) {
std::string dirName;
// get the next entry in the path
newpos = path.find(sep, pos);
if (newpos != std::string::npos) {
dirName = path.substr(pos, newpos - pos);
pos = newpos+1;
} else {
dirName = path.substr(pos);
pos = newpos;
}
logger().debug(std::string(" looking into ") + dirName);
// look for files called "*.components" in the directory
DIR *dir = opendir(dirName.c_str());
if (dir) {
struct dirent * entry;
while ((entry = readdir(dir))) {
std::string name(entry->d_name);
// check if the file name ends with ".components"
std::string::size_type extpos = name.find(".components");
if ((extpos != std::string::npos) &&
((extpos+11) == name.size())) {
std::string fullPath = (dirName + '/' + name);
{ // check if it is a regular file
struct stat buf;
stat(fullPath.c_str(), &buf);
if (!S_ISREG(buf.st_mode)) continue;
}
// read the file
logger().debug(std::string(" reading ") + name);
std::ifstream factories(fullPath.c_str());
std::string line;
int factoriesCount = 0;
int lineCount = 0;
while (!factories.eof()) {
++lineCount;
std::getline(factories, line);
trim(line);
// skip empty lines and lines starting with '#'
if (line.empty() || line[0] == '#') continue;
// look for the separator
std::string::size_type pos = line.find(':');
if (pos == std::string::npos) {
std::ostringstream o;
o << "failed to parse line " << fullPath
<< ':' << lineCount;
logger().warning(o.str());
continue;
}
const std::string lib(line, 0, pos);
const std::string fact(line, pos+1);
m_factories.insert(std::make_pair(fact, FactoryInfo(lib)));
#ifdef GAUDI_REFLEX_COMPONENT_ALIASES
// add an alias for the factory using the Reflex convention
std::string old_name = old_style_name(fact);
if (fact != old_name) {
FactoryInfo old_info(lib);
old_info.properties["ReflexName"] = "true";
m_factories.insert(std::make_pair(old_name, old_info));
}
#endif
++factoriesCount;
}
if (logger().level() <= Logger::Debug) {
std::ostringstream o;
o << " found " << factoriesCount << " factories";
logger().debug(o.str());
}
}
}
closedir(dir);
}
}
}
}

Registry & Gaudi::PluginService::Details::Registry::instance | ( |  | ) |
| static

Retrieve the singleton instance of Registry.

Definition at line 123 of file PluginService.cpp.

{
SINGLETON_LOCK
static Registry r;
return r;
}

std::set< Registry::KeyType > Gaudi::PluginService::Details::Registry::loadedFactories | ( |  | ) | const

Return a list of all the known and loaded factories.

Definition at line 316 of file PluginService.cpp.

{
REG_SCOPE_LOCK
const FactoryMap &facts = factories();
std::set<KeyType> l;
for (FactoryMap::const_iterator f = facts.begin();
f != facts.end(); ++f)
{
if (f->second.ptr)
l.insert(f->first);
}
return l;
}

## Member Data Documentation

FactoryMap Gaudi::PluginService::Details::Registry::m_factories
| private

Internal storage for factories.

Definition at line 214 of file PluginServiceDetails.h.

bool Gaudi::PluginService::Details::Registry::m_initialized
| private

Flag recording if the registry has been initialized or not.

Definition at line 211 of file PluginServiceDetails.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiPluginService/Gaudi/Details/PluginServiceDetails.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiPluginService/src/PluginService.cpp