Gaudi::PluginService::Details::Registry Class Reference

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

#include </scratch/z5/marcocle/GaudiDocs/lhcb-release/825/GAUDI/GAUDI_v26r3/InstallArea/x86_64-slc6-gcc48-opt/include/Gaudi/Details/PluginServiceDetails.h>

Collaboration diagram for Gaudi::PluginService::Details::Registry:

Classes

struct  FactoryInfo
 

Public Types

typedef std::string KeyType
 
typedef std::map< KeyType, std::string > Properties
 Type used for the properties implementation. More...
 
typedef std::map< KeyType, FactoryInfoFactoryMap
 Type used for the database implementation. More...
 
typedef std::string KeyType
 
typedef std::map< KeyType, std::string > Properties
 Type used for the properties implementation. More...
 
typedef std::map< KeyType, FactoryInfoFactoryMap
 Type used for the database implementation. More...
 

Public Member Functions

template<typename F , typename T , typename I >
FactoryInfoadd (const I &id, typename F::FuncType ptr)
 Add a factory to the database. More...
 
void * get (const std::string &id, const std::string &type) const
 Retrieve the factory for the given id. More...
 
const FactoryInfogetInfo (const std::string &id) const
 Retrieve the FactoryInfo object for an id. More...
 
RegistryaddProperty (const std::string &id, const std::string &k, const std::string &v)
 Add a property to an already existing FactoryInfo object (via its id.) More...
 
std::set< KeyTypeloadedFactories () const
 Return a list of all the known and loaded factories. More...
 
const FactoryMapfactories () const
 Return the known factories (loading the list if not yet done). More...
 
template<typename F , typename T , typename I >
FactoryInfoadd (const I &id, typename F::FuncType ptr)
 Add a factory to the database. More...
 
void * get (const std::string &id, const std::string &type) const
 Retrieve the factory for the given id. More...
 
const FactoryInfogetInfo (const std::string &id) const
 Retrieve the FactoryInfo object for an id. More...
 
RegistryaddProperty (const std::string &id, const std::string &k, const std::string &v)
 Add a property to an already existing FactoryInfo object (via its id.) More...
 
std::set< KeyTypeloadedFactories () const
 Return a list of all the known and loaded factories. More...
 
const FactoryMapfactories () const
 Return the known factories (loading the list if not yet done). More...
 

Static Public Member Functions

static Registryinstance ()
 Retrieve the singleton instance of Registry. More...
 
static Registryinstance ()
 Retrieve the singleton instance of Registry. More...
 

Private Member Functions

 Registry ()
 Private constructor for the singleton pattern. More...
 
 Registry (const Registry &)
 Private copy constructor for the singleton pattern. More...
 
