#include <uhd/property_tree.hpp>
Public Types | |
typedef std::function< void(const T &)> | subscriber_type |
typedef std::function< T(void)> | publisher_type |
typedef std::function< T(const T &)> | coercer_type |
Public Member Functions | |
virtual | ~property (void)=0 |
virtual property< T > & | set_coercer (const coercer_type &coercer)=0 |
virtual property< T > & | set_publisher (const publisher_type &publisher)=0 |
virtual property< T > & | add_desired_subscriber (const subscriber_type &subscriber)=0 |
virtual property< T > & | add_coerced_subscriber (const subscriber_type &subscriber)=0 |
virtual property< T > & | update (void)=0 |
virtual property< T > & | set (const T &value)=0 |
virtual property< T > & | set_coerced (const T &value)=0 |
virtual const T | get (void) const =0 |
virtual const T | get_desired (void) const =0 |
virtual bool | empty (void) const =0 |
Public Member Functions inherited from uhd::property_iface | |
virtual | ~property_iface ()=default |
A templated property interface for holding the state associated with a property in a uhd::property_tree and registering callbacks when that value changes.
A property is defined to have two separate values:
By default, the desired and coerced values are identical as long as the property is not coerced. A property can be coerced in two ways:
It is possible to get notified every time the desired or coerced values of a property potentially change using subscriber callbacks. Every property can have zero or more desired and coerced subscribers.
If storing the property readback state in software is not appropriate (for example if it needs to be queried from hardware) then it is possible to use a publisher callback to get the value of the property. Calling get on the property will always call the publisher and the cached desired and coerced values are updated only using set* calls. A property must have at most one publisher. It is legal to have both a coercer and publisher for a property but the only way to access the desired and coerced values in that case would be by notification using the desired and coerced subscribers. Publishers are useful for creating read-only properties.
Requirements for the template type T:
typedef std::function<T(const T&)> uhd::property< T >::coercer_type |
typedef std::function<T(void)> uhd::property< T >::publisher_type |
typedef std::function<void(const T&)> uhd::property< T >::subscriber_type |
|
pure virtual |
|
pure virtual |
Register a subscriber into the property. All coerced subscribers are called when the coerced value potentially changes.
Once a subscriber is registered, it cannot be unregistered.
subscriber | the subscriber callback function |
|
pure virtual |
Register a subscriber into the property. All desired subscribers are called when the desired value potentially changes.
Once a subscriber is registered, it cannot be unregistered.
subscriber | the subscriber callback function |
|
pure virtual |
A property is empty if it has never been set. A property with a publisher is never empty.
|
pure virtual |
Get the current value of this property. The publisher (when provided) yields the value, otherwise an internal coerced value is returned.
uhd::assertion_error |
|
pure virtual |
Get the current desired value of this property.
uhd::assertion_error |
|
pure virtual |
Set the new value and call all the necessary subscribers. Order of operations:
value | the new value to set on this property |
uhd::assertion_error |
|
pure virtual |
Set a coerced value and call all subscribers. The coercer is bypassed, and the specified value is used as the coerced value. All coerced subscribers are called. This function can only be used when the coerce mode is set to MANUAL_COERCE.
value | the new value to set on this property |
uhd::assertion_error |
|
pure virtual |
Register a coercer into the property. A coercer is a callback function that updates the coerced value of a property.
Only one coercer may be registered per property.
coercer | the coercer callback function |
uhd::assertion_error | if called more than once |
|
pure virtual |
Register a publisher into the property. A publisher is a callback function the provides the value for a property.
Only one publisher may be registered per property.
publisher | the publisher callback function |
uhd::assertion_error | if called more than once |
|
pure virtual |
Calls all subscribers with the current value.
uhd::assertion_error |