|
dxd - dynax driver framework 3.0.1d223
cross platform open source driver development framework
|
promoted value More...
#include <dx_value.h>
Classes | |
| class | chain |
| a server that keeps the one it replaces: a derived class prepends its own step (the device's request to the hardware) and hands the rest to the server its base installed More... | |
| class | preference |
Public Types | |
| typedef std::unique_lock< mutex_t > | lock_t |
| typedef std::mutex | mutex_t |
| typedef _value_t | value_t |
Public Member Functions | |
| void | commit (lock_t &&lock, const value_t &value) |
| the server's answer: the value stands, the transition ends and the listeners are told - outside the lock, so a listener may read the promoted back | |
| operator const value_t & () | |
| promoted & | operator++ () noexcept |
| value_t | operator++ (int) noexcept |
| promoted & | operator+= (const value_t &value) noexcept |
| promoted & | operator-- () noexcept |
| value_t | operator-- (int) noexcept |
| promoted & | operator-= (const value_t &value) noexcept |
| const value_t & | operator-> () |
| promoted & | operator= (const value_t &value) |
| promoted & | operator= (promoted &promoted) noexcept |
| bool | operator== (const value_t &value) |
| bool | operator== (promoted &promoted) noexcept |
| promoted ()=delete | |
| a value stands either behind a server, asked on the first access, or on a value given at construction: neither is no promoted | |
| promoted (const value_t &value) | |
| promoted (const value_t &value, decltype(listen)::listeners &&listeners) | |
| promoted (decltype(server)&&server) | |
| promoted (decltype(server)&&server, decltype(listen)::listeners &&listeners) | |
Public Attributes | |
| bool | initialized {} |
| listen< std::function< void(const value_t &)> > | listen |
| std::function< void(lock_t &&, const value_t &, const value_t &)> | server {} |
| \ indicate the value is in transition - does not have the new value yet | |
| bool | transient {} |
| \ indicate the value has been initialized | |
Protected Attributes | |
| value_t | value {} |
promoted value
This works like any value_t except that interested parties can subscribe to get notified about changes. If a server has been given assigning a value forwards it to the server and expects the value to be commit()ed back, then all parties are notified. It features caching but ensures that always the actual server value are returned, if the server behaves correctly and promotes all value changes via commit() on its own. If the value has not been initialized the promoted value makes sure to request it from the server. A promoted is never born empty: it is constructed with a server, asked on the first access, or with a value - there is no default constructor, so a value that could be asked without either does not compile (dxd/CLAUDE.md, "A promoted with a server asks it first"). The listener need to make sure to unsubscribe when deleted.
usage: dx::promoted<value_t> promoted_value{server}; // or {value} promoted_value= new value assignment; current value= promoted_value;
using value_t= decltype(promoted<value_t>::value); using server_t= decltype(promoted<value_t>::server); using listen_t= decltype(promoted<value_t>::listen::value_t);
promoted_value.listen[id]= std::function<void(const value_t&)>; promoted_value.server(server);
The server needs to take ownership of the unique_lock and has to make sure to callback commit() and unlock the lock.
| typedef std::unique_lock<mutex_t> dx::promoted< _value_t >::lock_t |
| typedef std::mutex dx::promoted< _value_t >::mutex_t |
| typedef _value_t dx::promoted< _value_t >::value_t |
|
inline |
|
inline |
|
delete |
a value stands either behind a server, asked on the first access, or on a value given at construction: neither is no promoted
|
inline |
|
inline |
|
inline |
the server's answer: the value stands, the transition ends and the listeners are told - outside the lock, so a listener may read the promoted back
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
| bool dx::promoted< _value_t >::initialized {} |
| listen<std::function<void(const value_t&)> > dx::promoted< _value_t >::listen |
| std::function<void(lock_t&&, const value_t&, const value_t&)> dx::promoted< _value_t >::server {} |
\ indicate the value is in transition - does not have the new value yet
server: handle synchronous and asynchronous value updates and initialization lock: lock promoted value from access during update value: new value (if in transition) current: current value to allow discarding update and reverting to current value if update is not permitted
it needs to handle these case: not initialized and not in transition: initialze and commit the value not initialized and in transition: if dependent on external settings initialize a temporary and compare it with the new value and update the external setting if required make sure to commit the new value so listeners get notified either synchronously or asynchronously by external notification initialized and in transition: update external settings if any and make sure to commit the new value so listeners get notified either synchronously or asynchronousl by external notification
server will not be called with this state: initialized and not in transation
for synchronous operation: move lock to commit for asynchronous operation: store lock and at asynchronous response restore and move lock to commit
| bool dx::promoted< _value_t >::transient {} |
\ indicate the value has been initialized
|
protected |
| (c) copyright 2009 dynamic acoustics e.U. | generated on |