FairMQ: Add static plugin mechanism

* Add skeleton for Take/ReleaseControl API
* Add skeleton for control_static builtin plugin
This commit is contained in:
Dennis Klein
2017-09-12 19:25:36 +02:00
committed by Mohammad Al-Turany
parent 17d7cd8ce4
commit 052ac8487d
11 changed files with 181 additions and 11 deletions

11
fairmq/plugins/Builtin.h Normal file
View File

@@ -0,0 +1,11 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
// List of all builtin plugin headers (the ones which call REGISTER_FAIRMQ_PLUGIN macro)
#include <fairmq/plugins/ControlStatic.h>

View File

@@ -0,0 +1,54 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include "ControlStatic.h"
namespace fair
{
namespace mq
{
namespace plugins
{
ControlStatic::ControlStatic(
const std::string name,
const Plugin::Version version,
const std::string maintainer,
const std::string homepage,
PluginServices* pluginServices)
: Plugin(name, version, maintainer, homepage, pluginServices)
{
SubscribeToDeviceStateChange(
[&](DeviceState newState){
LOG(WARN) << newState;
switch (newState)
{
case DeviceState::InitializingDevice:
LOG(WARN) << GetPropertyAsString("custom-example-option");
SetProperty("custom-example-option", std::string{"new value"});
break;
case DeviceState::Exiting:
LOG(WARN) << GetProperty<std::string>("custom-example-option");
UnsubscribeFromDeviceStateChange();
break;
}
}
);
}
auto ControlStaticPluginProgramOptions() -> Plugin::ProgOptions
{
auto plugin_options = boost::program_options::options_description{"Control Static Plugin"};
plugin_options.add_options()
("custom-example-option", boost::program_options::value<std::string>(), "Custom option.");
return plugin_options;
}
} /* namespace plugins */
} /* namespace mq */
} /* namespace fair */

View File

@@ -0,0 +1,51 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef FAIR_MQ_PLUGINS_CONTROLSTATIC
#define FAIR_MQ_PLUGINS_CONTROLSTATIC
#include <fairmq/Plugin.h>
#include <string>
namespace fair
{
namespace mq
{
namespace plugins
{
class ControlStatic : public Plugin
{
public:
ControlStatic(
const std::string name,
const Plugin::Version version,
const std::string maintainer,
const std::string homepage,
PluginServices* pluginServices
);
}; /* class ControlStatic */
auto ControlStaticPluginProgramOptions() -> Plugin::ProgOptions;
REGISTER_FAIRMQ_PLUGIN(
ControlStatic, // Class name
control_static, // Plugin name (string, lower case chars only)
(Plugin::Version{1,0,0}), // Version
"FairRootGroup <fairroot@gsi.de>", // Maintainer
"https://github.com/FairRootGroup/FairRoot", // Homepage
ControlStaticPluginProgramOptions // Free function which declares custom program options for the plugin
// signature: () -> boost::optional<boost::program_options::options_description>
)
} /* namespace plugins */
} /* namespace mq */
} /* namespace fair */
#endif /* FAIR_MQ_PLUGINS_CONTROLSTATIC */