Data channels
Channels & subscriptions
Device telemetry, device status, and haptics state use Core channels. Each Sample carries the value, sequence, and timing metadata.
ReadChannel<T>
A read-only data channel returned by a device or Skeleton data accessor. Samples use the Sample wrapper.
ReadChannel<T>::latest()
Immediately read the most recent data item.
Type
std::optional<Sample<T>> ReadChannel<T>::latest() const;Returns
std::optional<Sample<T>>. See Sample<T>.
Details
- Call conditions: Owning object not closed.
- Does not wait for new data; returns an empty value when no sample exists.
Each call reads the snapshot currently retained by the channel; it does not wait for the next frame. Use next() to wait once, or subscribe() to process data continuously.
Errors
- Close errors.
Example
These snippets use an already selected device.
if (const auto sample = device.telemetry().latest()) {
std::cout << sample->sequence << '\n';
}Complete example: telemetry.cpp.
See also
ReadChannel<T>::subscribe()
Invoke the callback each time new data arrives.
Type
Subscription ReadChannel<T>::subscribe(std::function<void(const Sample<T>&)> callback) const;Parameters
std::function<void(const Sample<T>&)>, required
Returns
Details
- Call conditions: Recommended before start.
The callback receives a const Sample<T>&. Keep the returned Subscription alive. Callbacks for one subscription execute sequentially, without concurrency; do not synchronously cancel or destroy the subscription from inside its own callback.
Errors
- Parameter or close errors.
Example
These snippets use an already selected device. Register the subscription before starting the device.
auto subscription = device.telemetry().subscribe(
[](const qnbot::Sample<qnbot::ExoTelemetry>& sample) {
std::cout << sample.sequence << '\n';
});Complete example: telemetry.cpp.
See also
ReadChannel<T>::next()
Create a wait operation for the next sample.
Type
NextOperation<T> ReadChannel<T>::next() const;Returns
NextOperation<T>. See NextOperation<T>.
Details
- Call conditions: While the owning object is running.
- Creates a wait operation without blocking here; use
get()to wait orcancel()to cancel.
Errors
- Cancellation, close, or data stream errors.
Example
Start the owning device first. get() blocks the current thread until a sample arrives or the wait ends.
auto operation = device.telemetry().next();
auto sample = operation.get();
std::cout << sample.sequence << '\n';Related Core example (Glove): async_runtime.cpp.
See also
ReadChannel<T>::with_config()
Create a channel view with a subscription delivery policy.
Type
ReadChannel<T> ReadChannel<T>::with_config(const SubscriptionConfig& config) const;Parameters
const SubscriptionConfig&
Returns
ReadChannel<T>. See ReadChannel<T>.
Details
- Call conditions: Before creating a subscription.
- Returns a new read view sharing the same source; leaves the original channel, existing subscriptions, and computation rates unchanged.
The configuration affects only subscriptions newly created from that view. Snapshot reads through latest() and one-shot waits through next() retain their behavior.
Errors
- Parameter or close errors.
Example
These snippets use an already selected device. on_pose is an application-defined callback.
auto pose = device.telemetry().with_config(
qnbot::SubscriptionConfig::latest(30.0));
auto subscription = pose.subscribe(on_pose);Related Core example (Glove): subscription_config.cpp.
See also
Subscription
Returned by subscribe() to represent a callback subscription. Closing the owning scope reclaims remaining subscriptions.
Subscription::unsubscribe()
Stop one callback early.
Type
void Subscription::unsubscribe();Returns
void.
Details
- Call conditions: When the SDK keeps running but the callback is no longer needed.
- Use only to stop a callback early. Do not synchronously unsubscribe from inside that subscription’s own callback.
Errors
- Synchronous cancellation inside the callback is unsafe.
Example
channel is an existing read channel whose device has started, and on_sample is an application callback. Stop early from the application thread, not synchronously from inside this subscription’s own callback.
auto subscription = channel.subscribe(on_sample);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
subscription.unsubscribe();Related Core example (Glove): subscription_config.cpp.
See also
SubscriptionConfig
The max_rate_hz delivery period includes callback processing time; only the remainder of the period is waited, rather than a full period after processing. The first available sample is delivered immediately. Scheduling jitter can vary individual intervals, so this is not a fixed sampling frequency.
Defines delivery for a subscription view used through with_config(). It affects subsequent subscriptions, not latest(), next(), existing subscriptions, or SDK/algorithm computation rates.
SubscriptionConfig::latest()
Deliver only the newest value in each pacing interval.
Type
SubscriptionConfig SubscriptionConfig::latest(std::optional<double> max_rate_hz = std::nullopt);Parameters
max_rate_hz: defaults tostd::nulloptwith no delivery rate cap; a supplied value must be positive and finite.
Returns
Details
- Call conditions: Configuring callbacks.
Errors
- Invalid rate.
Example
auto config = qnbot::SubscriptionConfig::latest(30.0);Related Core example (Glove): subscription_config.cpp.
See also
SubscriptionConfig::fifo()
Use a bounded ordered queue; drop the oldest item when full.
Type
SubscriptionConfig SubscriptionConfig::fifo(
std::size_t capacity,
std::optional<double> max_rate_hz = std::nullopt
);Parameters
capacity: required and positive; a full queue discards the oldest pending value.max_rate_hz: defaults tostd::nulloptwith no delivery rate cap; a supplied value must be positive and finite.
Returns
Details
- Call conditions: Configuring callbacks.
Errors
- Invalid capacity or rate.
Example
auto config = qnbot::SubscriptionConfig::fifo(128, 30.0);Related Core example (Glove): subscription_config.cpp.
See also
NextOperation<T>
Returned by ReadChannel<T>::next() to represent one cancellable wait.
NextOperation<T>::get()
Block until the next sample is available and return it.
Type
Sample<T> NextOperation<T>::get();Returns
Sample<T>. See Sample<T>.
Details
- Call conditions: During a single wait.
Errors
- Cancellation, close, or repeated consumption errors.
Example
The device owning channel has started. get() blocks the current thread; other application logic may request cancellation of this wait.
auto operation = channel.next();
const auto sample = operation.get();
std::cout << sample.sequence << '\n';Related Core example (Glove): async_runtime.cpp.
See also
NextOperation<T>::cancel()
Cancel this one-shot sample wait.
Type
void NextOperation<T>::cancel();Returns
void.
Details
- Call conditions: During a single wait.
Errors
- Cancellation, close, or repeated consumption errors.
See also
Sample<T>
Fields
Fields
| Field | Type | Description |
|---|---|---|
value | T | Current business data |
sequence | std::uint64_t | SDK sequence number, monotonically increasing within the same data category |
source_time | std::optional<double> | Data source time |
observed_at | double | Monotonic time at which the SDK received the data |
Neither source_time nor observed_at is a system calendar time.