FairMQ
1.3.9
C++ Message Passing Framework
|
Facilitates communication between devices and plugins. More...
#include <fairmq/PluginServices.h>
Classes | |
struct | DeviceControlError |
struct | InvalidStateError |
struct | PropertyNotFoundError |
Public Types | |
enum | DeviceState : int { Ok, Error, Idle, InitializingDevice, DeviceReady, InitializingTask, Ready, Running, Paused, ResettingTask, ResettingDevice, Exiting } |
See https://github.com/FairRootGroup/FairRoot/blob/dev/fairmq/docs/Device.md#13-state-machine. | |
enum | DeviceStateTransition : int { InitDevice, InitTask, Run, Pause, Resume, Stop, ResetTask, ResetDevice, End, ErrorFound } |
Public Member Functions | |
PluginServices (FairMQProgOptions &config, FairMQDevice &device) | |
PluginServices (const PluginServices &)=delete | |
PluginServices | operator= (const PluginServices &)=delete |
auto | GetCurrentDeviceState () const -> DeviceState |
auto | TakeDeviceControl (const std::string &controller) -> void |
Become device controller. More... | |
auto | StealDeviceControl (const std::string &controller) -> void |
Become device controller by force. More... | |
auto | ReleaseDeviceControl (const std::string &controller) -> void |
Release device controller role. More... | |
auto | GetDeviceController () const -> boost::optional< std::string > |
Get current device controller. | |
auto | WaitForReleaseDeviceControl () -> void |
Block until control is released. | |
auto | ChangeDeviceState (const std::string &controller, const DeviceStateTransition next) -> void |
Request a device state transition. More... | |
auto | SubscribeToDeviceStateChange (const std::string &subscriber, std::function< void(DeviceState)> callback) -> void |
Subscribe with a callback to device state changes. More... | |
auto | UnsubscribeFromDeviceStateChange (const std::string &subscriber) -> void |
Unsubscribe from device state changes. More... | |
auto | PropertyExists (const std::string &key) const -> bool |
template<typename T > | |
auto | SetProperty (const std::string &key, T val) -> void |
Set config property. More... | |
template<typename T > | |
auto | GetProperty (const std::string &key) const -> T |
Read config property. More... | |
auto | GetPropertyAsString (const std::string &key) const -> std::string |
Read config property as string. More... | |
auto | GetChannelInfo () const -> std::unordered_map< std::string, int > |
auto | GetPropertyKeys () const -> std::vector< std::string > |
Discover the list of property keys. More... | |
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. More... | |
template<typename T > | |
auto | UnsubscribeFromPropertyChange (const std::string &subscriber) -> void |
Unsubscribe from property updates of type T. More... | |
auto | SubscribeToPropertyChangeAsString (const std::string &subscriber, std::function< void(const std::string &key, std::string)> callback) const -> void |
Subscribe to property updates. More... | |
auto | UnsubscribeFromPropertyChangeAsString (const std::string &subscriber) -> void |
Unsubscribe from property updates that convert to string. More... | |
auto | CycleLogConsoleSeverityUp () -> void |
auto | CycleLogConsoleSeverityDown () -> void |
auto | CycleLogVerbosityUp () -> void |
auto | CycleLogVerbosityDown () -> void |
Static Public Member Functions | |
static auto | ToDeviceState (const std::string &state) -> DeviceState |
Convert string to DeviceState. More... | |
static auto | ToDeviceStateTransition (const std::string &transition) -> DeviceStateTransition |
Convert string to DeviceStateTransition. More... | |
static auto | ToStr (DeviceState state) -> std::string |
Convert DeviceState to string. More... | |
static auto | ToStr (DeviceStateTransition transition) -> std::string |
Convert DeviceStateTransition to string. More... | |
Static Public Attributes | |
static const std::unordered_map< std::string, DeviceState > | fkDeviceStateStrMap |
static const std::unordered_map< DeviceState, std::string, tools::HashEnum< DeviceState > > | fkStrDeviceStateMap |
static const std::unordered_map< std::string, DeviceStateTransition > | fkDeviceStateTransitionStrMap |
static const std::unordered_map< DeviceStateTransition, std::string, tools::HashEnum< DeviceStateTransition > > | fkStrDeviceStateTransitionMap |
static const std::unordered_map< FairMQDevice::State, DeviceState, tools::HashEnum< FairMQDevice::State > > | fkDeviceStateMap |
static const std::unordered_map< DeviceStateTransition, FairMQDevice::Event, tools::HashEnum< DeviceStateTransition > > | fkDeviceStateTransitionMap |
Friends | |
auto | operator<< (std::ostream &os, const DeviceState &state) -> std::ostream & |
auto | operator<< (std::ostream &os, const DeviceStateTransition &transition) -> std::ostream & |
Facilitates communication between devices and plugins.
auto PluginServices::ChangeDeviceState | ( | const std::string & | controller, |
const DeviceStateTransition | next | ||
) | -> void |
Request a device state transition.
controller | id |
next | state transition |
fair::mq::PluginServices::DeviceControlError | if control role is not currently owned by passed controller id. |
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.
|
inline |
|
inline |
Read config property.
key |
TODO Currently, if a non-existing key is requested and a default constructed object is returned. This behaviour will be changed in the future to throw an exception in that case to provide a proper sentinel.
|
inline |
Read config property as string.
key |
If a type is not supported, the user can provide support by overloading the ostream operator for this type
|
inline |
Discover the list of property keys.
auto PluginServices::ReleaseDeviceControl | ( | const std::string & | controller | ) | -> void |
Release device controller role.
controller | id |
fair::mq::PluginServices::DeviceControlError | if passed controller id is not the current device controller. |
|
inline |
Set config property.
key | |
val |
fair::mq::PluginServices::InvalidStateError | if method is called in unsupported device states |
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.
auto PluginServices::StealDeviceControl | ( | const std::string & | controller | ) | -> void |
Become device controller by force.
controller | id |
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).
|
inline |
Subscribe with a callback to device state changes.
subscriber | id |
callback | The callback will be called at the beginning of a new state. The callback is called from the thread the state is running in. |
|
inline |
Subscribe to property updates of type T.
subscriber | |
callback | function |
Subscribe to property changes with a callback to monitor property changes in an event based fashion.
|
inline |
Subscribe to property updates.
subscriber | |
callback | function |
Subscribe to property changes with a callback to monitor property changes in an event based fashion. Will convert the property to string.
auto PluginServices::TakeDeviceControl | ( | const std::string & | controller | ) | -> void |
Become device controller.
controller | id |
fair::mq::PluginServices::DeviceControlError | if there is already a device controller. |
Only one plugin can succeed to take control over device state transitions at a time.
|
inlinestatic |
Convert string to DeviceState.
state | to convert |
std::out_of_range | if a string cannot be resolved to a DeviceState |
|
inlinestatic |
Convert string to DeviceStateTransition.
transition | to convert |
std::out_of_range | if a string cannot be resolved to a DeviceStateTransition |
|
inlinestatic |
Convert DeviceState to string.
state | to convert |
|
inlinestatic |
Convert DeviceStateTransition to string.
transition | to convert |
|
inline |
Unsubscribe from device state changes.
subscriber | id |
|
inline |
Unsubscribe from property updates of type T.
subscriber |
|
inline |
Unsubscribe from property updates that convert to string.
subscriber |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |