27 #if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
28 #define REG_SCOPE_LOCK \
29 std::lock_guard<std::recursive_mutex> _guard(m_mutex);
32 std::mutex registrySingletonMutex;
34 #define SINGLETON_LOCK \
35 std::lock_guard<std::mutex> _guard(::registrySingletonMutex);
37 #define REG_SCOPE_LOCK
38 #define SINGLETON_LOCK
74 }
else if (dest != value) {
76 o <<
"new factory loaded for '" <<
id <<
"' with different "
77 << desc <<
": " << dest <<
" != " << value;
84 void operator() (
const char c) {
95 name.push_back(
'r');
break;
97 name.push_back(
'p');
break;
100 name.push_back(c);
break;
106 return std::for_each(name.begin(), name.end(), OldStyleCnv()).name;
110 namespace Gaudi {
namespace PluginService {
113 Exception::~Exception() throw() {}
114 const char* Exception::what()
const throw() {
115 return m_msg.c_str();
120 return Registry::instance().get(
id, type);
129 Registry::Registry(): m_initialized(false) {}
133 if (m_initialized)
return;
134 m_initialized =
true;
136 const char* envVar =
"PATH";
137 const char sep =
';';
139 const char* envVar =
"LD_LIBRARY_PATH";
140 const char sep =
':';
142 char *search_path = ::getenv(envVar);
148 while (pos != std::string::npos) {
151 newpos = path.
find(sep, pos);
152 if (newpos != std::string::npos) {
153 dirName = path.substr(pos, newpos - pos);
156 dirName = path.substr(pos);
161 DIR *dir = opendir(dirName.c_str());
163 struct dirent * entry;
164 while ((entry = readdir(dir))) {
168 if ((extpos != std::string::npos) &&
169 ((extpos+11) == name.size())) {
173 stat(fullPath.c_str(), &buf);
174 if (!S_ISREG(buf.st_mode))
continue;
180 int factoriesCount = 0;
187 if (line.empty() || line[0] ==
'#')
continue;
190 if (pos == std::string::npos) {
192 o <<
"failed to parse line " << fullPath
200 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
203 if (fact != old_name) {
213 o <<
" found " << factoriesCount <<
" factories";
232 if (entry == facts.end())
237 type, rtype, className, props))).first;
240 if (!entry->second.ptr) {
241 entry->second.ptr = factory;
243 factoryInfoSetHelper(entry->second.type, type,
"type",
id);
244 factoryInfoSetHelper(entry->second.rtype, rtype,
"return type",
id);
245 factoryInfoSetHelper(entry->second.className, className,
"class",
id);
247 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
251 add(old_name, factory, type, rtype, className, props)
252 .properties[
"ReflexName"] =
"true";
254 return entry->second;
261 if (f != facts.end())
263 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
264 const Properties& props = f->second.properties;
265 if (props.
find(
"ReflexName") != props.
end())
266 logger().
warning(
"requesting factory via old name '" +
id +
"'"
267 "use '" + f->second.className +
"' instead");
269 if (!f->second.ptr) {
270 if (!dlopen(f->second.library.c_str(), RTLD_LAZY | RTLD_GLOBAL)) {
272 " for factory " +
id);
273 char *dlmsg = dlerror();
280 if (f->second.type == type) {
281 return f->second.ptr;
283 logger().
warning(
"found factory " +
id +
", but of wrong type: " +
284 f->second.type +
" instead of " + type);
295 if (f != facts.
end())
309 if (f != facts.end())
311 f->second.properties[k] = v;
321 f != facts.end(); ++f)
333 if (realname == 0)
return id.name();
340 static const char* levels[] = {
"DEBUG : ",
344 if (lvl >=
level()) {
360 using namespace Details;
364 else if (debugLevel > 0)
365 l.setLevel(Logger::Info);
366 else l.setLevel(Logger::Warning);
370 using namespace Details;
373 case Logger::Info:
return 1;
break;