Monado OpenXR Runtime
Loading...
Searching...
No Matches
ipc_server_handle_helpers.h
Go to the documentation of this file.
1// Copyright 2026, NVIDIA CORPORATION.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Helpers shared between the IPC server handle functions.
6 * @author Jakob Bornecrantz <tbornecrantz@nvidia.com>
7 * @ingroup ipc_server
8 */
9
10#pragma once
11
12#include "util/u_misc.h"
13
14#include "server/ipc_server.h"
15
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21
22/*
23 *
24 * IO blocking.
25 *
26 */
27
28/*!
29 * Is the given input blocked for this client by its @ref ipc_client_io_blocks.
30 *
31 * @ingroup ipc_server
32 */
33static inline bool
35{
36 volatile struct ipc_client_io_blocks *iob = &ics->client_state.io_blocks;
37
38 switch (XRT_GET_INPUT_TYPE(name)) {
39 case XRT_INPUT_TYPE_POSE: return iob->block_poses && name != XRT_INPUT_GENERIC_HEAD_POSE;
40 case XRT_INPUT_TYPE_HAND_TRACKING: return iob->block_hand_tracking;
45 case XRT_INPUT_TYPE_BOOLEAN: return iob->block_inputs;
46 // Don't block face or body tracking.
48 case XRT_INPUT_TYPE_FACE_TRACKING: return false;
49 }
50
51 return false;
52}
53
54/*!
55 * Zero out the inputs that are blocked for this client, in place.
56 *
57 * @ingroup ipc_server
58 */
59static inline void
61 struct xrt_input *inputs,
62 uint32_t input_count)
63{
64 for (uint32_t i = 0; i < input_count; i++) {
65 enum xrt_input_name name = inputs[i].name;
66 if (!ipc_server_client_is_input_blocked(ics, name)) {
67 continue;
68 }
69
70 // Keep the name, clients find inputs by name.
71 U_ZERO(&inputs[i]);
72 inputs[i].name = name;
73 }
74}
75
76/*!
77 * Zero out the outputs if outputs are blocked for this client, in place.
78 *
79 * @ingroup ipc_server
80 */
81static inline void
83 struct xrt_output *outputs,
84 uint32_t output_count)
85{
86 if (!ics->client_state.io_blocks.block_outputs) {
87 return;
88 }
89
90 for (uint32_t i = 0; i < output_count; i++) {
91 enum xrt_output_name name = outputs[i].name;
92
93 // Keep the name, clients find outputs by name.
94 U_ZERO(&outputs[i]);
95 outputs[i].name = name;
96 }
97}
98
99
100/*
101 *
102 * Validation.
103 *
104 */
105
106/*!
107 * Plain output calls copy the value as is, so reject PCM values: they hold
108 * client pointers and must go through a varlen haptic output call.
109 *
110 * @ingroup ipc_server
111 */
112static inline xrt_result_t
114{
115 if (value->type == XRT_OUTPUT_VALUE_TYPE_PCM_VIBRATION) {
116 IPC_ERROR(ics->server, "PCM vibration must use a haptic output call");
118 }
119
120 return XRT_SUCCESS;
121}
122
123/*!
124 * Reject haptic output calls with no samples, since the message channel can't
125 * send zero bytes, or with more samples than the service will allocate, see
126 * @ref IPC_MAX_PCM_HAPTIC_SAMPLES.
127 *
128 * @ingroup ipc_server
129 */
130static inline xrt_result_t
132{
133 if (buffer->num_samples == 0) {
134 IPC_ERROR(ics->server, "Sample count can't be zero");
136 }
137
138 if (buffer->num_samples > IPC_MAX_PCM_HAPTIC_SAMPLES) {
139 IPC_ERROR(ics->server, "Sample count exceeds maximum allowed count (%u > %u)", buffer->num_samples,
142 }
143
144 return XRT_SUCCESS;
145}
146
147#ifdef __cplusplus
148}
149#endif
#define U_ZERO(PTR)
Zeroes the correct amount of memory based on the type pointed-to by the argument.
Definition u_misc.h:68
static xrt_result_t ipc_server_validate_output_value(volatile struct ipc_client_state *ics, const struct xrt_output_value *value)
Plain output calls copy the value as is, so reject PCM values: they hold client pointers and must go ...
Definition ipc_server_handle_helpers.h:113
static void ipc_server_client_filter_blocked_inputs(volatile struct ipc_client_state *ics, struct xrt_input *inputs, uint32_t input_count)
Zero out the inputs that are blocked for this client, in place.
Definition ipc_server_handle_helpers.h:60
static void ipc_server_client_filter_blocked_outputs(volatile struct ipc_client_state *ics, struct xrt_output *outputs, uint32_t output_count)
Zero out the outputs if outputs are blocked for this client, in place.
Definition ipc_server_handle_helpers.h:82
static xrt_result_t ipc_server_validate_pcm_haptic_buffer(volatile struct ipc_client_state *ics, const struct ipc_pcm_haptic_buffer *buffer)
Reject haptic output calls with no samples, since the message channel can't send zero bytes,...
Definition ipc_server_handle_helpers.h:131
static bool ipc_server_client_is_input_blocked(volatile struct ipc_client_state *ics, enum xrt_input_name name)
Is the given input blocked for this client by its ipc_client_io_blocks.
Definition ipc_server_handle_helpers.h:34
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition xrt_defines.h:961
enum xrt_result xrt_result_t
Result type used across Monado.
xrt_output_name
Name of a output with a baked in type.
Definition xrt_defines.h:1645
#define XRT_GET_INPUT_TYPE(name)
Extract the xrt_input_type from an xrt_input_name.
Definition xrt_defines.h:940
@ XRT_INPUT_TYPE_POSE
A tracked pose.
Definition xrt_defines.h:891
@ XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE
Vec2 input, components in [-1, 1].
Definition xrt_defines.h:885
@ XRT_INPUT_TYPE_VEC3_MINUS_ONE_TO_ONE
Vec3 input, components in [-1, 1].
Definition xrt_defines.h:887
@ XRT_INPUT_TYPE_FACE_TRACKING
A tracked face.
Definition xrt_defines.h:895
@ XRT_INPUT_TYPE_BODY_TRACKING
A tracked body.
Definition xrt_defines.h:897
@ XRT_INPUT_TYPE_HAND_TRACKING
A tracked hand.
Definition xrt_defines.h:893
@ XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE
Float input in [-1, 1].
Definition xrt_defines.h:883
@ XRT_INPUT_TYPE_BOOLEAN
Boolean (digital, binary) input.
Definition xrt_defines.h:889
@ XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE
Float input in [0, 1].
Definition xrt_defines.h:881
@ XRT_INPUT_GENERIC_HEAD_POSE
Standard pose used for rendering.
Definition xrt_defines.h:966
@ XRT_SUCCESS
The operation succeeded.
Definition xrt_results.h:27
@ XRT_ERROR_INVALID_ARGUMENT
Invalid function arguments passed in, e.g.
Definition xrt_results.h:243
#define IPC_MAX_PCM_HAPTIC_SAMPLES
Max number of samples in one ipc_pcm_haptic_buffer.
Definition ipc_protocol.h:401
Common server side code.
Which types of IO to block for a client.
Definition ipc_protocol.h:343
Holds the state for a single client.
Definition ipc_server.h:102
struct ipc_server * server
Link back to the main server.
Definition ipc_server.h:104
Definition ipc_protocol.h:404
A single named input, that sits on a xrt_device.
Definition xrt_device.h:236
A union of all output types.
Definition xrt_defines.h:2422
A single named output, that sits on a xrt_device.
Definition xrt_device.h:254
Very small misc utils.