template <typename T, typename C = void(T)>
class HangingGetterBase
Defined at line 46 of file ../../src/connectivity/bluetooth/lib/fidl/hanging_getter.h
HangingGetter generalizes the consumer/producer pattern often involved in FIDL hanging get
implementations.
USAGE:
Use `Set()` to update the state watched by the FIDL method:
HangingGetter
<int
> foo;
...
void OnFooUpdated(int new_foo) {
foo.Set(new_foo);
}
Use `Watch()` to invoke the response callback with any updates to the state or defer it until the
update happens later:
void GetFoo(GetFooCallback callback) {
foo.Watch(std::move(callback));
}
A specialization is provided for state that is a growing collection of state updates:
HangingVectorGetter
<int
> foo;
...
void OnFooUpdated(int new_foo) {
foo.Add(new_foo);
}
Public Methods
bool armed ()
Returns true if a callback is already assigned to this getter.
Defined at line 52 of file ../../src/connectivity/bluetooth/lib/fidl/hanging_getter.h
void Set (T value)
Assign |value| to the stored state and notify any pending Watch callbacks.
Defined at line 55 of file ../../src/connectivity/bluetooth/lib/fidl/hanging_getter.h
void Transform (Mutator f)
Mutably access the stored state via function |f| and notify any pending Watch callbacks. The
Mutator function |f| will receive the current value and should the return the new value after
applying any transformations to it.
This is useful for value types that accumulate data. To directly assign a value, use the
non-mutator overload instead.
Defined at line 66 of file ../../src/connectivity/bluetooth/lib/fidl/hanging_getter.h
void Watch (Callback callback)
Invoke |callback| with any updates to the state. If the state has been accessed via one of the
Set() functions since the last call to Watch(), then |callback| will run immediately.
Otherwise, |callback| is run next time the state is accessed.
Once |callback| runs, the store state becomes cleared. The next call to one of the Set()
functions will default-construct a new state.
Multiple callbacks can be queued to be notified simultaneously next time the state gets
updated. All callbacks will get invoked with a separate copy of the new state, however there is
no requirement that the state type T itself be copiable. How the value is passed to the
callbacks is left up to the Notify() member function implementation.
Defined at line 89 of file ../../src/connectivity/bluetooth/lib/fidl/hanging_getter.h
Protected Methods
void Notify (std::queue<Callback> callbacks, T value)
This member function is called when a value update triggers a registered watcher Callback to be
notified. This is abstract to allow HangingGetter variants to apply any necessary
transformations between the stored value type "T" and the parameter type of the callback type
"C".
For example, this is useful when the stored type is a custom accumulator type. A
HangingGetterBase implementation can, for example, implement a custom mapping from the stored
accumulator to a FIDL struct type that the callback expects.