FairMQ: Integration of Plugins through PluginServices

This commit is contained in:
Dennis Klein
2017-06-26 15:08:26 +02:00
committed by Mohammad Al-Turany
parent 60d929b0bd
commit 9b61b924b2
26 changed files with 244 additions and 701 deletions

View File

@@ -9,8 +9,6 @@
#define RUNSIMPLEMQSTATEMACHINE_H
#include "FairMQLogger.h"
#include "FairMQConfigPlugin.h"
#include "FairMQControlPlugin.h"
#include "options/FairMQParser.h"
#include "options/FairMQProgOptions.h"
@@ -47,12 +45,6 @@ inline int runStateMachine(TMQDevice& device, FairMQProgOptions& cfg)
std::string config = cfg.GetValue<std::string>("config");
std::string control = cfg.GetValue<std::string>("control");
// plugin objects
void* ldConfigHandle = nullptr;
void* ldControlHandle = nullptr;
FairMQConfigPlugin* fairmqConfigPlugin = nullptr;
FairMQControlPlugin* fairmqControlPlugin = nullptr;
std::clock_t cStart = std::clock();
auto tStart = std::chrono::high_resolution_clock::now();
@@ -60,75 +52,6 @@ inline int runStateMachine(TMQDevice& device, FairMQProgOptions& cfg)
// Wait for the binding channels to bind
device.WaitForInitialValidation();
if (config != "static")
{
LOG(DEBUG) << "Opening config plugin: " << config;
ldConfigHandle = dlopen(config.c_str(), RTLD_LAZY);
if (!ldConfigHandle)
{
LOG(ERROR) << "Cannot open library: " << dlerror();
return 1;
}
// load the fairmqConfigPlugin
dlerror();
fairmqConfigPlugin = static_cast<FairMQConfigPlugin*>(dlsym(ldConfigHandle, "fairmqConfigPlugin"));
const char* dlsymError = dlerror();
if (dlsymError)
{
LOG(ERROR) << "Cannot load fairmqConfigPlugin() from: " << dlsymError;
fairmqConfigPlugin = nullptr;
dlclose(ldConfigHandle);
return 1;
}
fairmqConfigPlugin->initConfig(device);
}
if (control != "interactive" && control != "static")
{
LOG(DEBUG) << "Opening control plugin: " << control;
ldControlHandle = dlopen(control.c_str(), RTLD_LAZY);
if (!ldControlHandle)
{
LOG(ERROR) << "Cannot open library: " << dlerror();
if (ldConfigHandle)
{
dlclose(ldConfigHandle);
}
return 1;
}
// load the fairmqControlPlugin
dlerror();
fairmqControlPlugin = static_cast<FairMQControlPlugin*>(dlsym(ldControlHandle, "fairmqControlPlugin"));
const char* dlsymError = dlerror();
if (dlsymError)
{
LOG(ERROR) << "Cannot load fairmqControlPlugin(): " << dlsymError;
fairmqControlPlugin = nullptr;
dlclose(ldControlHandle);
// also close the config plugin before quiting with error.
if (ldConfigHandle)
{
dlclose(ldConfigHandle);
}
return 1;
}
fairmqControlPlugin->initControl(device);
}
if (config != "static")
{
if (fairmqConfigPlugin)
{
fairmqConfigPlugin->handleInitialConfig(device);
}
}
device.WaitForEndOfState(TMQDevice::INIT_DEVICE);
std::clock_t cEnd = std::clock();
@@ -163,30 +86,6 @@ inline int runStateMachine(TMQDevice& device, FairMQProgOptions& cfg)
}
else
{
if (fairmqControlPlugin)
{
fairmqControlPlugin->handleStateChanges(device);
}
}
if (config != "static")
{
if (fairmqConfigPlugin)
{
LOG(DEBUG) << "Closing FairMQConfigPlugin...";
fairmqConfigPlugin->stopConfig();
dlclose(ldConfigHandle);
}
}
if (control != "interactive" && control != "static")
{
if (fairmqControlPlugin)
{
LOG(DEBUG) << "Closing FairMQControlPlugin...";
fairmqControlPlugin->stopControl();
dlclose(ldControlHandle);
}
}
return 0;