Several API Instances in One Process
Source: qar-streaming-c/examples/api_instances_in_one_process.c. Which mode to use: Choosing an Onboarding Mode. API details: Onboarding and Sessions.
Several API Instances in One Process
What You Will Learn
- Why a second API instance in the same process needs no invite and no approval of its own
- That two local onboards with the same app tag return two handles to one session, under one peer id
- That a different tag is a different peer with a session of its own
- When the shared session ends
When to Use It
Your process uses QAROS from more than one place: an application and a plug-in it hosts, native code and a C# or Unity layer, two libraries that each wrap the C API. Each place creates its own QarRuntime and onboards as a local app (Local App Onboarding). The runtime library notices that the process already holds a session with that hub and tag and hands out a new handle to it. One approval, one enrollment, one peer. Windows and Linux, like local enrollment.
A process you start is not covered: it is another executable, so it joins with a co-process invite (Co-Process Onboarding).
Build and Run
The first run asks for the approval once, as any local app does.
Step 1: Each Instance Onboards as a Local App
Both "instances" run the same function with their own runtime, as two libraries in one process would:
Step 2: One Session, One Peer
What the runtime does for the second onboard with the same hub and tag:
- It sends nothing to the hub: no enrollment, no prompt, no new certificate. The progress callback reports one INFO message saying the session is shared.
- The returned onboarding id is zero, as for every local app.
- The first onboard's options win: the second one's presentation and QarGraphicsDeviceId are not applied. Agree on them inside your process, or let the instance that starts first decide.
- Two onboards running at the same time share one enrollment: the second waits for the first and then shares its session (or fails with QAR_STATUS_TIMEOUT when the first does not finish within the approval timeout plus two minutes).
A different tag is a different peer: the hub remembers a peer id per approval and tag, so the third onboard below enrolls on its own and gets a session of its own.
Step 3: Release in Any Order
- Each handle is released on its own with qar_session_handle_destroy. The session is left when the last handle to it is released, whichever instance created it; destroying the runtime that enrolled it first is fine.
- If the hub refuses to renew the session's certificate, every handle sees the same session end; it stays shared until its last handle goes.
- The next onboard after the last handle enrolls again and, with no other live process holding it, gets the same remembered peer id.
What Is Stored
Nothing, as for any local app: the key lives in this process's memory with a 30-minute certificate the runtime renews; the hub keeps the approval and the remembered peer id per tag.
Generated via doxygen2docusaurus 2.2.1 by Doxygen 1.9.8.