Monado OpenXR Runtime
solarxr_ipc_socket.h
1// Copyright 2025, rcelyte
2// SPDX-License-Identifier: BSL-1.0
3
4#pragma once
5#include "util/u_logging.h"
6#include "util/u_time.h"
7#include "xrt/xrt_handles.h"
8
9#include <stdatomic.h>
10#ifdef XRT_OS_WINDOWS
11#include <afunix.h>
12#else
13#include <sys/un.h>
14#endif
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
21{
22 _Atomic(xrt_ipc_handle_t) ipc_handle;
23 struct xrt_reference reference;
24 enum u_logging_level log_level;
25 timepoint_ns timestamp;
26 uint32_t head, buffer_len, buffer_cap;
27 uint8_t *buffer;
28};
29
30void
31solarxr_ipc_socket_init(struct solarxr_ipc_socket *state, enum u_logging_level log_level);
32
33void
34solarxr_ipc_socket_destroy(struct solarxr_ipc_socket *state); // thread safe
35
36struct sockaddr_un
37solarxr_ipc_socket_find(enum u_logging_level log_level, const char filename[]);
38
39bool
40solarxr_ipc_socket_connect(struct solarxr_ipc_socket *state, struct sockaddr_un addr);
41
42bool
43solarxr_ipc_socket_wait_timeout(struct solarxr_ipc_socket *state, time_duration_ns timeout); // thread safe
44
45bool
46solarxr_ipc_socket_send_raw(struct solarxr_ipc_socket *state,
47 const uint8_t packet[],
48 uint32_t packet_len); // thread safe
49
50uint32_t
51solarxr_ipc_socket_receive(struct solarxr_ipc_socket *state);
52
53static inline bool
54solarxr_ipc_socket_is_connected(struct solarxr_ipc_socket *const state)
55{
56 return atomic_load(&state->ipc_handle) != XRT_IPC_HANDLE_INVALID;
57}
58
59#ifdef __cplusplus
60}
61#endif
u_logging_level
Logging level enum.
Definition: u_logging.h:44
int64_t timepoint_ns
Integer timestamp type.
Definition: u_time.h:77
int64_t time_duration_ns
Integer duration type in nanoseconds.
Definition: u_time.h:88
Definition: solarxr_ipc_socket.h:21
A base class for reference counted objects.
Definition: xrt_defines.h:98
Basic logging functionality.
Time-keeping: a clock that is steady, convertible to system time, and ideally high-resolution.
Native handle types.
int xrt_ipc_handle_t
The type for an IPC handle.
Definition: xrt_handles.h:74
#define XRT_IPC_HANDLE_INVALID
An invalid value for an IPC handle.
Definition: xrt_handles.h:84