VLink  2.0.0
A high-performance communication middleware
getter.h File Reference

Read-side primitive of the VLink field communication model. More...

#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <type_traits>
#include "./base/condition_variable.h"
#include "./base/functional.h"
#include "./impl/getter_impl.h"
#include "./node.h"
#include "./internal/getter-inl.h"
Include dependency graph for getter.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  vlink::Getter< ValueT, SecT >
 Type-safe latest-value reader for the VLink field communication model. More...
 
class  vlink::SecurityGetter< ValueT >
 Convenience alias of Getter with per-message decryption enabled. More...
 

Namespaces

 

Detailed Description

Read-side primitive of the VLink field communication model.

Getter<ValueT, SecT> mirrors the latest value produced by a matching Setter on the same URL. Unlike Subscriber it retains only the most recent payload rather than queuing every update, and it offers a blocking wait_for_value() entry point in addition to the standard event callback.

The class is a thin, header-only template wrapper around GetterImpl and owns its own cached value_, change-tracking buffer, and condition variable.

Field-model Data Flow
*   Setter<ValueT>             Transport Back-end             Getter<ValueT>
*   --------------             ------------------             ---------------
*      | set(v)                       |                              |
*      |----------------------------->|  serialised latest value     |
*      |                              |--- overwrites previous ----->|
*      |                              |                              |
*      |                              |                              |  Serializer::
*      |                              |                              |  deserialize
*      |                              |                              |--> listen cb (optional)
*      |                              |                              |--> value_ cached
*      |                              |                              |--> wait_for_value
*      |                              |                              |    returns true
*      |                              |                              |--> get() => value
* 
Getter vs Subscriber
Feature Getter<T> Subscriber<T>
Value retention Latest value cached None
Transport role tag kGetter kSubscriber
Blocking read wait_for_value() N/A
Duplicate suppression set_change_reporting(true) N/A
Cross-role bridge mark_as_subscriber() mark_as_getter()
Read-Mode Variants
Method Blocking Result type Notes
get() No std::optional Returns nullopt initially
wait_for_value(timeout) Yes bool (then get()) Default infinite if 0
listen(callback) No void(const ValueT&) Fires on every update
listen(cb) + change_reporting No void(const ValueT&) Suppress identical bytes
Usage Patterns
vlink::Getter<int> g("shm://vehicle/gear");
if (auto v = g.get()) { use(*v); }
if (g.wait_for_value(std::chrono::milliseconds(500))) {
use(*g.get());
}
g.listen([](const int& v) { on_update(v); });
g.set_change_reporting(true);
g.listen([](const int& v) { on_changed(v); });
Note
Until a Setter writes for the first time, get() returns std::nullopt and wait_for_value() blocks.
See also
setter.h, subscriber.h, node.h, serializer.h