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
impl Session
Sourcepub fn as_raw(&self) -> *mut QarSession
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
Sessionlives; never use it after theSessionis dropped. - Never destroy it (
qar_session_handle_destroy): theSessiondestroys it on drop. - The session’s threading rules apply: call with it on the thread that uses this
Session(no handle type isSend). 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_destroyfunction.
Sourcepub fn graphics_adapter(&self) -> Result<Option<GraphicsAdapter>>
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.
Sourcepub fn set_display_name(&self, display_name: &str) -> Result<()>
pub fn set_display_name(&self, display_name: &str) -> Result<()>
qar_peer_update_display_name.
Sourcepub fn subscribe_peer_updates(
&self,
callback: impl Fn(PeerInfo) + Send + Sync + 'static,
) -> Result<Subscription>
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.
Sourcepub fn lifecycle(&self) -> Result<SessionLifecycle>
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.
Sourcepub fn open_qaros_view(&self, view: QarosView) -> Result<()>
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.
Sourcepub fn subscribe_lifecycle(
&self,
callback: impl Fn(SessionLifecycle) + Send + Sync + 'static,
) -> Result<Subscription>
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.
Sourcepub fn subscribe_render_requests(
&self,
callback: impl Fn(RenderRequest) + Send + Sync + 'static,
) -> Result<Subscription>
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.
Sourcepub fn create_render_sender(
&self,
config: &RenderSenderConfig,
options: &BlockingOptions<'_>,
) -> Result<RenderSender>
pub fn create_render_sender( &self, config: &RenderSenderConfig, options: &BlockingOptions<'_>, ) -> Result<RenderSender>
qar_render_sender_create with the CPU graphics API.
Sourcepub fn start_render_sender(
&self,
config: &RenderSenderConfig,
timeout: Option<Duration>,
wake: impl Fn() + Send + Sync + 'static,
) -> Result<PendingRenderSender>
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.
Sourcepub unsafe fn create_vulkan_render_sender(
&self,
config: &RenderSenderConfig,
vulkan: VulkanStreamParams,
options: &BlockingOptions<'_>,
) -> Result<RenderSender>
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_deviceandvulkan.deviceare valid handles, the device was created from that physical device, on the adapter this session was onboarded or rejoined with, and enablescrate::vulkan::required_device_extensions.- The device outlives the returned sender and every frame and image handle taken from it.
Sourcepub unsafe fn start_vulkan_render_sender(
&self,
config: &RenderSenderConfig,
vulkan: VulkanStreamParams,
timeout: Option<Duration>,
wake: impl Fn() + Send + Sync + 'static,
) -> Result<PendingRenderSender>
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.
Sourcepub unsafe fn create_d3d11_render_sender(
&self,
config: &RenderSenderConfig,
d3d11: D3D11StreamParams,
options: &BlockingOptions<'_>,
) -> Result<RenderSender>
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
d3d11is 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_rawhold 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.
Sourcepub unsafe fn start_d3d11_render_sender(
&self,
config: &RenderSenderConfig,
d3d11: D3D11StreamParams,
timeout: Option<Duration>,
wake: impl Fn() + Send + Sync + 'static,
) -> Result<PendingRenderSender>
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.
Sourcepub fn release_abandoned_creations(&self)
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.
Sourcepub fn app_volumes(&self) -> AppVolumes<'_>
pub fn app_volumes(&self) -> AppVolumes<'_>
The session’s app volume operations.
Sourcepub fn gui_panels(&self) -> GuiPanels<'_>
pub fn gui_panels(&self) -> GuiPanels<'_>
The session’s GUI panel operations.
Sourcepub fn panel_content(&self) -> PanelContent<'_>
pub fn panel_content(&self) -> PanelContent<'_>
Web pages this session serves to served GUI panels, and their messages.
Sourcepub fn update_device_identity(&self, identity: &DeviceIdentity) -> Result<()>
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.
Sourcepub fn start_onboarding_invite(
&self,
app_tag: &str,
progress: Option<Sender<Progress>>,
timeout: Option<Duration>,
wake: impl Fn() + Send + Sync + 'static,
) -> Result<PendingCall<OnboardingInvite>>
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.
Sourcepub fn invite_target_app(
&self,
connection: &str,
options: &BlockingOptions<'_>,
) -> Result<PeerId>
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.
Sourcepub fn start_invite_target_app(
&self,
connection: &str,
progress: Option<Sender<Progress>>,
timeout: Option<Duration>,
wake: impl Fn() + Send + Sync + 'static,
) -> Result<PendingCall<PeerId>>
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.
Sourcepub fn kill_target_app(
&self,
target_app: PeerId,
options: &BlockingOptions<'_>,
) -> Result<()>
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.
Sourcepub fn start_kill_target_app(
&self,
target_app: PeerId,
progress: Option<Sender<Progress>>,
timeout: Option<Duration>,
wake: impl Fn() + Send + Sync + 'static,
) -> Result<PendingCall<()>>
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.
Sourcepub fn find_render_target(&self, connection: &str) -> Result<PeerId>
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.
Sourcepub fn request_onboarding_invite(
&self,
app_tag: &str,
options: &BlockingOptions<'_>,
) -> Result<OnboardingInvite>
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.