21 std::vector<LoadablePlugin> loadablePlugins;
22 enum struct ParserState :
int {
28 const char* cur =
str;
29 const char* next = cur;
30 ParserState
state = ParserState::IN_LIBRARY;
31 std::string_view library;
32 std::string_view
name;
33 while (cur && *cur !=
'\0') {
34 ParserState previousState =
state;
35 state = ParserState::IN_ERROR;
36 switch (previousState) {
37 case ParserState::IN_LIBRARY:
38 next = strchr(cur,
':');
39 if (next !=
nullptr) {
40 state = ParserState::IN_NAME;
41 library = std::string_view(cur, next - cur);
44 case ParserState::IN_NAME:
45 next = strchr(cur,
',');
46 if (next ==
nullptr) {
47 state = ParserState::IN_END;
48 name = std::string_view(cur, strlen(cur));
50 name = std::string_view(cur, next - cur);
51 state = ParserState::IN_LIBRARY;
53 loadablePlugins.push_back({std::string(
name), std::string(library)});
55 case ParserState::IN_END:
57 case ParserState::IN_ERROR:
58 LOG(error) <<
"Error while parsing DPL_LOAD_SERVICES";
66 return loadablePlugins;
71 auto plugin = std::find_if(libs.begin(), libs.end(), [dso](
PluginInfo& info) { return info.name == dso; });
72 if (plugin != libs.end()) {
73 return onSuccess(plugin->instance);
75 auto* supportLib = (uv_lib_t*)malloc(
sizeof(uv_lib_t));
78 char const* extension =
"dylib";
80 char const* extension =
"so";
82 std::string
filename = fmt::format(
"lib{}.{}", dso, extension);
85 LOG(fatal) << uv_dlerror(supportLib);
90 result = uv_dlsym(supportLib,
"dpl_plugin_callback", (
void**)&dpl_plugin_callback);
92 LOG(fatal) << uv_dlerror(supportLib);
95 if (dpl_plugin_callback ==
nullptr) {
96 LOGP(fatal,
"Could not find the {} plugin.", dso);
100 libs.push_back({supportLib, dso});
101 onSuccess(pluginInstance);
106 std::shared_ptr<AlgorithmSpec> algorithm{
nullptr};
108 if (algorithm.get()) {
109 return algorithm->
onInit(ic);
113 std::string libName =
"lib" + library;
119 int result = uv_dlopen(libName.c_str(), &supportLib);
121 LOG(fatal) << uv_dlerror(&supportLib);
125 result = uv_dlsym(&supportLib,
"dpl_plugin_callback", (
void**)&dpl_plugin_callback);
127 LOG(fatal) << uv_dlerror(&supportLib);
129 if (dpl_plugin_callback ==
nullptr) {
130 LOGP(fatal,
"Could not find the {} plugin in {}.", plugin, libName);
133 auto* creator = PluginManager::getByName<AlgorithmPlugin>(pluginInstance, plugin.c_str());
135 LOGP(fatal,
"Could not find the {} plugin in {}.", plugin, libName);
137 algorithm = std::make_shared<AlgorithmSpec>(creator->create(context));
138 return algorithm->onInit(ic);