Skip to main content
QAROS Rust API Dev (main) · versions: Dev (main) · Developer Guide

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

A QarSession, obtained by crate::Runtime::rejoin or crate::Runtime::onboard.

Dropping the last handle destroys the session (qar_session_handle_destroy) and keeps the persisted identity, so a later rejoin works. Render senders keep the session alive; the session keeps its runtime alive.

Subscription callback state is owned here and freed only after the session handle is destroyed. The vendored header (“Ending a subscription”) guarantees that cancelling waits for a running callback, so freeing at cancel would also be sound; freeing at session end keeps a channel connected until then, which callers already rely on.

Implementations§

Source§

impl Session

Source

pub fn library(&self) -> Library

The library this session belongs to.

Source

pub fn as_raw(&self) -> *mut QarSession

The QarSession handle, for the functions only the raw table of Library::raw_api reaches (the “Raw only” column of the README’s coverage table), as in (library.raw_api().qar_impl_gui_panels_update_visible_to)(session.as_raw(), ...).

Taking the pointer is safe; using it is unsafe, and the caller keeps these rules:

  • It is valid while this Session lives; never use it after the Session is dropped.
  • Never destroy it (qar_session_handle_destroy): the Session destroys it on drop.
  • The session’s threading rules apply: call with it on the thread that uses this Session (no handle type is Send). A callback registered through a raw call runs on a library thread, and its state must stay alive until its subscription ends; end the subscription (cancel its token) before the session drops.
  • A handle a raw call hands out (a peer spec, a panel, an invite) is the caller’s to destroy with its _handle_destroy function.
Source

pub fn id(&self) -> Result<SessionId>

The session’s id (qar_session_get_id).

Source

pub fn graphics_adapter(&self) -> Result<Option<GraphicsAdapter>>

The GPU adapter the session’s graphics devices, and so every render sender’s frame textures, live on (qar_session_get_graphics_device_id): the one chained at onboard or rejoin, else the one QAROS or the library selected. Create the renderer’s device on it. None when the session knows no adapter. A session created without a graphics device fails with crate::StatusCode::GRAPHICS_DEVICE_NOT_INITIALIZED.

Source

pub fn my_peer(&self) -> Result<PeerInfo>

This application’s own peer.

Source

pub fn peers(&self) -> Result<Vec<PeerInfo>>

Snapshot of every known peer (count-then-fetch).

Source

pub fn set_display_name(&self, display_name: &str) -> Result<()>

qar_peer_update_display_name.

Source

