The open source OpenXR runtime

u/prober: Add helper file for prober functions

authored by

Jakob Bornecrantz and committed by
Jakob Bornecrantz
ceed09d9 d76b1f5e

+116
+2
src/xrt/auxiliary/CMakeLists.txt
··· 194 194 util/u_pacing_compositor_fake.c 195 195 util/u_pretty_print.c 196 196 util/u_pretty_print.h 197 + util/u_prober.c 198 + util/u_prober.h 197 199 util/u_sink.h 198 200 util/u_sink_combiner.c 199 201 util/u_sink_force_genlock.c
+69
src/xrt/auxiliary/util/u_prober.c
··· 1 + // Copyright 2019-2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Helpers for prober related code. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com> 8 + * @ingroup aux_util 9 + */ 10 + 11 + #include "xrt/xrt_prober.h" 12 + 13 + #include "u_prober.h" 14 + 15 + #include <string.h> 16 + 17 + 18 + /* 19 + * 20 + * Helpers. 21 + * 22 + */ 23 + 24 + #define ENUM_TO_STR(r) \ 25 + case r: return #r 26 + 27 + 28 + /* 29 + * 30 + * 'Exported' functions. 31 + * 32 + */ 33 + 34 + const char * 35 + u_prober_string_to_string(enum xrt_prober_string t) 36 + { 37 + switch (t) { 38 + ENUM_TO_STR(XRT_PROBER_STRING_MANUFACTURER); 39 + ENUM_TO_STR(XRT_PROBER_STRING_PRODUCT); 40 + ENUM_TO_STR(XRT_PROBER_STRING_SERIAL_NUMBER); 41 + } 42 + return "XRT_PROBER_STRING_<INVALID>"; 43 + } 44 + 45 + const char * 46 + u_prober_bus_type_to_string(enum xrt_bus_type t) 47 + { 48 + switch (t) { 49 + ENUM_TO_STR(XRT_BUS_TYPE_UNKNOWN); 50 + ENUM_TO_STR(XRT_BUS_TYPE_USB); 51 + ENUM_TO_STR(XRT_BUS_TYPE_BLUETOOTH); 52 + } 53 + return "XRT_BUS_TYPE_<INVALID>"; 54 + } 55 + 56 + bool 57 + u_prober_match_string(struct xrt_prober *xp, 58 + struct xrt_prober_device *dev, 59 + enum xrt_prober_string type, 60 + const char *to_match) 61 + { 62 + unsigned char s[256] = {0}; 63 + int len = xrt_prober_get_string_descriptor(xp, dev, type, s, sizeof(s)); 64 + if (len <= 0) { 65 + return false; 66 + } 67 + 68 + return 0 == strncmp(to_match, (const char *)s, sizeof(s)); 69 + }
+45
src/xrt/auxiliary/util/u_prober.h
··· 1 + // Copyright 2019-2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Helpers for prober related code. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup aux_util 8 + */ 9 + 10 + #pragma once 11 + 12 + #include "xrt/xrt_prober.h" 13 + 14 + 15 + #ifdef __cplusplus 16 + extern "C" { 17 + #endif 18 + 19 + 20 + /*! 21 + * Helper to match various strings of a xrt_prober_device to 22 + * @public @memberof xrt_prober 23 + */ 24 + bool 25 + u_prober_match_string(struct xrt_prober *xp, 26 + struct xrt_prober_device *dev, 27 + enum xrt_prober_string type, 28 + const char *to_match); 29 + 30 + const char * 31 + u_prober_string_to_string(enum xrt_prober_string t); 32 + 33 + const char * 34 + u_prober_bus_type_to_string(enum xrt_bus_type t); 35 + 36 + bool 37 + u_prober_match_string(struct xrt_prober *xp, 38 + struct xrt_prober_device *dev, 39 + enum xrt_prober_string type, 40 + const char *to_match); 41 + 42 + 43 + #ifdef __cplusplus 44 + } 45 + #endif