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  * @interface os_ble_device
24  * Representing a single ble notify attribute on a device.
25  *
26  * @ingroup aux_os
27  */
29 {
30  int (*read)(struct os_ble_device *ble_dev, uint8_t *data, size_t size, int milliseconds);
31 
32  void (*destroy)(struct os_ble_device *ble_dev);
33 };
34 
35 /*!
36  * Read data from the ble file descriptor, if any, from the given bledevice.
37  *
38  * If milliseconds are negative, this call blocks indefinitely, 0 polls,
39  * and positive will block for that amount of milliseconds.
40  *
41  * @ingroup aux_os
42  */
43 XRT_MAYBE_UNUSED static inline int
44 os_ble_read(struct os_ble_device *ble_dev, uint8_t *data, size_t size, int milliseconds)
45 {
46  return ble_dev->read(ble_dev, data, size, milliseconds);
47 }
48 
49 /*!
50  * Close and free the given device, does null checking and zeroing.
51  *
52  * @ingroup aux_os
53  */
54 XRT_MAYBE_UNUSED static inline void
55 os_ble_destroy(struct os_ble_device **ble_dev_ptr)
56 {
57  struct os_ble_device *ble_dev = *ble_dev_ptr;
58  if (ble_dev == NULL) {
59  return;
60  }
61 
62  ble_dev->destroy(ble_dev);
63  *ble_dev_ptr = NULL;
64 }
65 
66 #ifdef XRT_OS_LINUX
67 /*!
68  * Returns a notification endpoint from the given device uuid and char uuid.
69  *
70  * @returns Negative on failure, zero on no device found and positive if a
71  * device has been found.
72  *
73  * @ingroup aux_os
74  */
75 int
76 os_ble_notify_open(const char *dev_uuid, const char *char_uuid, struct os_ble_device **out_ble);
77 
78 /*!
79  * Returns write startpoints from the given device uuid and char uuid.
80  *
81  * @returns Negative on failure, zero on no device found and positive if a
82  * device has been found.
83  *
84  * @ingroup aux_os
85  */
86 int
87 os_ble_broadcast_write_value(const char *service_uuid, const char *char_uuid, uint8_t value);
88 #endif
89 
90 
91 #ifdef __cplusplus
92 }
93 #endif
static XRT_MAYBE_UNUSED int os_ble_read(struct os_ble_device *ble_dev, uint8_t *data, size_t size, int milliseconds)
Read data from the ble file descriptor, if any, from the given bledevice.
Definition: os_ble.h:44
int os_ble_notify_open(const char *dev_uuid, const char *char_uuid, struct os_ble_device **out_ble)
Returns a notification endpoint from the given device uuid and char uuid.
Definition: os_ble_dbus.c:1067
int os_ble_broadcast_write_value(const char *service_uuid, const char *char_uuid, uint8_t value)
Returns write startpoints from the given device uuid and char uuid.
Definition: os_ble_dbus.c:1086
static XRT_MAYBE_UNUSED void os_ble_destroy(struct os_ble_device **ble_dev_ptr)
Close and free the given device, does null checking and zeroing.
Definition: os_ble.h:55
Representing a single ble notify attribute on a device.
Definition: os_ble.h:29
Header holding common defines.
Auto detect OS and certain features.