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> 22 #include <unordered_map> 25 #include <condition_variable> 48 , fDeviceControllerMutex()
49 , fReleaseDeviceControlCondition()
55 LOG(debug) <<
"Shutting down Plugin Services";
61 using DeviceState = fair::mq::State;
62 using DeviceStateTransition = fair::mq::Transition;
70 static auto ToDeviceState(
const std::string& state) -> DeviceState {
return GetState(state); }
76 static auto ToDeviceStateTransition(
const std::string& transition) -> DeviceStateTransition {
return GetTransition(transition); }
81 static auto ToStr(DeviceState state) -> std::string {
return GetStateName(state); }
86 static auto ToStr(DeviceStateTransition transition) -> std::string {
return GetTransitionName(transition); }
125 auto ChangeDeviceState(
const std::string& controller,
const DeviceStateTransition next) -> bool;
135 fDevice.SubscribeToStateChange(subscriber, [&,callback](fair::mq::State newState){
149 auto PropertyExists(
const std::string& key)
const ->
bool {
return fConfig.Count(key) > 0; }
158 auto SetProperty(
const std::string& key, T val) ->
void { fConfig.SetProperty(key, val); }
161 void SetProperties(
const fair::mq::Properties& props) { fConfig.SetProperties(props); }
166 bool UpdateProperty(
const std::string& key, T val) {
return fConfig.UpdateProperty(key, val); }
169 bool UpdateProperties(
const fair::mq::Properties& input) {
return fConfig.UpdateProperties(input); }
179 auto GetProperty(
const std::string& key)
const -> T {
return fConfig.GetProperty<T>(key); }
186 T
GetProperty(
const std::string& key,
const T& ifNotFound)
const {
return fConfig.GetProperty(key, ifNotFound); }
195 auto GetPropertyAsString(
const std::string& key)
const -> std::string {
return fConfig.GetPropertyAsString(key); }
205 auto GetPropertyAsString(
const std::string& key,
const std::string& ifNotFound)
const -> std::string {
return fConfig.GetPropertyAsString(key, ifNotFound); }
210 fair::mq::Properties
GetProperties(
const std::string& q)
const {
return fConfig.GetProperties(q); }
220 std::map<std::string, std::string>
GetPropertiesAsString(
const std::string& q)
const {
return fConfig.GetPropertiesAsString(q); }
244 fConfig.Subscribe<T>(subscriber, callback);
259 fConfig.SubscribeAsString(subscriber, callback);
278 boost::optional<std::string> fDeviceController;
279 mutable std::mutex fDeviceControllerMutex;
280 std::condition_variable fReleaseDeviceControlCondition;
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
static auto ToStr(DeviceStateTransition transition) -> std::string
Convert DeviceStateTransition to string.
Definition: PluginServices.h:86
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
T GetProperty(const std::string &key, const T &ifNotFound) const
Read config property, return provided value if no property with this key exists.
Definition: PluginServices.h:186
auto CycleLogVerbosityDown() -> void
Decreases logging verbosity, or sets it to highest if it is already lowest.
Definition: PluginServices.h:273
Definition: PluginServices.h:97
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
auto ReleaseDeviceControl(const std::string &controller) -> void
Release device controller role.
Definition: PluginServices.cxx:54
Definition: ProgOptions.h:36
auto SubscribeToDeviceStateChange(const std::string &subscriber, std::function< void(DeviceState)> callback) -> void
Subscribe with a callback to device state changes.
Definition: PluginServices.h:133
auto GetPropertyAsString(const std::string &key, const std::string &ifNotFound) const -> std::string
Read config property, return provided value if no property with this key exists.
Definition: PluginServices.h:205
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
Definition: FairMQDevice.h:53
auto ChangeDeviceState(const std::string &controller, const DeviceStateTransition next) -> bool
Request a device state transition.
Definition: PluginServices.cxx:15
auto WaitForReleaseDeviceControl() -> void
Block until control is released.
Definition: PluginServices.cxx:77
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
auto GetDeviceController() const -> boost::optional< std::string >
Get current device controller.
Definition: PluginServices.cxx:70