Reading data
Channels & subscriptions
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.pose().latest()) {
std::cout << sample->sequence << '\n';
}Complete example: subscription_config.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.pose().subscribe(
[](const qnbot::Sample<qnbot::GlovePose>& sample) {
std::cout << sample.sequence << '\n';
});Complete example: subscription_config.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.pose().next();
auto sample = operation.get();
std::cout << sample.sequence << '\n';Complete example: 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.pose().with_config(
qnbot::SubscriptionConfig::latest(30.0));
auto subscription = pose.subscribe(on_pose);Complete example: subscription_config.cpp.
See also