API Conventions
The API is deliberately uniform: once you know these six patterns, every module (onboarding, panels, volumes, streams, peers) reads the same way. The concepts are identical across languages; the idioms differ. Pick your language above.
The API also only grows: functions are appended, never changed, so any header works with any QAROS runtime, older or newer. How to detect a feature an older runtime lacks, and the mistakes to avoid: Compatibility.
1. Opaque handles and value IDs
Two kinds of identifiers exist everywhere. Opaque handles are references to library-owned objects — you never inspect them, you pass them back to the API and release them. Value IDs are small copyable UUID values you can store, compare, stringify, and persist.
The key rule: releasing a handle ends what it refers to in this process. Releasing a session handle leaves the session; nothing is persisted, so the next start of a local app or a companion simply joins again.
- Opaque handles:
QarRuntime*,QarSession*,QarGuiPanel*,QarAppVolume*,QarPeerSpec*,QarCancelToken*,QarOnboardingInvite*. Release with the matchingqar_*_handle_destroy(). - Value IDs:
QarPeerId,QarSessionId,QarGuiPanelId,QarAppVolumeId,QarStreamId. Compare withqar_*_id_equals, render withqar_uuid_to_string.
// Releasing the handle leaves the session; a local app joins again on its next start:
qar_session_handle_destroy(session);
// IDs compare by value and render as text:
bool same_peer = qar_peer_id_equals(&first_peer, &second_peer);
char text[64];
qar_result_log_if_error(qar_uuid_to_string(first_peer.data, text, sizeof(text)));
2. Results and status
Every fallible call reports success or failure by value — never by throwing for an expected native condition. Some status codes are expected control flow, not errors: an approval prompt nobody answered in time means "ask the user and start again", not a bug.
Every fallible function returns a QarResult by value:
QarResult r = qar_some_call(...);
if (qar_result_is_error(r)) { /* handle */ }
if (qar_result_has_code(r, QAR_STATUS_ONBOARDING_APPROVAL_TIMEOUT)) { /* ask, start again */ }
qar_result_log_if_error(r); // convenience: log if it was an error
qar_result_is_success / qar_result_is_error test the outcome;
qar_result_has_code matches a specific QarStatusCode.
3. Extensible init structs (QarStructureHeader)
Optional capabilities are added by chaining extension structures onto a base init struct — the same pattern OpenXR and Vulkan use. This is how the API grows without ever changing a signature: new capabilities appear as new extension structs. For example, a local app joins with the local-app extension, and an app tag extension chained after it tells several instances of one app apart.
Every ...Init struct begins with a QarStructureHeader { type, next }. Always
build it with its qar_*_default() helper (which zero-fills and stamps type),
then chain extensions through next:
QarOnboardInit init = qar_onboard_init_default();
QarOnboardLocalAppExt local = qar_onboard_local_app_ext_default();
QarOnboardLocalAppTagExt tag = qar_onboard_local_app_tag_ext_default();
local.approval_timeout_ms = 60000;
tag.app_tag = "left.my-viewer.vendor"; // printable ASCII, constant across versions
local.header.next = &tag.header; // chain local app -> tag
init.header.next = &local.header; // chain init -> local app
4. Blocking / async pairs
Every long-running operation exists twice: a blocking form and an async form. The blocking form can report progress while you wait; the async form returns immediately and delivers its outcome later, exactly once, including on cancellation.
- Blocking:
qar_runtime_onboard(...)blocks until done; an optional progress callback fires from an internal thread while you wait. - Async:
qar_runtime_onboard_async(...)returns immediately; a result callback fires exactly once on a background thread — on success, error, and cancellation. After it returns, the library never touches youruser_stateagain.
Both accept an optional QarCancelToken (qar_cancel_token_create /
_with_timeout), which you may cancel from any thread and must keep alive until
the operation finishes. Progress callbacks share one signature delivering a
severity, a percentage, and a message.
:::warning Callback threading Result and progress callbacks (in C) and subscription/event callbacks (in every language) arrive on library threads. Do not call blocking QAROS functions from inside them, and marshal to your own thread before touching single-threaded application state. :::
:::info Ending a subscription
When qar_cancel_token_cancel, qar_cancel_token_handle_destroy,
qar_session_handle_destroy or qar_library_destroy returns (in C#, Dispose
of the subscription; in Rust, dropping its Subscription, which cancels its
token), a callback of the subscription that was running on another thread has
finished, and none starts afterwards. Free user_state right after that call.
Called from inside the subscription's own callback, these calls return without
waiting for it. Never end a subscription while holding a lock its callback
takes.
:::
5. Enumeration and string getters
Reading a variable-size collection or string is a snapshot operation in every language: the shape of the call differs, the meaning does not.
Enumerations use the two-call count-then-fetch idiom; string getters take a
caller-provided buffer plus size; serialization uses *_serialized_size then
*_serialize:
size_t count = 0;
qar_query_peer_specs_count(session, &count); // 1: ask for the size
QarPeerSpec** specs = malloc(count * sizeof(*specs));
qar_query_peer_specs(session, specs, count, &count); // 2: fetch
// ... use ...
for (size_t i = 0; i < count; ++i) qar_peer_spec_handle_destroy(specs[i]);
free(specs);
6. Ownership and lifetime
The lifetime discipline is the same idea in every language: you own what you receive, borrowed things handed to you inside a callback are valid only for that callback, and teardown runs in reverse of setup.
- Init structs and the strings they point to are copied before the call returns — stack-allocate freely.
- Out-handles are owned by you: release every handle you receive (from calls
and from result callbacks) with its
*_handle_destroy. - Handles delivered inside a callback are borrowed — read what you need during the callback; do not store the handle.
- A session handle keeps the runtime alive internally, so destruction-order mistakes don't dangle — but the intended order is: destroy session handle → destroy runtime → destroy library.
- The API is designed for single-threaded use per runtime; callbacks are the only cross-thread surface.