9 #ifndef FAIR_MQ_PLUGIN_H 10 #define FAIR_MQ_PLUGIN_H 12 #include <fairmq/Tools.h> 13 #include <fairmq/PluginServices.h> 15 #include <boost/dll/alias.hpp> 16 #include <boost/optional.hpp> 17 #include <boost/program_options.hpp> 20 #include <unordered_map> 41 using ProgOptions = boost::optional<boost::program_options::options_description>;
46 Plugin(
const std::string name,
const Version version,
const std::string maintainer,
const std::string homepage,
PluginServices* pluginServices);
53 auto GetName()
const ->
const std::string& {
return fkName; }
54 auto GetVersion()
const ->
const Version {
return fkVersion; }
55 auto GetMaintainer()
const ->
const std::string& {
return fkMaintainer; }
56 auto GetHomepage()
const ->
const std::string& {
return fkHomepage; }
58 friend auto operator==(
const Plugin& lhs,
const Plugin& rhs) ->
bool {
return std::make_tuple(lhs.GetName(), lhs.GetVersion()) == std::make_tuple(rhs.GetName(), rhs.GetVersion()); }
59 friend auto operator!=(
const Plugin& lhs,
const Plugin& rhs) ->
bool {
return !(lhs == rhs); }
60 friend auto operator<<(std::ostream& os,
const Plugin& p) -> std::ostream&
62 return os <<
"'" << p.GetName() <<
"', " 63 <<
"version '" << p.GetVersion() <<
"', " 64 <<
"maintainer '" << p.GetMaintainer() <<
"', " 65 <<
"homepage '" << p.GetHomepage() <<
"'";
67 static auto NoProgramOptions() -> ProgOptions {
return boost::none; }
72 using DeviceStateTransition = fair::mq::PluginServices::DeviceStateTransition;
74 auto ToDeviceStateTransition(
const std::string& transition)
const -> DeviceStateTransition {
return fPluginServices->
ToDeviceStateTransition(transition); }
75 auto ToStr(
DeviceState state)
const -> std::string {
return fPluginServices->
ToStr(state); }
76 auto ToStr(DeviceStateTransition transition)
const -> std::string {
return fPluginServices->
ToStr(transition); }
81 auto ChangeDeviceState(
const DeviceStateTransition next) ->
void { fPluginServices->
ChangeDeviceState(fkName, next); }
87 auto PropertyExists(
const std::string& key) ->
int {
return fPluginServices->PropertyExists(key); }
89 auto SetProperty(
const std::string& key, T val) ->
void { fPluginServices->
SetProperty(key, val); }
91 auto GetProperty(
const std::string& key)
const -> T {
return fPluginServices->
GetProperty<T>(key); }
92 auto GetPropertyAsString(
const std::string& key)
const -> std::string {
return fPluginServices->
GetPropertyAsString(key); }
93 auto GetChannelInfo()
const -> std::unordered_map<std::string, int> {
return fPluginServices->GetChannelInfo(); }
94 auto GetPropertyKeys()
const -> std::vector<std::string> {
return fPluginServices->
GetPropertyKeys(); }
96 auto SubscribeToPropertyChange(std::function<
void(
const std::string& key, T newValue)> callback) ->
void { fPluginServices->
SubscribeToPropertyChange<T>(fkName, callback); }
99 auto SubscribeToPropertyChangeAsString(std::function<
void(
const std::string& key, std::string newValue)> callback) ->
void { fPluginServices->
SubscribeToPropertyChangeAsString(fkName, callback); }
102 auto CycleLogConsoleSeverityUp() ->
void { fPluginServices->CycleLogConsoleSeverityUp(); }
103 auto CycleLogConsoleSeverityDown() ->
void { fPluginServices->CycleLogConsoleSeverityDown(); }
104 auto CycleLogVerbosityUp() ->
void { fPluginServices->CycleLogVerbosityUp(); }
105 auto CycleLogVerbosityDown() ->
void { fPluginServices->CycleLogVerbosityDown(); }
108 const std::string fkName;
110 const std::string fkMaintainer;
111 const std::string fkHomepage;
118 #define REGISTER_FAIRMQ_PLUGIN(KLASS, NAME, VERSION, MAINTAINER, HOMEPAGE, PROGOPTIONS) \ 119 static auto Make_##NAME##_Plugin(fair::mq::PluginServices* pluginServices) -> std::unique_ptr<fair::mq::Plugin> \ 121 return fair::mq::tools::make_unique<KLASS>(std::string{#NAME}, VERSION, std::string{MAINTAINER}, std::string{HOMEPAGE}, pluginServices); \ 123 BOOST_DLL_ALIAS(Make_##NAME##_Plugin, make_##NAME##_plugin) \ 124 BOOST_DLL_ALIAS(PROGOPTIONS, get_##NAME##_plugin_progoptions) Facilitates communication between devices and plugins.
Definition: PluginServices.h:38
auto StealDeviceControl(const std::string &controller) -> void
Become device controller by force.
Definition: PluginServices.cxx:133
auto UnsubscribeFromPropertyChange(const std::string &subscriber) -> void
Unsubscribe from property updates of type T.
Definition: PluginServices.h:249
auto TakeDeviceControl(const std::string &controller) -> void
Become device controller.
Definition: PluginServices.cxx:112
auto SubscribeToPropertyChange(const std::string &subscriber, std::function< void(const std::string &key, T)> callback) const -> void
Subscribe to property updates of type T.
Definition: PluginServices.h:241
auto UnsubscribeFromDeviceStateChange(const std::string &subscriber) -> void
Unsubscribe from device state changes.
Definition: PluginServices.h:171
static auto ToStr(DeviceState state) -> std::string
Convert DeviceState to string.
Definition: PluginServices.h:107
auto GetCurrentDeviceState() const -> DeviceState
Definition: PluginServices.h:118
auto GetPropertyAsString(const std::string &key) const -> std::string
Read config property as string.
Definition: PluginServices.h:222
Base class for FairMQ plugins.
Definition: Plugin.h:38
auto ReleaseDeviceControl(const std::string &controller) -> void
Release device controller role.
Definition: PluginServices.cxx:140
auto SubscribeToDeviceStateChange(const std::string &subscriber, std::function< void(DeviceState)> callback) -> void
Subscribe with a callback to device state changes.
Definition: PluginServices.h:162
static auto ToDeviceState(const std::string &state) -> DeviceState
Convert string to DeviceState.
Definition: PluginServices.h:96
auto GetProperty(const std::string &key) const -> T
Read config property.
Definition: PluginServices.h:210
auto SubscribeToPropertyChangeAsString(const std::string &subscriber, std::function< void(const std::string &key, std::string)> callback) const -> void
Subscribe to property updates.
Definition: PluginServices.h:256
DeviceState
See https://github.com/FairRootGroup/FairRoot/blob/dev/fairmq/docs/Device.md#13-state-machine.
Definition: PluginServices.h:60
auto SetProperty(const std::string &key, T val) -> void
Set config property.
Definition: PluginServices.h:186
auto UnsubscribeFromPropertyChangeAsString(const std::string &subscriber) -> void
Unsubscribe from property updates that convert to string.
Definition: PluginServices.h:263
static auto ToDeviceStateTransition(const std::string &transition) -> DeviceStateTransition
Convert string to DeviceStateTransition.
Definition: PluginServices.h:102
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23
auto GetPropertyKeys() const -> std::vector< std::string >
Discover the list of property keys.
Definition: PluginServices.h:233
auto ChangeDeviceState(const std::string &controller, const DeviceStateTransition next) -> void
Request a device state transition.
Definition: PluginServices.cxx:93