17DalFactory::get_known_class_name_ref(
const std::string& name)
19 std::lock_guard<std::mutex> scoped_lock(m_known_class_mutex);
20 return *m_known_classes.emplace(name).first;
24DalFactory::try_load_class_library(Configuration& db,
const std::string& class_name) {
26 auto&
c = db.get_class_info(class_name);
27 TLOG_DEBUG(1) <<
"Resolvung dal library for class " << class_name;
29 std::string
file =
c.p_schema_path;
30 std::string search {
"/schema/"};
31 auto start =
file.rfind(search);
32 if ( start == std::string::npos) {
33 throw (DalPackageNameNotFound(
ERS_HERE, class_name, file));
35 start += search.size();
36 auto end =
file.find(
"/", start);
37 if ( end == std::string::npos) {
38 throw (DalPackageNameNotFound(
ERS_HERE, class_name, file));
41 std::string
package = file.substr(start,end-start);
42 std::string library =
"lib"+package+
"_dal.so";
43 TLOG_DEBUG(1) <<
"Loading dal library " << library <<
" for class " << class_name;
45 auto handle = dlopen(library.c_str(), RTLD_LAZY|RTLD_GLOBAL);
46 if (handle ==
nullptr) {
50 return handle !=
nullptr;
60 TLOG_DEBUG(50) <<
"Building object " << o.UID() <<
" of class " << o.class_name();
62 auto it = m_creators.find(o.class_name());
64 if (it == m_creators.end()) {
65 TLOG_DEBUG(50) <<
"Constructor for class " << o.class_name() <<
" not found";
67 if (!this->try_load_class_library(reg.configuration(), o.class_name())) {
70 it = m_creators.find(o.class_name());
71 if (it == m_creators.end()) {
75 TLOG() <<
">>> Constructor for class " << o.class_name() <<
" found";
78 auto dal_obj = it->second(reg,o);
79 TLOG_DEBUG(50) <<
"Object " << o.UID() <<
" of class " << o.class_name() <<
" created " << (
void*)dal_obj;
89DalFactory::make(conffwk::DalRegistry& reg,
conffwk::ConfigObject& o,
const std::string& fallback_unregistred) {
92 TLOG_DEBUG(50) <<
"Building object " << o.UID() <<
" of class " << o.class_name();
94 auto it = m_creators.find(o.class_name());
96 if (it == m_creators.end()) {
97 if (!this->try_load_class_library(reg.configuration(), o.class_name())) {
100 it = m_creators.find(o.class_name());
101 if (it == m_creators.end()) {
107 auto dal_obj = it->second(reg,o);
108 TLOG_DEBUG(50) <<
"Object " << o.UID() <<
" of class " << o.class_name() <<
" created " << (
void*)dal_obj;
115DalFactory::instance()
123DalFactory::get(Configuration& db, ConfigObject& obj,
const std::string& uid,
bool upcast_unregistered)
const
125 return (*instance().functions(db,
obj.class_name(), upcast_unregistered).m_creator_fn)(db,
obj, uid);
129DalFactory::get(Configuration& db, ConfigObject& obj,
const std::string& uid,
const std::string& class_name)
const
131 return (*instance().functions(db, class_name,
false).m_creator_fn)(db,
obj, uid);
135const DalFactoryFunctions&
136DalFactory::functions(Configuration& db,
const std::string& name,
bool upcast_unregistered)
138 auto it = m_classes.find(name);
140 if (it == m_classes.end())
142 if (!this->try_load_class_library(db, name)) {
145 it = m_classes.find(name);
146 if (it == m_classes.end()) {
156DalFactory::class4algo(Configuration& db,
const std::string& name,
const std::string&
algorithm)
const
158 for (
const auto& x : m_classes)
159 if (x.second.m_algorithms.find(
algorithm) != x.second.m_algorithms.end() && db.try_cast(x.first, name))
162 static const std::string empty;
167const DalFactoryFunctions&
168DalFactory::functions(
const std::string& name)
const
170 auto it = m_classes.find(name);
172 ERS_ASSERT_MSG( (it != m_classes.end()),
"writer lock was not initialized" );
#define ERS_ASSERT_MSG(expression, message)
Try to access non-existent object or class.
#define TLOG_DEBUG(lvl,...)