forked from cms-patatrack/heterogeneous-clue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginManager.cc
36 lines (29 loc) · 970 Bytes
/
PluginManager.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <fstream>
#include "PluginManager.h"
#ifndef LIB_DIR
#error "LIB_DIR undefined"
#endif
#define STR_EXPAND(x) #x
#define STR(x) STR_EXPAND(x)
namespace edmplugin {
PluginManager::PluginManager() {
std::ifstream pluginMap(STR(LIB_DIR) "/plugins.txt");
std::string plugin, library;
while (pluginMap >> plugin >> library) {
//std::cout << "plugin " << plugin << " in " << library << std::endl;
pluginToLibrary_[plugin] = library;
}
}
SharedLibrary const& PluginManager::load(std::string const& pluginName) {
std::lock_guard<std::recursive_mutex> guard(mutex_);
auto libName = pluginToLibrary_.at(pluginName);
auto found = loadedPlugins_.find(libName);
if (found == loadedPlugins_.end()) {
auto ptr = std::make_shared<SharedLibrary>(STR(LIB_DIR) "/" + libName);
loadedPlugins_[libName] = ptr;
return *ptr;
}
return *(found->second);
}
} // namespace edmplugin