Mstdlib-1.24.0
m_io_bluetooth.h
1/* The MIT License (MIT)
2 *
3 * Copyright (c) 2017 Monetra Technologies, LLC.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24#ifndef __M_IO_BLUETOOTH_H__
25#define __M_IO_BLUETOOTH_H__
26
27#include <mstdlib/base/m_defs.h>
28#include <mstdlib/base/m_types.h>
29#include <mstdlib/io/m_io.h>
30#include <mstdlib/io/m_event.h>
31
32__BEGIN_DECLS
33
34/*! \addtogroup m_io_bluetooth Bluetooth IO functions
35 * \ingroup m_eventio_base
36 *
37 * Bluetooth IO functions.
38 *
39 * This is a connectivity layer and uses rfcomm. Protocols,
40 * such as AVDTP, should be implemented at a layer above this one.
41 * The generic rfcomm uuid that the vast majority of devices use is
42 * 00001101-0000-1000-8000-00805f9b34fb.
43 *
44 * Supported OS:
45 * - Android
46 * - macOS
47 *
48 * @{
49 */
50
51
54
55
56/*! Create a bluetooth enumeration object.
57 *
58 * Use to determine what bluetooth devices are connected and
59 * what services are being offered. This is a
60 * list of associated devices not necessarily what's actively connected.
61 *
62 * The enumeration is based on available services. Meaning a device may
63 * be listed multiple times if it exposes multiple services.
64 *
65 * \return Bluetooth enumeration object.
66 */
68
69
70/*! Destroy a bluetooth enumeration object.
71 *
72 * \param[in] btenum Bluetooth enumeration object.
73 */
75
76
77/*! Number of bluetooth objects in the enumeration.
78 *
79 * \param[in] btenum Bluetooth enumeration object.
80 *
81 * \return Count of bluetooth devices.
82 */
84
85
86/*! Name of bluetooth device as reported by the device.
87 *
88 * \param[in] btenum Bluetooth enumeration object.
89 * \param[in] idx Index in bluetooth enumeration.
90 *
91 * \return String.
92 */
93M_API const char *M_io_bluetooth_enum_name(const M_io_bluetooth_enum_t *btenum, size_t idx);
94
95
96/*! MAC of bluetooth device.
97 *
98 * \param[in] btenum Bluetooth enumeration object.
99 * \param[in] idx Index in bluetooth enumeration.
100 *
101 * \return String.
102 */
103M_API const char *M_io_bluetooth_enum_mac(const M_io_bluetooth_enum_t *btenum, size_t idx);
104
105
106/*! Whether the device is connected.
107 *
108 * Not all systems are able to report the connected status making this function
109 * less useful than you would think.
110 *
111 * \return M_TRUE if the device is connected, otherwise M_FALSE.
112 * If it is not possible to determine the connected status this
113 * function will return M_TRUE.
114 */
115M_API M_bool M_io_bluetooth_enum_connected(const M_io_bluetooth_enum_t *btenum, size_t idx);
116
117
118/*! Name of service reported by device.
119 *
120 * \param[in] btenum Bluetooth enumeration object.
121 * \param[in] idx Index in bluetooth enumeration.
122 *
123 * \return String.
124 */
125M_API const char *M_io_bluetooth_enum_service_name(const M_io_bluetooth_enum_t *btenum, size_t idx);
126
127
128/*! Uuid of service reported by device.
129 *
130 * \param[in] btenum Bluetooth enumeration object.
131 * \param[in] idx Index in bluetooth enumeration.
132 *
133 * \return String.
134 */
135M_API const char *M_io_bluetooth_enum_service_uuid(const M_io_bluetooth_enum_t *btenum, size_t idx);
136
137
138/*! Create a bluetooth connection.
139 *
140 * \param[out] io_out io object for communication.
141 * \param[in] mac Required MAC of the device.
142 * \param[in] uuid Optional UUID of the device. For rfcomm (used by this io interface) the uuid
143 * is almost always 00001101-0000-1000-8000-00805f9b34fb unless the device is
144 * providing multiple services. Such as a device that can do multiple things like
145 * bar code scanner, and integrated printer. If not specified the generic
146 * rfcomm uuid will be used.
147 *
148 * \return Result.
149 */
150M_API M_io_error_t M_io_bluetooth_create(M_io_t **io_out, const char *mac, const char *uuid);
151
152/*! @} */
153
154__END_DECLS
155
156#endif /* __M_IO_BLUETOOTH_H__ */
void M_io_bluetooth_enum_destroy(M_io_bluetooth_enum_t *btenum)
M_bool M_io_bluetooth_enum_connected(const M_io_bluetooth_enum_t *btenum, size_t idx)
size_t M_io_bluetooth_enum_count(const M_io_bluetooth_enum_t *btenum)
const char * M_io_bluetooth_enum_service_name(const M_io_bluetooth_enum_t *btenum, size_t idx)
struct M_io_bluetooth_enum M_io_bluetooth_enum_t
Definition: m_io_bluetooth.h:53
const char * M_io_bluetooth_enum_mac(const M_io_bluetooth_enum_t *btenum, size_t idx)
M_io_error_t M_io_bluetooth_create(M_io_t **io_out, const char *mac, const char *uuid)
const char * M_io_bluetooth_enum_name(const M_io_bluetooth_enum_t *btenum, size_t idx)
M_io_bluetooth_enum_t * M_io_bluetooth_enum(void)
const char * M_io_bluetooth_enum_service_uuid(const M_io_bluetooth_enum_t *btenum, size_t idx)
enum M_io_error M_io_error_t
Definition: m_io.h:93
struct M_io M_io_t
Definition: m_io.h:59