9 #ifndef FAIR_MQ_PLUGIN_H 10 #define FAIR_MQ_PLUGIN_H 12 #include <fairmq/tools/CppSTL.h> 13 #include <fairmq/tools/Version.h> 14 #include <fairmq/PluginServices.h> 16 #include <boost/dll/alias.hpp> 17 #include <boost/optional.hpp> 18 #include <boost/program_options.hpp> 21 #include <unordered_map> 42 using ProgOptions = boost::optional<boost::program_options::options_description>;
49 std::string maintainer,
58 auto GetName()
const ->
const std::string& {
return fkName; }
59 auto GetVersion()
const ->
const Version {
return fkVersion; }
60 auto GetMaintainer()
const ->
const std::string& {
return fkMaintainer; }
61 auto GetHomepage()
const ->
const std::string& {
return fkHomepage; }
63 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()); }
64 friend auto operator!=(
const Plugin& lhs,
const Plugin& rhs) ->
bool {
return !(lhs == rhs); }
65 friend auto operator<<(std::ostream& os,
const Plugin& p) -> std::ostream&
67 return os <<
"'" << p.GetName() <<
"', " 68 <<
"version '" << p.GetVersion() <<
"', " 69 <<
"maintainer '" << p.GetMaintainer() <<
"', " 70 <<
"homepage '" << p.GetHomepage() <<
"'";
72 static auto NoProgramOptions() -> ProgOptions {
return boost::none; }
76 using DeviceState = fair::mq::PluginServices::DeviceState;
77 using DeviceStateTransition = fair::mq::PluginServices::DeviceStateTransition;
78 auto ToDeviceState(
const std::string& state)
const -> DeviceState {
return fPluginServices->
ToDeviceState(state); }
79 auto ToDeviceStateTransition(
const std::string& transition)
const -> DeviceStateTransition {
return fPluginServices->
ToDeviceStateTransition(transition); }
80 auto ToStr(DeviceState state)
const -> std::string {
return fPluginServices->
ToStr(state); }
81 auto ToStr(DeviceStateTransition transition)
const -> std::string {
return fPluginServices->
ToStr(transition); }
82 auto GetCurrentDeviceState()
const -> DeviceState {
return fPluginServices->
GetCurrentDeviceState(); }
86 auto ChangeDeviceState(
const DeviceStateTransition next) ->
bool {
return fPluginServices->
ChangeDeviceState(fkName, next); }
87 auto SubscribeToDeviceStateChange(std::function<
void(DeviceState)> callback) ->
void { fPluginServices->
SubscribeToDeviceStateChange(fkName, callback); }
92 auto PropertyExists(
const std::string& key) ->
int {
return fPluginServices->
PropertyExists(key); }
95 T GetProperty(
const std::string& key)
const {
return fPluginServices->
GetProperty<T>(key); }
97 T GetProperty(
const std::string& key,
const T& ifNotFound)
const {
return fPluginServices->
GetProperty(key, ifNotFound); }
98 std::string GetPropertyAsString(
const std::string& key)
const {
return fPluginServices->
GetPropertyAsString(key); }
99 std::string GetPropertyAsString(
const std::string& key,
const std::string& ifNotFound)
const {
return fPluginServices->
GetPropertyAsString(key, ifNotFound); }
100 fair::mq::Properties GetProperties(
const std::string& q)
const {
return fPluginServices->
GetProperties(q); }
101 fair::mq::Properties GetPropertiesStartingWith(
const std::string& q)
const {
return fPluginServices->
GetPropertiesStartingWith(q); };
102 std::map<std::string, std::string> GetPropertiesAsString(
const std::string& q)
const {
return fPluginServices->
GetPropertiesAsString(q); }
103 std::map<std::string, std::string> GetPropertiesAsStringStartingWith(
const std::string& q)
const {
return fPluginServices->
GetPropertiesAsStringStartingWith(q); };
105 auto GetChannelInfo()
const -> std::unordered_map<std::string, int> {
return fPluginServices->
GetChannelInfo(); }
106 auto GetPropertyKeys()
const -> std::vector<std::string> {
return fPluginServices->
GetPropertyKeys(); }
109 auto SetProperty(
const std::string& key, T val) ->
void { fPluginServices->
SetProperty(key, val); }
110 void SetProperties(
const fair::mq::Properties& props) { fPluginServices->
SetProperties(props); }
112 bool UpdateProperty(
const std::string& key, T val) {
return fPluginServices->
UpdateProperty(key, val); }
113 bool UpdateProperties(
const fair::mq::Properties& input) {
return fPluginServices->
UpdateProperties(input); }
115 void DeleteProperty(
const std::string& key) { fPluginServices->
DeleteProperty(key); }
118 auto SubscribeToPropertyChange(std::function<
void(
const std::string& key, T newValue)> callback) ->
void { fPluginServices->
SubscribeToPropertyChange<T>(fkName, callback); }
121 auto SubscribeToPropertyChangeAsString(std::function<
void(
const std::string& key, std::string newValue)> callback) ->
void { fPluginServices->
SubscribeToPropertyChangeAsString(fkName, callback); }
130 const std::string fkName;
132 const std::string fkMaintainer;
133 const std::string fkHomepage;
140 #define REGISTER_FAIRMQ_PLUGIN(KLASS, NAME, VERSION, MAINTAINER, HOMEPAGE, PROGOPTIONS) \ 141 static auto Make_##NAME##_Plugin(fair::mq::PluginServices* pluginServices) -> std::unique_ptr<fair::mq::Plugin> \ 143 return fair::mq::tools::make_unique<KLASS>(std::string{#NAME}, VERSION, std::string{MAINTAINER}, std::string{HOMEPAGE}, pluginServices); \ 145 BOOST_DLL_ALIAS(Make_##NAME##_Plugin, make_##NAME##_plugin) \ 146 BOOST_DLL_ALIAS(PROGOPTIONS, get_##NAME##_plugin_progoptions) Facilitates communication between devices and plugins.
Definition: PluginServices.h:40
auto StealDeviceControl(const std::string &controller) -> void
Become device controller by force.
Definition: PluginServices.cxx:47
auto UnsubscribeFromPropertyChange(const std::string &subscriber) -> void
Unsubscribe from property updates of type T.
Definition: PluginServices.h:250
bool UpdateProperty(const std::string &key, T val)
Updates an existing config property (or fails if it doesn't exist)
Definition: PluginServices.h:166
void DeleteProperty(const std::string &key)
Deletes a property with the given key from the config store.
Definition: PluginServices.h:173
auto TakeDeviceControl(const std::string &controller) -> void
Become device controller.
Definition: PluginServices.cxx:31
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:242
fair::mq::Properties GetProperties(const std::string &q) const
Read several config properties whose keys match the provided regular expression.
Definition: PluginServices.h:210
auto CycleLogVerbosityUp() -> void
Increases logging verbosity, or sets it to lowest if it is already highest.
Definition: PluginServices.h:271
auto UnsubscribeFromDeviceStateChange(const std::string &subscriber) -> void
Unsubscribe from device state changes.
Definition: PluginServices.h:142
static auto ToStr(DeviceState state) -> std::string
Convert DeviceState to string.
Definition: PluginServices.h:81
auto GetCurrentDeviceState() const -> DeviceState
Definition: PluginServices.h:89
auto PropertyExists(const std::string &key) const -> bool
Checks a property with the given key exist in the configuration.
Definition: PluginServices.h:149
auto CycleLogVerbosityDown() -> void
Decreases logging verbosity, or sets it to highest if it is already lowest.
Definition: PluginServices.h:273
std::map< std::string, std::string > GetPropertiesAsString(const std::string &q) const
Read several config properties as string whose keys match the provided regular expression.
Definition: PluginServices.h:220
auto GetPropertyAsString(const std::string &key) const -> std::string
Read config property as string, throw if no property with this key exists.
Definition: PluginServices.h:195
auto GetChannelInfo() const -> std::unordered_map< std::string, int >
Retrieve current channel information.
Definition: PluginServices.h:230
Base class for FairMQ plugins.
Definition: Plugin.h:39
auto ReleaseDeviceControl(const std::string &controller) -> void
Release device controller role.
Definition: PluginServices.cxx:54
auto SubscribeToDeviceStateChange(const std::string &subscriber, std::function< void(DeviceState)> callback) -> void
Subscribe with a callback to device state changes.
Definition: PluginServices.h:133
void SetProperties(const fair::mq::Properties &props)
Set multiple config properties.
Definition: PluginServices.h:161
static auto ToDeviceState(const std::string &state) -> DeviceState
Convert string to DeviceState.
Definition: PluginServices.h:70
auto GetProperty(const std::string &key) const -> T
Read config property, throw if no property with this key exists.
Definition: PluginServices.h:179
auto CycleLogConsoleSeverityDown() -> void
Decreases console logging severity, or sets it to highest if it is already lowest.
Definition: PluginServices.h:269
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:257
bool UpdateProperties(const fair::mq::Properties &input)
Updates multiple existing config properties (or fails of any of then do not exist, leaving property store unchanged)
Definition: PluginServices.h:169
std::map< std::string, std::string > GetPropertiesAsStringStartingWith(const std::string &q) const
Read several config properties as string whose keys start with the provided string.
Definition: PluginServices.h:226
auto SetProperty(const std::string &key, T val) -> void
Set config property.
Definition: PluginServices.h:158
auto UnsubscribeFromPropertyChangeAsString(const std::string &subscriber) -> void
Unsubscribe from property updates that convert to string.
Definition: PluginServices.h:264
static auto ToDeviceStateTransition(const std::string &transition) -> DeviceStateTransition
Convert string to DeviceStateTransition.
Definition: PluginServices.h:76
auto CycleLogConsoleSeverityUp() -> void
Increases console logging severity, or sets it to lowest if it is already highest.
Definition: PluginServices.h:267
auto ChangeDeviceState(const std::string &controller, const DeviceStateTransition next) -> bool
Request a device state transition.
Definition: PluginServices.cxx:15
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23
fair::mq::Properties GetPropertiesStartingWith(const std::string &q) const
Read several config properties whose keys start with the provided string.
Definition: PluginServices.h:216
auto GetPropertyKeys() const -> std::vector< std::string >
Discover the list of property keys.
Definition: PluginServices.h:234