| 41 | const char *const HandlerManager::FACTORY_FUNCTION_NAME = "createSpecialIncludeHandler"; |
| 42 | |
| 43 | void |
| 44 | HandlerManager::loadObjects(const Utils::KeyValueMap &handlers) |
| 45 | { |
| 46 | ModuleHandleMap::iterator path_map_iter; |
| 47 | |
| 48 | for (Utils::KeyValueMap::const_iterator id_map_iter = handlers.begin(); id_map_iter != handlers.end(); ++id_map_iter) { |
| 49 | const string &id = id_map_iter->first; |
| 50 | const string &path = id_map_iter->second; |
| 51 | |
| 52 | path_map_iter = _path_to_module_map.find(path); |
| 53 | |
| 54 | if (path_map_iter != _path_to_module_map.end()) { |
| 55 | // we have already loaded this object; just point id to original handle |
| 56 | _id_to_function_map.insert(FunctionHandleMap::value_type(id, (path_map_iter->second).function)); |
| 57 | } else { |
| 58 | // no, we have to load this object |
| 59 | void *obj_handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL); |
| 60 | if (!obj_handle) { |
| 61 | TSError("[%s::%s] Could not load module [%s]. Error [%s]", CLASS_NAME, __FUNCTION__, path.c_str(), dlerror()); |
| 62 | } else { |
| 63 | SpecialIncludeHandlerCreator func_handle = (SpecialIncludeHandlerCreator)(dlsym(obj_handle, FACTORY_FUNCTION_NAME)); |
| 64 | if (!func_handle) { |
| 65 | TSError("[%s::%s] Could not find factory function [%s] in module [%s]. Error [%s]", CLASS_NAME, __FUNCTION__, |
| 66 | FACTORY_FUNCTION_NAME, path.c_str(), dlerror()); |
| 67 | dlclose(obj_handle); |
| 68 | } else { |
| 69 | _id_to_function_map.insert(FunctionHandleMap::value_type(id, func_handle)); |
| 70 | _path_to_module_map.insert(ModuleHandleMap::value_type(path, ModuleHandles(obj_handle, func_handle))); |
| 71 | Dbg(dbg_ctl, "[%s] Loaded handler module [%s]", __FUNCTION__, path.c_str()); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | SpecialIncludeHandler * |
| 79 | HandlerManager::getHandler(Variables &esi_vars, Expression &esi_expr, HttpDataFetcher &fetcher, const std::string &id) const |
no test coverage detected