Monado OpenXR Runtime
os_ble.h
Go to the documentation of this file.
1 // Copyright 2019-2020, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Wrapper around OS native BLE functions.
6  * @author Pete Black <pete.black@collabora.com>
7  * @author Jakob Bornecrantz <jakob@collabora.com>
8  *
9  * @ingroup aux_os
10  */
11 
12 #pragma once
13 
14 #include "xrt/xrt_config_os.h"
15 #include "xrt/xrt_compiler.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 
22 /*!
23  * Representing a single ble notify attribute on a device.
24  *
25  * @ingroup aux_os
26  */
28 {
29  int (*read)(struct os_ble_device *ble_dev,
30  uint8_t *data,
31  size_t size,
32  int milliseconds);
33 
34  void (*destroy)(struct os_ble_device *ble_dev);
35 };
36 
37 /*!
38  * Read data from the ble file descriptor, if any, from the given bledevice.
39  *
40  * If milliseconds are negative, this call blocks indefinitely, 0 polls,
41  * and positive will block for that amount of milliseconds.
42  *
43  * @ingroup aux_os
44  */
45 XRT_MAYBE_UNUSED static inline int
46 os_ble_read(struct os_ble_device *ble_dev,
47  uint8_t *data,
48  size_t size,
49  int milliseconds)
50 {
51  return ble_dev->read(ble_dev, data, size, milliseconds);
52 }
53 
54 /*!
55  * Close and free the given device, does null checking and zeroing.
56  *
57  * @ingroup aux_os
58  */
59 XRT_MAYBE_UNUSED static inline void
60 os_ble_destroy(struct os_ble_device **ble_dev_ptr)
61 {
62  struct os_ble_device *ble_dev = *ble_dev_ptr;
63  if (ble_dev == NULL) {
64  return;
65  }
66 
67  ble_dev->destroy(ble_dev);
68  *ble_dev_ptr = NULL;
69 }
70 
71 #ifdef XRT_OS_LINUX
72 /*!
73  * Open the given mac and path to device endpoint (Currently Linux/BlueZ
74  * specific).
75  *
76  * @returns Negative on failure, zero on no device found and positive if a
77  * device has been found.
78  *
79  * @ingroup aux_os
80  */
81 int
82 os_ble_notify_open(const char *dev_uuid,
83  const char *char_uuid,
84  struct os_ble_device **out_ble);
85 #endif
86 
87 
88 #ifdef __cplusplus
89 }
90 #endif
Auto detect OS and certain features.
Representing a single ble notify attribute on a device.
Definition: os_ble.h:27
Header holding common defines.