FactoryInfoadd (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. More...
 
FactoryMapfactories ()
 Return the known factories (loading the list if not yet done). More...
 
void initialize ()
 Initialize the registry loading the list of factories from the .component files in the library search path. More...
 
 Registry ()
 Private constructor for the singleton pattern. More...
 
 Registry (const Registry &)
 Private copy constructor for the singleton pattern. More...
 
FactoryInfoadd (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. More...
 
FactoryMapfactories ()
 Return the known factories (loading the list if not yet done). More...
 
void initialize ()
 Initialize the registry loading the list of factories from the .component files in the library search path. More...
 

Private Attributes

bool m_initialized
 Flag recording if the registry has been initialized or not. More...
 
FactoryMap m_factories
 Internal storage for factories. More...
 

Detailed Description

In-memory database of the loaded factories.

Definition at line 99 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 128 of file PluginServiceDetails.h.

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

Type used for the database implementation.

Definition at line 128 of file PluginServiceDetails.h.

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

Definition at line 101 of file PluginServiceDetails.h.

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

Definition at line 101 of file PluginServiceDetails.h.

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

Type used for the properties implementation.

Definition at line 104 of file PluginServiceDetails.h.

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

Type used for the properties implementation.

Definition at line 104 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 142 of file PluginService.cpp.

142 : m_initialized(false) {}
bool m_initialized
Flag recording if the registry has been initialized or not.
Gaudi::PluginService::Details::Registry::Registry ( const Registry )
inlineprivate

Private copy constructor for the singleton pattern.

Definition at line 174 of file PluginServiceDetails.h.

174 : m_initialized(false) {}
bool m_initialized
Flag recording if the registry has been initialized or not.
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.

Gaudi::PluginService::Details::Registry::Registry ( const Registry )
inlineprivate

Private copy constructor for the singleton pattern.

Definition at line 174 of file PluginServiceDetails.h.

174 : m_initialized(false) {}
bool m_initialized
Flag recording if the registry has been initialized or not.

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 135 of file PluginServiceDetails.h.

135  {
136  union { typename F::FuncType src; void* dst; } p2p;
137  p2p.src = ptr;
138  std::ostringstream o; o << id;
139  return add(o.str(), p2p.dst,
140  typeid(typename F::FuncType).name(),
141  typeid(typename F::ReturnType).name(),
142  demangle<T>());
143  }
FactoryInfo & add(const I &id, typename F::FuncType ptr)
Add a factory to the database.
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 135 of file PluginServiceDetails.h.

135  {
136  union { typename F::FuncType src; void* dst; } p2p;
137  p2p.src = ptr;
138  std::ostringstream o; o << id;
139  return add(o.str(), p2p.dst,
140  typeid(typename F::FuncType).name(),
141  typeid(typename F::ReturnType).name(),
142  demangle<T>());
143  }
FactoryInfo & add(const I &id, typename F::FuncType ptr)
Add a factory to the database.
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 238 of file PluginService.cpp.

241  {
243  FactoryMap &facts = factories();
244  FactoryMap::iterator entry = facts.find(id);
245  if (entry == facts.end())
246  {
247  // this factory was not known yet
248  entry = facts.insert(std::make_pair(id,
249  FactoryInfo("unknown", factory,
250  type, rtype, className, props))).first;
251  } else {
252  // do not replace an existing factory with a new one
253  if (!entry->second.ptr) {
254  entry->second.ptr = factory;
255  }
256  factoryInfoSetHelper(entry->second.type, type, "type", id);
257  factoryInfoSetHelper(entry->second.rtype, rtype, "return type", id);
258  factoryInfoSetHelper(entry->second.className, className, "class", id);
259  }
260 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
261  // add an alias for the factory using the Reflex convention
262  std::string old_name = old_style_name(id);
263  if (id != old_name)
264  add(old_name, factory, type, rtype, className, props)
265  .properties["ReflexName"] = "true";
266 #endif
267  return entry->second;
268  }
#define REG_SCOPE_LOCK
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
FactoryInfo & add(const I &id, typename F::FuncType ptr)
Add a factory to the database.
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
string type
Definition: gaudirun.py:151
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.

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 316 of file PluginService.cpp.

318  {
320  FactoryMap &facts = factories();
321  FactoryMap::iterator f = facts.find(id);
322  if (f != facts.end())
323  {
324  f->second.properties[k] = v;
325  }
326  return *this;
327  }
#define REG_SCOPE_LOCK
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
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.)

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

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

Definition at line 161 of file PluginServiceDetails.h.

161  {
162  if (!m_initialized) const_cast<Registry*>(this)->initialize();
163  return m_factories;
164  }
Registry()
Private constructor for the singleton pattern.
void initialize()
Initialize the registry loading the list of factories from the .component files in the library search...
FactoryMap m_factories
Internal storage for factories.
bool m_initialized
Flag recording if the registry has been initialized or not.
const FactoryMap& Gaudi::PluginService::Details::Registry::factories ( ) const
inline

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

Definition at line 161 of file PluginServiceDetails.h.

161  {
162  if (!m_initialized) const_cast<Registry*>(this)->initialize();
163  return m_factories;
164  }
Registry()
Private constructor for the singleton pattern.
void initialize()
Initialize the registry loading the list of factories from the .component files in the library search...
FactoryMap m_factories
Internal storage for factories.
bool m_initialized
Flag recording if the registry has been initialized or not.
FactoryMap& Gaudi::PluginService::Details::Registry::factories ( )
inlineprivate

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

Definition at line 184 of file PluginServiceDetails.h.

184  {
185  if (!m_initialized) initialize();
186  return m_factories;
187  }
void initialize()
Initialize the registry loading the list of factories from the .component files in the library search...
FactoryMap m_factories
Internal storage for factories.
bool m_initialized
Flag recording if the registry has been initialized or not.
FactoryMap& Gaudi::PluginService::Details::Registry::factories ( )
inlineprivate

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

Definition at line 184 of file PluginServiceDetails.h.

184  {
185  if (!m_initialized) initialize();
186  return m_factories;
187  }
void initialize()
Initialize the registry loading the list of factories from the .component files in the library search...
FactoryMap m_factories
Internal storage for factories.
bool m_initialized
Flag recording if the registry has been initialized or not.
void* Gaudi::PluginService::Details::Registry::get ( const std::string &  id,
const std::string &  type 
) const

Retrieve the factory for the given id.

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 270 of file PluginService.cpp.

270  {
272  const FactoryMap &facts = factories();
273  FactoryMap::const_iterator f = facts.find(id);
274  if (f != facts.end())
275  {
276 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
277  const Properties& props = f->second.properties;
278  if (props.find("ReflexName") != props.end())
279  logger().warning("requesting factory via old name '" + id + "'"
280  "use '" + f->second.className + "' instead");
281 #endif
282  if (!f->second.ptr) {
283  if (!dlopen(f->second.library.c_str(), RTLD_LAZY | RTLD_GLOBAL)) {
284  logger().warning("cannot load " + f->second.library +
285  " for factory " + id);
286  char *dlmsg = dlerror();
287  if (dlmsg)
288  logger().warning(dlmsg);
289  return 0;
290  }
291  f = facts.find(id); // ensure that the iterator is valid
292  }
293  if (f->second.type == type) {
294  return f->second.ptr;
295  } else {
296  logger().warning("found factory " + id + ", but of wrong type: " +
297  demangle(f->second.type) + " instead of " + demangle(type));
298  }
299  }
300  return 0; // factory not found
301  }
#define REG_SCOPE_LOCK
GAUDIPS_API Logger & logger()
Return the current logger instance.
std::map< KeyType, std::string > Properties
Type used for the properties implementation.
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
GAUDIPS_API std::string demangle(const std::type_info &id)
Return a canonical name for type_info object (implementation borrowed from GaudiKernel/System).
void warning(const std::string &msg)
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
string type
Definition: gaudirun.py:151
const Registry::FactoryInfo & Gaudi::PluginService::Details::Registry::getInfo ( const std::string &  id) const

Retrieve the FactoryInfo object for an id.

Definition at line 303 of file PluginService.cpp.

303  {
305  static FactoryInfo unknown("unknown");
306  const FactoryMap &facts = factories();
307  FactoryMap::const_iterator f = facts.find(id);
308  if (f != facts.end())
309  {
310  return f->second;
311  }
312  return unknown; // factory not found
313  }
#define REG_SCOPE_LOCK
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
const FactoryInfo& Gaudi::PluginService::Details::Registry::getInfo ( const std::string &  id) const

Retrieve the FactoryInfo object for an id.

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

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

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 144 of file PluginService.cpp.

144  {
146  if (m_initialized) return;
147  m_initialized = true;
148 #ifdef WIN32
149  const char* envVar = "PATH";
150  const char sep = ';';
151 #else
152  const char* envVar = "LD_LIBRARY_PATH";
153  const char sep = ':';
154 #endif
155  char *search_path = ::getenv(envVar);
156  if (search_path) {
157  logger().debug(std::string("searching factories in ") + envVar);
158  std::string path(search_path);
159  std::string::size_type pos = 0;
160  std::string::size_type newpos = 0;
161  while (pos != std::string::npos) {
162  std::string dirName;
163  // get the next entry in the path
164  newpos = path.find(sep, pos);
165  if (newpos != std::string::npos) {
166  dirName = path.substr(pos, newpos - pos);
167  pos = newpos+1;
168  } else {
169  dirName = path.substr(pos);
170  pos = newpos;
171  }
172  logger().debug(std::string(" looking into ") + dirName);
173  // look for files called "*.components" in the directory
174  DIR *dir = opendir(dirName.c_str());
175  if (dir) {
176  struct dirent * entry;
177  while ((entry = readdir(dir))) {
178  std::string name(entry->d_name);
179  // check if the file name ends with ".components"
180  std::string::size_type extpos = name.find(".components");
181  if ((extpos != std::string::npos) &&
182  ((extpos+11) == name.size())) {
183  std::string fullPath = (dirName + '/' + name);
184  { // check if it is a regular file
185  struct stat buf;
186  stat(fullPath.c_str(), &buf);
187  if (!S_ISREG(buf.st_mode)) continue;
188  }
189  // read the file
190  logger().debug(std::string(" reading ") + name);
191  std::ifstream factories(fullPath.c_str());
192  std::string line;
193  int factoriesCount = 0;
194  int lineCount = 0;
195  while (!factories.eof()) {
196  ++lineCount;
197  std::getline(factories, line);
198  trim(line);
199  // skip empty lines and lines starting with '#'
200  if (line.empty() || line[0] == '#') continue;
201  // look for the separator
202  std::string::size_type pos = line.find(':');
203  if (pos == std::string::npos) {
204  std::ostringstream o;
205  o << "failed to parse line " << fullPath
206  << ':' << lineCount;
207  logger().warning(o.str());
208  continue;
209  }
210  const std::string lib(line, 0, pos);
211  const std::string fact(line, pos+1);
212  m_factories.insert(std::make_pair(fact, FactoryInfo(lib)));
213 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
214  // add an alias for the factory using the Reflex convention
215  std::string old_name = old_style_name(fact);
216  if (fact != old_name) {
217  FactoryInfo old_info(lib);
218  old_info.properties["ReflexName"] = "true";
219  m_factories.insert(std::make_pair(old_name, old_info));
220  }
221 #endif
222  ++factoriesCount;
223  }
224  if (logger().level() <= Logger::Debug) {
225  std::ostringstream o;
226  o << " found " << factoriesCount << " factories";
227  logger().debug(o.str());
228  }
229  }
230  }
231  closedir(dir);
232  }
233  }
234  }
235  }
#define REG_SCOPE_LOCK
list path
Definition: __init__.py:15
GAUDIPS_API Logger & logger()
Return the current logger instance.
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
void warning(const std::string &msg)
FactoryMap m_factories
Internal storage for factories.
bool m_initialized
Flag recording if the registry has been initialized or not.
int line
Definition: ana.py:50
Registry & Gaudi::PluginService::Details::Registry::instance ( )
static

Retrieve the singleton instance of Registry.

Definition at line 136 of file PluginService.cpp.

136  {
138  static Registry r;
139  return r;
140  }
Registry()
Private constructor for the singleton pattern.
#define SINGLETON_LOCK
static Registry& Gaudi::PluginService::Details::Registry::instance ( )
static

Retrieve the singleton instance of Registry.

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

Return a list of all the known and loaded factories.

Definition at line 329 of file PluginService.cpp.

329  {
331  const FactoryMap &facts = factories();
332  std::set<KeyType> l;
333  for (FactoryMap::const_iterator f = facts.begin();
334  f != facts.end(); ++f)
335  {
336  if (f->second.ptr)
337  l.insert(f->first);
338  }
339  return l;
340  }
#define REG_SCOPE_LOCK
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
dictionary l
Definition: gaudirun.py:420
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
std::set<KeyType> Gaudi::PluginService::Details::Registry::loadedFactories ( ) const

Return a list of all the known and loaded factories.

Member Data Documentation

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

Internal storage for factories.

Definition at line 197 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 194 of file PluginServiceDetails.h.


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