FairMQ
1.4.33
C++ Message Queuing Library and Framework
|
9 #ifndef FAIR_MQ_PLUGIN_H
10 #define FAIR_MQ_PLUGIN_H
12 #include <fairmq/tools/Version.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>
39 using ProgOptions = boost::optional<boost::program_options::options_description>;
41 using Version = tools::Version;
46 std::string maintainer,
55 auto GetName() const -> const std::
string& {
return fkName; }
56 auto GetVersion() const -> const Version {
return fkVersion; }
57 auto GetMaintainer() const -> const std::
string& {
return fkMaintainer; }
58 auto GetHomepage() const -> const std::
string& {
return fkHomepage; }
60 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()); }
61 friend auto operator!=(
const Plugin& lhs,
const Plugin& rhs) ->
bool {
return !(lhs == rhs); }
62 friend auto operator<<(std::ostream& os,
const Plugin& p) -> std::ostream&
64 return os <<
"'" << p.GetName() <<
"', "
65 <<
"version '" << p.GetVersion() <<
"', "
66 <<
"maintainer '" << p.GetMaintainer() <<
"', "
67 <<
"homepage '" << p.GetHomepage() <<
"'";
69 static auto NoProgramOptions() -> ProgOptions {
return boost::none; }
73 using DeviceState = fair::mq::PluginServices::DeviceState;
74 using DeviceStateTransition = fair::mq::PluginServices::DeviceStateTransition;
75 auto ToDeviceState(
const std::string& state)
const -> DeviceState {
return fPluginServices->
ToDeviceState(state); }
76 auto ToDeviceStateTransition(
const std::string& transition)
const -> DeviceStateTransition {
return fPluginServices->
ToDeviceStateTransition(transition); }
77 auto ToStr(DeviceState state)
const -> std::string {
return fPluginServices->
ToStr(state); }
78 auto ToStr(DeviceStateTransition transition)
const -> std::string {
return fPluginServices->
ToStr(transition); }
79 auto GetCurrentDeviceState() const -> DeviceState {
return fPluginServices->
GetCurrentDeviceState(); }
83 auto ChangeDeviceState(
const DeviceStateTransition next) ->
bool {
return fPluginServices->
ChangeDeviceState(fkName, next); }
84 auto SubscribeToDeviceStateChange(std::function<
void(DeviceState)> callback) ->
void { fPluginServices->
SubscribeToDeviceStateChange(fkName, callback); }
89 auto PropertyExists(
const std::string& key) ->
int {
return fPluginServices->
PropertyExists(key); }
92 T GetProperty(
const std::string& key)
const {
return fPluginServices->
GetProperty<T>(key); }
94 T GetProperty(
const std::string& key,
const T& ifNotFound)
const {
return fPluginServices->
GetProperty(key, ifNotFound); }
95 std::string GetPropertyAsString(
const std::string& key)
const {
return fPluginServices->
GetPropertyAsString(key); }
96 std::string GetPropertyAsString(
const std::string& key,
const std::string& ifNotFound)
const {
return fPluginServices->
GetPropertyAsString(key, ifNotFound); }
97 fair::mq::Properties GetProperties(
const std::string& q)
const {
return fPluginServices->
GetProperties(q); }
98 fair::mq::Properties GetPropertiesStartingWith(
const std::string& q)
const {
return fPluginServices->
GetPropertiesStartingWith(q); };
99 std::map<std::string, std::string> GetPropertiesAsString(
const std::string& q)
const {
return fPluginServices->
GetPropertiesAsString(q); }
100 std::map<std::string, std::string> GetPropertiesAsStringStartingWith(
const std::string& q)
const {
return fPluginServices->
GetPropertiesAsStringStartingWith(q); };
102 auto GetChannelInfo() const -> std::unordered_map<std::
string,
int> {
return fPluginServices->
GetChannelInfo(); }
103 auto GetPropertyKeys() const -> std::vector<std::
string> {
return fPluginServices->
GetPropertyKeys(); }
106 auto SetProperty(
const std::string& key, T val) ->
void { fPluginServices->
SetProperty(key, val); }
107 void SetProperties(
const fair::mq::Properties& props) { fPluginServices->
SetProperties(props); }
109 bool UpdateProperty(
const std::string& key, T val) {
return fPluginServices->
UpdateProperty(key, val); }
110 bool UpdateProperties(
const fair::mq::Properties& input) {
return fPluginServices->
UpdateProperties(input); }
112 void DeleteProperty(
const std::string& key) { fPluginServices->
DeleteProperty(key); }
115 auto SubscribeToPropertyChange(std::function<
void(
const std::string& key, T newValue)> callback) ->
void { fPluginServices->
SubscribeToPropertyChange<T>(fkName, callback); }
118 auto SubscribeToPropertyChangeAsString(std::function<
void(
const std::string& key, std::string newValue)> callback) ->
void { fPluginServices->
SubscribeToPropertyChangeAsString(fkName, callback); }
127 const std::string fkName;
128 const Version fkVersion;
129 const std::string fkMaintainer;
130 const std::string fkHomepage;
131 PluginServices* fPluginServices;
136 #define REGISTER_FAIRMQ_PLUGIN(KLASS, NAME, VERSION, MAINTAINER, HOMEPAGE, PROGOPTIONS) \
137 static auto Make_##NAME##_Plugin(fair::mq::PluginServices* pluginServices) -> std::unique_ptr<fair::mq::Plugin> \
139 return std::make_unique<KLASS>(std::string{#NAME}, VERSION, std::string{MAINTAINER}, std::string{HOMEPAGE}, pluginServices); \
141 BOOST_DLL_ALIAS(Make_##NAME##_Plugin, make_##NAME##_plugin) \
142 BOOST_DLL_ALIAS(PROGOPTIONS, get_##NAME##_plugin_progoptions)
auto SetProperty(const std::string &key, T val) -> void
Set config property.
Definition: PluginServices.h:163
auto CycleLogConsoleSeverityDown() -> void
Decreases console logging severity, or sets it to highest if it is already lowest.
Definition: PluginServices.h:274
auto GetCurrentDeviceState() const -> DeviceState
Definition: PluginServices.h:94
auto UnsubscribeFromPropertyChangeAsString(const std::string &subscriber) -> void
Unsubscribe from property updates that convert to string.
Definition: PluginServices.h:269
Facilitates communication between devices and plugins.
Definition: PluginServices.h:46
auto ChangeDeviceState(const std::string &controller, const DeviceStateTransition next) -> bool
Request a device state transition.
Definition: PluginServices.cxx:15
auto CycleLogVerbosityDown() -> void
Decreases logging verbosity, or sets it to highest if it is already lowest.
Definition: PluginServices.h:278
auto CycleLogConsoleSeverityUp() -> void
Increases console logging severity, or sets it to lowest if it is already highest.
Definition: PluginServices.h:272
fair::mq::Properties GetPropertiesStartingWith(const std::string &q) const
Read several config properties whose keys start with the provided string.
Definition: PluginServices.h:221
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:239
auto SubscribeToDeviceStateChange(const std::string &subscriber, std::function< void(DeviceState)> callback) -> void
Subscribe with a callback to device state changes.
Definition: PluginServices.h:138
static auto ToDeviceState(const std::string &state) -> DeviceState
Convert string to DeviceState.
Definition: PluginServices.h:75
bool UpdateProperty(const std::string &key, T val)
Updates an existing config property (or fails if it doesn't exist)
Definition: PluginServices.h:171
static auto ToDeviceStateTransition(const std::string &transition) -> DeviceStateTransition
Convert string to DeviceStateTransition.
Definition: PluginServices.h:81
bool UpdateProperties(const fair::mq::Properties &input)
Updates multiple existing config properties (or fails of any of then do not exist,...
Definition: PluginServices.h:174
void DeleteProperty(const std::string &key)
Deletes a property with the given key from the config store.
Definition: PluginServices.h:178
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:231
auto TakeDeviceControl(const std::string &controller) -> void
Become device controller.
Definition: PluginServices.cxx:31
auto UnsubscribeFromDeviceStateChange(const std::string &subscriber) -> void
Unsubscribe from device state changes.
Definition: PluginServices.h:147
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:247
auto CycleLogVerbosityUp() -> void
Increases logging verbosity, or sets it to lowest if it is already highest.
Definition: PluginServices.h:276
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:225
auto PropertyExists(const std::string &key) const -> bool
Checks a property with the given key exist in the configuration.
Definition: PluginServices.h:154
auto UnsubscribeFromPropertyChange(const std::string &subscriber) -> void
Unsubscribe from property updates of type T.
Definition: PluginServices.h:255
auto GetChannelInfo() const -> std::unordered_map< std::string, int >
Retrieve current channel information.
Definition: PluginServices.h:235
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:200
auto StealDeviceControl(const std::string &controller) -> void
Become device controller by force.
Definition: PluginServices.cxx:47
auto ReleaseDeviceControl(const std::string &controller) -> void
Release device controller role.
Definition: PluginServices.cxx:54
fair::mq::Properties GetProperties(const std::string &q) const
Read several config properties whose keys match the provided regular expression.
Definition: PluginServices.h:215
void SetProperties(const fair::mq::Properties &props)
Set multiple config properties.
Definition: PluginServices.h:166
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:262
auto GetProperty(const std::string &key) const -> T
Read config property, throw if no property with this key exists.
Definition: PluginServices.h:184
Base class for FairMQ plugins.
Definition: Plugin.h:43
static auto ToStr(DeviceState state) -> std::string
Convert DeviceState to string.
Definition: PluginServices.h:86
privacy