Skip to content

API · fair::mq

PluginServicesclass

#include <fairmq/PluginServices.h>fairmq/PluginServices.h:39GitHub ↗

Facilitates communication between devices and plugins.

  • Configuration interface
  • Control interface

Nested types

Types

Functions

auto TakeDeviceControl(const std::string& controller) -> void

Become device controller.

Only one plugin can succeed to take control over device state transitions at a time.

controller
id
fair::mq::PluginServices::DeviceControlError throws
if there is already a device controller.
auto StealDeviceControl(const std::string& controller) -> void

Become device controller by force.

Take over device controller privileges by force. Does not trigger the ReleaseDeviceControl condition! This function is intended to implement override/emergency control functionality (e.g. device shutdown on SIGINT).

controller
id
auto ReleaseDeviceControl(const std::string& controller) -> void

Release device controller role.

controller
id
fair::mq::PluginServices::DeviceControlError throws
if passed controller id is not the current device controller.
auto ChangeDeviceState(
    const std::string& controller,
    DeviceStateTransition next
) -> bool

Request a device state transition.

The state transition may not happen immediately, but when the current state evaluates the pending transition event and terminates. In other words, the device states are scheduled cooperatively. If the device control role has not been taken yet, calling this function will take over control implicitely.

controller
id
next
state transition
fair::mq::PluginServices::DeviceControlError throws
if control role is not currently owned by passed controller id.
auto SubscribeToDeviceStateChange(
    const std::string& subscriber,
    std::function<void(DeviceState)> callback
) -> void

Subscribe with a callback to device state changes.

The callback will be called at the beginning of a new state. The callback is called from the thread the state is running in.

subscriber
id
callback
—
auto GetNumberOfConnectedPeers(
    const std::string& channelName,
    int index = 0
) -> unsigned long

DO NOT USE, ONLY FOR TESTING, WILL BE REMOVED (and info made available via property api)

auto PropertyExists(const std::string& key) const -> bool

Checks a property with the given key exist in the configuration.

key
—
Returns
true if it exists, false otherwise
template<typename T>
auto SetProperty(const std::string& key, T val) -> void

Set config property.

Setting a config property will store the value in the FairMQ internal config store and notify any subscribers about the update. It is property dependent, if the call to this method will have an immediate, delayed or any effect at all.

key
—
val
—
template<typename T>
bool UpdateProperty(const std::string& key, T val)

Updates an existing config property (or fails if it doesn't exist)

key
—
val
—
template<typename T>
auto GetProperty(const std::string& key) const -> T

Read config property, throw if no property with this key exists.

key
—
Returns
config property
template<typename T>
T GetProperty(const std::string& key, const T& ifNotFound) const

Read config property, return provided value if no property with this key exists.

key
—
ifNotFound
value to return if key is not found
Returns
config property
auto GetPropertyAsString(const std::string& key) const -> std::string

Read config property as string, throw if no property with this key exists.

Supports conversion to string for a fixed set of types, for custom/unsupported types add them via fair::mq::PropertyHelper::AddType<MyType>("optional label") the provided type must then be convertible to string via operator<<

key
—
Returns
config property converted to string
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.

Supports conversion to string for a fixed set of types, for custom/unsupported types add them via fair::mq::PropertyHelper::AddType<MyType>("optional label") the provided type must then be convertible to string via operator<<

key
—
ifNotFound
value to return if key is not found
Returns
config property converted to string
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.

q
regex string to match for
Returns
container with properties (fair::mq::Properties as an alias for std::map<std::string, Property>, where property is boost::any)
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.

Typically more performant than GetPropertiesAsString with regex

q
string to match for
Returns
container with properties (fair::mq::Properties as an alias for std::map<std::string, Property>, where property is boost::any)
auto GetChannelInfo() const -> std::unordered_map< std::string, int >

Retrieve current channel information.

Returns
a map of <channel name, number of subchannels>
template<typename T>
auto SubscribeToPropertyChange(
    const std::string& subscriber,
    std::function<void(const std::string&key, T)> callback
) const -> void

Subscribe to property updates of type T.

Subscribe to property changes with a callback to monitor property changes in an event based fashion.

subscriber
—
callback
function
auto SubscribeToPropertyChangeAsString(
    const std::string& subscriber,
    std::function<void(const std::string&key, std::string)> callback
) const -> void

Subscribe to property updates.

Subscribe to property changes with a callback to monitor property changes in an event based fashion. Will convert the property to string.

subscriber
—
callback
function

Static functions

static auto ToDeviceState(const std::string& state) -> DeviceState

Convert string to DeviceState.

state
to convert
Returns
DeviceState enum entry
std::out_of_range throws
if a string cannot be resolved to a DeviceState
static auto ToDeviceStateTransition(const std::string& transition) -> DeviceStateTransition

Convert string to DeviceStateTransition.

transition
to convert
Returns
DeviceStateTransition enum entry
std::out_of_range throws
if a string cannot be resolved to a DeviceStateTransition
static auto ToStr(DeviceState state) -> std::string

Convert DeviceState to string.

state
to convert
Returns
string representation of DeviceState enum entry