Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ o2_add_library(Framework
src/O2ControlLabels.cxx
src/OutputSpec.cxx
src/PropertyTreeHelpers.cxx
src/Plugins.cxx
src/RCombinedDS.cxx
src/ReadoutAdapter.cxx
src/ResourcesMonitoringHelper.cxx
Expand Down
16 changes: 16 additions & 0 deletions Framework/Core/include/Framework/Plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#include "Framework/AlgorithmSpec.h"
#include <cstring>
#include <string>
#include <functional>
#include <uv.h>

namespace o2::framework
{
Expand Down Expand Up @@ -40,6 +43,14 @@ struct DPLPluginHandle {
DPLPluginHandle* previous;
};

// Struct to hold live plugin information which the plugin itself cannot
// know and that is owned by the framework.
struct PluginInfo {
uv_lib_t* dso = nullptr;
std::string name;
DPLPluginHandle* instance = nullptr;
};

#define DEFINE_DPL_PLUGIN(NAME, KIND) \
extern "C" { \
DPLPluginHandle* dpl_plugin_callback(DPLPluginHandle* previous) \
Expand Down Expand Up @@ -75,7 +86,12 @@ struct PluginManager {
}
return nullptr;
}
/// Load a DSO called @a dso and insert its handle in @a infos
/// On successfull completion @a onSuccess is called passing
/// the DPLPluginHandle provided by the library.
static void load(std::vector<PluginInfo>& infos, const char* dso, std::function<void(DPLPluginHandle*)>& onSuccess);
};

} // namespace o2::framework

#endif // O2_FRAMEWORK_PLUGINS_H_
55 changes: 55 additions & 0 deletions Framework/Core/src/Plugins.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "Framework/Plugins.h"
#include "Framework/Logger.h"
#include <uv.h>
#include <functional>
#include <vector>

namespace o2::framework
{

void PluginManager::load(std::vector<PluginInfo>& libs, const char* dso, std::function<void(DPLPluginHandle*)>& onSuccess)
{
auto plugin = std::find_if(libs.begin(), libs.end(), [dso](PluginInfo& info) { return info.name == dso; });
if (plugin != libs.end()) {
return onSuccess(plugin->instance);
}
uv_lib_t* supportLib = (uv_lib_t*)malloc(sizeof(uv_lib_t));
int result = 0;
#ifdef __APPLE__
char const* extension = "dylib";
#else
char const* extension = "so";
#endif
std::string filename = fmt::format("lib{}.{}", dso, extension);
result = uv_dlopen(filename.c_str(), supportLib);
if (result == -1) {
LOG(FATAL) << uv_dlerror(supportLib);
return;
}
void* callback = nullptr;
DPLPluginHandle* (*dpl_plugin_callback)(DPLPluginHandle*);

result = uv_dlsym(supportLib, "dpl_plugin_callback", (void**)&dpl_plugin_callback);
if (result == -1) {
LOG(FATAL) << uv_dlerror(supportLib);
return;
}
if (dpl_plugin_callback == nullptr) {
LOGP(FATAL, "Could not find the {} plugin.", dso);
return;
}
DPLPluginHandle* pluginInstance = dpl_plugin_callback(nullptr);
libs.push_back({supportLib, dso});
onSuccess(pluginInstance);
}
} // namespace o2::framework
2 changes: 2 additions & 0 deletions Framework/Core/src/runDataProcessing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,8 @@ int doMain(int argc, char** argv, o2::framework::WorkflowSpec const& workflow,
{
O2_SIGNPOST_INIT();
std::vector<std::string> currentArgs;
std::vector<PluginInfo> plugins;

for (size_t ai = 1; ai < argc; ++ai) {
currentArgs.push_back(argv[ai]);
}
Expand Down