FairMQ
1.4.33
C++ Message Queuing Library and Framework
|
9 #ifndef FAIR_MQ_PLUGINSERVICES_H
10 #define FAIR_MQ_PLUGINSERVICES_H
12 #include <fairmq/States.h>
13 #include <FairMQDevice.h>
14 #include <fairmq/ProgOptions.h>
15 #include <fairmq/Properties.h>
17 #include <boost/optional.hpp>
18 #include <boost/optional/optional_io.hpp>
20 #include <condition_variable>
26 #include <unordered_map>
42 PluginServices() =
delete;
43 PluginServices(ProgOptions& config,
FairMQDevice& device)
47 , fDeviceControllerMutex()
48 , fReleaseDeviceControlCondition()
54 LOG(debug) <<
"Shutting down Plugin Services";
57 PluginServices(
const PluginServices&) =
delete;
58 PluginServices operator=(
const PluginServices&) =
delete;
60 using DeviceState = fair::mq::State;
61 using DeviceStateTransition = fair::mq::Transition;
69 static auto ToDeviceState(
const std::string& state) -> DeviceState {
return GetState(state); }
75 static auto ToDeviceStateTransition(
const std::string& transition) -> DeviceStateTransition {
return GetTransition(transition); }
80 static auto ToStr(DeviceState state) -> std::string {
return GetStateName(state); }
85 static auto ToStr(DeviceStateTransition transition) -> std::string {
return GetTransitionName(transition); }
96 struct DeviceControlError : std::runtime_error {
using std::runtime_error::runtime_error; };
124 auto
ChangeDeviceState(const std::
string& controller, const DeviceStateTransition next) ->
bool;
148 auto PropertyExists(
const std::string& key)
const ->
bool {
return fConfig.
Count(key) > 0; }
185 T
GetProperty(
const std::string& key,
const T& ifNotFound)
const {
return fConfig.
GetProperty(key, ifNotFound); }
241 auto SubscribeToPropertyChange(
const std::string& subscriber, std::function<
void(
const std::string& key, T)> callback)
const ->
void
243 fConfig.
Subscribe<T>(subscriber, callback);
277 boost::optional<std::string> fDeviceController;
278 mutable std::mutex fDeviceControllerMutex;
279 std::condition_variable fReleaseDeviceControlCondition;
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
Definition: ProgOptions.h:41
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
fair::mq::State GetCurrentState() const
Returns the current state.
Definition: FairMQDevice.h:473
std::vector< std::string > GetPropertyKeys() const
Discover the list of property keys.
Definition: ProgOptions.cxx:189
auto ChangeDeviceState(const std::string &controller, const DeviceStateTransition next) -> bool
Request a device state transition.
Definition: PluginServices.cxx:15
fair::mq::Properties GetPropertiesStartingWith(const std::string &q) const
Read several config properties whose keys start with the provided string.
Definition: ProgOptions.cxx:256
bool UpdateProperty(const std::string &key, T val)
Updates an existing config property (or fails if it doesn't exist)
Definition: ProgOptions.h:152
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
void Unsubscribe(const std::string &subscriber) const
Unsubscribe from property updates of type T.
Definition: ProgOptions.h:202
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 GetDeviceController() const -> boost::optional< std::string >
Get current device controller.
Definition: PluginServices.cxx:70
auto SubscribeToDeviceStateChange(const std::string &subscriber, std::function< void(DeviceState)> callback) -> void
Subscribe with a callback to device state changes.
Definition: PluginServices.h:138
T GetProperty(const std::string &key) const
Read config property, throw if no property with this key exists.
Definition: ProgOptions.h:69
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
std::string GetPropertyAsString(const std::string &key) const
Read config property as string, throw if no property with this key exists.
auto TakeDeviceControl(const std::string &controller) -> void
Become device controller.
Definition: PluginServices.cxx:31
void SetProperty(const std::string &key, T val)
Set config property.
Definition: ProgOptions.h:136
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: ProgOptions.cxx:271
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 WaitForReleaseDeviceControl() -> void
Block until control is released.
Definition: PluginServices.cxx:77
void SubscribeAsString(const std::string &subscriber, std::function< void(typename fair::mq::PropertyChange::KeyType, std::string)> func) const
Subscribe to property updates, with values converted to string.
Definition: ProgOptions.h:213
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
void SubscribeToStateChange(const std::string &key, std::function< void(const fair::mq::State)> callback)
Subscribe with a callback to state changes.
Definition: FairMQDevice.h:454
bool UpdateProperties(const fair::mq::Properties &input)
Updates multiple existing config properties (or fails of any of then do not exist,...
Definition: ProgOptions.cxx:323
auto UnsubscribeFromPropertyChange(const std::string &subscriber) -> void
Unsubscribe from property updates of type T.
Definition: PluginServices.h:255
void Subscribe(const std::string &subscriber, std::function< void(typename fair::mq::PropertyChange::KeyType, T)> func) const
Subscribe to property updates of type T.
Definition: ProgOptions.h:191
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
void UnsubscribeAsString(const std::string &subscriber) const
Unsubscribe from property updates that convert to string.
Definition: ProgOptions.h:221
auto StealDeviceControl(const std::string &controller) -> void
Become device controller by force.
Definition: PluginServices.cxx:47
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: ProgOptions.cxx:291
void SetProperties(const fair::mq::Properties &input)
Set multiple config properties.
Definition: ProgOptions.cxx:306
fair::mq::Properties GetProperties(const std::string &q) const
Read several config properties whose keys match the provided regular expression.
Definition: ProgOptions.cxx:236
int Count(const std::string &key) const
Checks a property with the given key exist in the configuration.
Definition: ProgOptions.cxx:155
void DeleteProperty(const std::string &key)
Deletes a property with the given key from the config store.
Definition: ProgOptions.cxx:349
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
Definition: FairMQDevice.h:50
void UnsubscribeFromStateChange(const std::string &key)
Unsubscribe from state changes.
Definition: FairMQDevice.h:457
std::unordered_map< std::string, int > GetChannelInfo() const
Retrieve current channel information.
Definition: ProgOptions.cxx:161
static auto ToStr(DeviceState state) -> std::string
Convert DeviceState to string.
Definition: PluginServices.h:86
privacy