pub fn subscribe_peer_updates( &self, callback: impl Fn(PeerInfo) + Send + Sync + 'static, ) -> Result<Subscription>

Calls callback with a snapshot whenever a peer joins, leaves or changes. Runs on library threads.

Source

pub fn lifecycle(&self) -> Result<SessionLifecycle>

The session’s current lifecycle state (qar_session_get_lifecycle_state): the session id it is in now and, after a move, the one it moved from and why. reason is empty here.

Source

pub fn open_qaros_view(&self, view: QarosView) -> Result<()>

Opens a predefined view of the QAROS Visualizer in this session’s QAROS (qar_session_open_qaros_view): the Pair Headset QR code, the Room Origin marker or the setup of one device type. The app needs no qaros:// link, no registered handler, and never looks for QAROS itself: an installed QAROS opens it through its own qaros.exe, a developer setup through the qaros.exe of the instance’s runtime folder, else the one beside the loaded runtime.

Only a session onboarded as a local app can open a view (ARGUMENT_NOT_SUPPORTED otherwise); ONBOARDING_HUB_UNREACHABLE when this session’s QAROS has no qaros.exe where it should be or it could not be started; NOT_IMPLEMENTED off Windows. Returns once the view was handed over, not when it shows.

Source

pub fn subscribe_lifecycle( &self, callback: impl Fn(SessionLifecycle) + Send + Sync + 'static, ) -> Result<Subscription>

Calls callback with each lifecycle state of the session (qar_session_subscribe_lifecycle): first the current one, then every change. Runs on library threads; hand the snapshot to the app’s own thread. On a new session id, get or create again what the app keys by it (app volumes, panels, senders); on crate::SessionLifecycleState::RePairRequired, drop the session and onboard again.

Source

pub fn subscribe_render_requests( &self, callback: impl Fn(RenderRequest) + Send + Sync + 'static, ) -> Result<Subscription>

Calls callback for each incoming render stream request (for example from a visualizer). Runs on library threads; create the sender on the session’s thread.

Source

pub fn create_render_sender( &self, config: &RenderSenderConfig, options: &BlockingOptions<'_>, ) -> Result<RenderSender>

qar_render_sender_create with the CPU graphics API.

Source

pub fn start_render_sender( &self, config: &RenderSenderConfig, timeout: Option<Duration>, wake: impl Fn() + Send + Sync + 'static, ) -> Result<PendingRenderSender>

Starts qar_render_sender_create_async with the CPU graphics API and returns at once; PendingRenderSender::poll picks the sender up on a later frame. timeout cancels the creation through its cancel token. wake runs on a library thread right after the library called back, for example to request a repaint that then polls. See PendingRenderSender for dropping a creation before it completes.

Source

pub unsafe fn create_vulkan_render_sender( &self, config: &RenderSenderConfig, vulkan: VulkanStreamParams, options: &BlockingOptions<'_>, ) -> Result<RenderSender>

qar_render_sender_create with the Vulkan graphics API: QAROS creates the frame images on vulkan.device and hands them out per frame through crate::OwnedFrame::vulkan_frame. Use crate::FrameLayout::SeparatedTextures for one image per eye and kind, as QuaternAR’s cube does. See crate::vulkan for the frame protocol.

§Safety
  • vulkan.physical_device and vulkan.device are valid handles, the device was created from that physical device, on the adapter this session was onboarded or rejoined with, and enables crate::vulkan::required_device_extensions.
  • The device outlives the returned sender and every frame and image handle taken from it.
Source

pub unsafe fn start_vulkan_render_sender( &self, config: &RenderSenderConfig, vulkan: VulkanStreamParams, timeout: Option<Duration>, wake: impl Fn() + Send + Sync + 'static, ) -> Result<PendingRenderSender>

Session::start_render_sender with the Vulkan graphics API, the non-blocking form of Session::create_vulkan_render_sender.

§Safety

As for Session::create_vulkan_render_sender, and the device must also stay valid for as long as the library may still create a sender on it: until this creation’s sender is taken and dropped; if the PendingRenderSender is dropped first, until the session is dropped; and if that creation had not called back by then, until the library is dropped.

Source

pub unsafe fn create_d3d11_render_sender( &self, config: &RenderSenderConfig, d3d11: D3D11StreamParams, options: &BlockingOptions<'_>, ) -> Result<RenderSender>

qar_render_sender_create with the D3D11 graphics API: QAROS creates the frame’s shared textures on the device in d3d11 and hands them out per frame through crate::OwnedFrame::d3d11_frame. See crate::d3d11 for the frame protocol. The sender keeps the references D3D11StreamParams::new (Windows) took on the device and context until it is destroyed, and its session with it when it held the last reference.

§Safety
  • The immediate context in d3d11 is used only on the thread that drives this session and its senders, or the device has multithread protection on: QAROS uses the context at times and on threads the header does not document, and a D3D11 immediate context is not thread-safe.
  • Parameters from crate::d3d11::D3D11StreamParams::from_raw hold valid pointers as long as that function requires.

The device should be on the adapter this session was onboarded or rejoined with (Session::graphics_adapter); the header creates the session’s devices there.

Source

pub unsafe fn start_d3d11_render_sender( &self, config: &RenderSenderConfig, d3d11: D3D11StreamParams, timeout: Option<Duration>, wake: impl Fn() + Send + Sync + 'static, ) -> Result<PendingRenderSender>

Session::start_render_sender with the D3D11 graphics API, the non-blocking form of Session::create_d3d11_render_sender. The device references stay with the creation: with the sender once taken; with the session when the PendingRenderSender is dropped first, until its callback comes; and for good when it never comes.

§Safety

As for Session::create_d3d11_render_sender. Parameters from crate::d3d11::D3D11StreamParams::from_raw must also stay valid for as long as the library may still create a sender on them: until this creation’s sender is taken and its session dropped; if the PendingRenderSender is dropped first, until the session is dropped; and if that creation had not called back by then, until the process ends.

Source

pub fn release_abandoned_creations(&self)

Destroys what async calls dropped before their callback delivered since: a render sender, an invite. Every start_* and every poll of a crate::PendingCall of this session do it too; call this regularly (once per frame) so such a sender does not stay connected to its target while no other call runs.

Source

pub fn app_volumes(&self) -> AppVolumes<'_>

The session’s app volume operations.

Source

pub fn gui_panels(&self) -> GuiPanels<'_>

The session’s GUI panel operations.

Source

pub fn panel_content(&self) -> PanelContent<'_>

Web pages this session serves to served GUI panels, and their messages.

Source

pub fn update_device_identity(&self, identity: &DeviceIdentity) -> Result<()>

Replaces the device this application describes itself as (qar_peer_update_device_identity), as crate::PeerPresentation::device_identity sets it at onboard or rejoin. A category other than the crate::SourceDeviceCategory values cannot be expressed; an empty device id fails with crate::StatusCode::ARGUMENT_NOT_SUPPORTED.

Source

pub fn start_onboarding_invite( &self, app_tag: &str, progress: Option<Sender<Progress>>, timeout: Option<Duration>, wake: impl Fn() + Send + Sync + 'static, ) -> Result<PendingCall<OnboardingInvite>>

Starts Session::request_onboarding_invite without blocking (qar_session_request_onboarding_invite_async) and returns at once; the PendingCall delivers the invite. The tag is checked (and copied) before this returns: a refused tag is the error of this call, and no callback follows. progress, timeout and wake as for crate::Runtime::start_onboard.

Source

pub fn invite_target_app( &self, connection: &str, options: &BlockingOptions<'_>, ) -> Result<PeerId>

Asks this machine’s hub to start the target app for one AR device (qar_session_invite_target_app) and returns its peer id once the target app’s peer has joined the session. connection names the device kind and address: "hololens:<host>", or a bare host, as hololens:<host>; crate::Library::target_app_connection_string builds it. An Android headset ("headset:<host>", "quest:", "android:") is never invited: it pairs itself and joins the session on its own, and this call fails with crate::StatusCode::HUB_TARGET_APP_DEVICE_NOT_INVITABLE for it; find it with Session::find_render_target.

Only this machine’s hub answers, and the invite is one-time: the hub remembers the device but never re-invites it by itself. A device another hub serves is stopped there first. Fails with crate::StatusCode::ARGUMENT_NOT_SUPPORTED for a malformed string, one without a host or of another kind (a visualizer: one, which Session::find_render_target resolves), and with crate::StatusCode::HUB_TARGET_APP_DEVICE_NOT_INVITABLE when the hub has no target app for the device family.

Source

pub fn start_invite_target_app( &self, connection: &str, progress: Option<Sender<Progress>>, timeout: Option<Duration>, wake: impl Fn() + Send + Sync + 'static, ) -> Result<PendingCall<PeerId>>

Starts Session::invite_target_app without blocking (qar_session_invite_target_app_async); the PendingCall delivers the target app’s peer id. progress, timeout and wake as for crate::Runtime::start_onboard.

Source

pub fn kill_target_app( &self, target_app: PeerId, options: &BlockingOptions<'_>, ) -> Result<()>

Asks this machine’s hub to stop a target app it started (qar_session_kill_target_app): the target app and the whole pipeline feeding it. A target app this machine’s hub did not start is served by no hub, so the call ends in crate::StatusCode::TIMEOUT, not an authorization error.

Source

pub fn start_kill_target_app( &self, target_app: PeerId, progress: Option<Sender<Progress>>, timeout: Option<Duration>, wake: impl Fn() + Send + Sync + 'static, ) -> Result<PendingCall<()>>

Starts Session::kill_target_app without blocking (qar_session_kill_target_app_async). progress, timeout and wake as for crate::Runtime::start_onboard.

Source

pub fn find_render_target(&self, connection: &str) -> Result<PeerId>

The peer id of an already-connected render target, from its connection string (qar_session_find_render_target), for example a visualizer: one.

Source

pub fn request_onboarding_invite( &self, app_tag: &str, options: &BlockingOptions<'_>, ) -> Result<OnboardingInvite>

Mints a co-process invite (qar_session_request_onboarding_invite): a process this app starts onboards with it (crate::OnboardMethod::Invite, with crate::RuntimeConfig::ephemeral_storage) and joins under the peer id the hub remembers for this app’s approval and app_tag. app_tag is required, an identity key as for crate::OnboardMethod::LocalApp; give the co-process a tag of its own. Only a session that joined as a local app, or an app the QAROS launcher started, may request one; any other fails with crate::StatusCode::ONBOARDING_INVITE_REFUSED, which is final. A tag that breaks the rules fails with crate::StatusCode::ARGUMENT_NOT_SUPPORTED before the hub is asked; crate::StatusCode::ONBOARDING_HUB_UNREACHABLE means the session names no hub to ask yet: retry. The invite is single use, valid for 60 s and redeemable only on the hub’s PC.

Trait Implementations§

Source§

impl Debug for Session

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.