11 #include <framework/core/Module.h>
12 #include <framework/core/ModuleManager.h>
13 #include <framework/utilities/FileSystem.h>
14 #include <framework/logging/Logger.h>
16 #include <boost/filesystem.hpp>
24 #define MAP_FILE_EXTENSION ".b2modmap"
25 #define LIB_FILE_EXTENSION ".so"
38 if (m_registeredProxyMap.count(moduleProxy->
getModuleName()) == 0) {
39 m_registeredProxyMap.insert(make_pair(moduleProxy->
getModuleName(), moduleProxy));
41 B2ERROR(
"There seems to be more than one module called '" << moduleProxy->
getModuleName() <<
42 "'. Since module names are unique, you must rename one of them!");
50 m_moduleSearchPathList.push_back(path);
53 auto fullPath = boost::filesystem::system_complete(boost::filesystem::path(path));
54 boost::filesystem::directory_iterator endIter;
57 map<string, string> moduleNameLibMap;
58 for (boost::filesystem::directory_iterator dirItr(fullPath); dirItr != endIter; ++dirItr) {
60 if (boost::filesystem::is_regular_file(dirItr->status())) {
61 if (boost::filesystem::extension(dirItr->path()) == MAP_FILE_EXTENSION) {
62 fillModuleNameLibMap(moduleNameLibMap, *dirItr);
67 m_moduleNameLibMap.insert(moduleNameLibMap.begin(), moduleNameLibMap.end());
74 return m_moduleSearchPathList;
80 return m_moduleNameLibMap;
86 auto moduleIter = m_registeredProxyMap.find(moduleName);
89 auto error = [&moduleName](
const std::string & text) ->
void {
90 auto exception = ModuleNotCreatedError() << moduleName << text;
91 B2ERROR(exception.what());
96 if (moduleIter == m_registeredProxyMap.end()) {
98 if (sharedLibPath.empty()) {
99 auto libIter = m_moduleNameLibMap.find(moduleName);
100 if (libIter != m_moduleNameLibMap.end()) {
101 sharedLibPath = libIter->second;
103 error(
"The module is not known to the framework!");
108 error(
"Could not load shared library " + sharedLibPath +
", file does not exist!");
111 error(
"Could not load shared library " + sharedLibPath +
".");
114 moduleIter = m_registeredProxyMap.find(moduleName);
115 if (moduleIter == m_registeredProxyMap.end()) {
116 error(
"The shared library " + sharedLibPath +
" does not contain the module!");
122 ModulePtr currModulePtr = moduleIter->second->createModule();
123 m_createdModulesList.push_back(currModulePtr);
124 return currModulePtr;
130 return m_createdModulesList;
138 for (
const ModulePtr& module : modulePathList)
139 if (module->hasProperties(propertyFlags)) tmpModuleList.push_back(module);
141 return tmpModuleList;
146 for (
const auto& m : list) {
147 if (!m->hasProperties(flag))
159 const boost::filesystem::directory_entry& mapPath)
162 string sharedLibPath = boost::filesystem::change_extension(mapPath, LIB_FILE_EXTENSION).string();
164 B2WARNING(
"The shared library file: " << sharedLibPath <<
" doesn't exist, but is required by " << mapPath.path().string());
169 ifstream mapFile(mapPath.path().string().c_str());
173 std::regex expression(
"^REG_MODULE\\((.+)\\)$");
174 std::match_results<std::string::const_iterator> matchResult;
177 while (getline(mapFile, currentLine)) {
180 if (!std::regex_match(currentLine, matchResult, expression)) {
181 B2ERROR(
"Problem parsing map file " << mapPath <<
": Invalid entry in line " << lineNr <<
", skipping remaining file");
185 string moduleName(matchResult[1].first, matchResult[1].second);
187 if (moduleNameLibMap.count(moduleName) == 0) {
188 moduleNameLibMap.insert(make_pair(moduleName, sharedLibPath));
190 B2ERROR(
"There seems to be more than one module called '" << moduleName <<
191 "'. Since module names are unique, you must rename one of them!");
205 m_createdModulesList.clear();