The open source OpenXR runtime
at main 69 lines 1.4 kB view raw
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 34const char * 35u_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 45const char * 46u_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 56bool 57u_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}