Mbed OS Reference
Loading...
Searching...
No Matches
gatt/DiscoveredService.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2006-2020 ARM Limited
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef MBED_DISCOVERED_SERVICE_H__
20#define MBED_DISCOVERED_SERVICE_H__
21
22#include "ble/common/UUID.h"
23#include "ble/gatt/GattAttribute.h"
24
25/**
26 * @addtogroup ble
27 * @{
28 * @addtogroup gatt
29 * @{
30 * @addtogroup client
31 * @{
32 */
33
34/**
35 * Representation of a GATT service discovered.
36 *
37 * The discovery procedure discovers GATT Services are discovered on distant
38 * GATT servers, which can be initiated by calling
39 * GattClient::launchServiceDiscovery() or GattClient::discoverServices(). The
40 * discovery process passes instances of this class to the callback handling
41 * service discovered.
42 *
43 * Discovered services are characterized by the UUID of the service discovered
44 * and the range of the GATT attributes belonging to the service.
45 *
46 * The UUID can be queried by calling getUUID() while the begining of the
47 * attribute range can be obtained through getStartHandle() and the end of the
48 * attribute range with a call to getEndHandle().
49 *
50 * The characteristics composing the service may be discovered by the function
51 * GattClient::launchServiceDiscovery().
52 */
54public:
55 /**
56 * Get the UUID of the discovered service.
57 *
58 * @return A reference to the UUID of the discovered service.
59 */
60 const UUID &getUUID() const
61 {
62 return uuid;
63 }
64
65 /**
66 * Get the start handle of the discovered service in the peer's GATT server.
67 *
68 * @return A reference to the start handle.
69 */
71 {
72 return startHandle;
73 }
74
75 /**
76 * Get the end handle of the discovered service in the peer's GATT server.
77 *
78 * @return A reference to the end handle.
79 */
81 {
82 return endHandle;
83 }
84
85public:
86 /**
87 * Construct a DiscoveredService instance.
88 *
89 * @attention This API is not meant to be used publicly. It is meant to be
90 * used by internal APIs of Mbed BLE.
91 */
93 uuid(UUID::ShortUUIDBytes_t(0)),
94 startHandle(GattAttribute::INVALID_HANDLE),
95 endHandle(GattAttribute::INVALID_HANDLE) {
96 }
97
98 DiscoveredService(const DiscoveredService &) = delete;
99 DiscoveredService operator=(const DiscoveredService &) = delete;
100
101 /**
102 * Set information about the discovered service.
103 *
104 * @attention This API is not meant to be used publicly. It is meant to be
105 * used by internal APIs of Mbed BLE.
106 *
107 * @param[in] uuidIn The UUID of the discovered service.
108 * @param[in] startHandleIn The start handle of the discovered service in
109 * the peer's GATT server.
110 * @param[in] endHandleIn The end handle of the discovered service in the
111 * peer's GATT server.
112 */
113 void setup(
114 const UUID& uuidIn,
115 GattAttribute::Handle_t startHandleIn,
116 GattAttribute::Handle_t endHandleIn
117 ) {
118 uuid = uuidIn;
119 startHandle = startHandleIn;
120 endHandle = endHandleIn;
121 }
122
123 /**
124 * Set the start and end handle of the discovered service.
125 *
126 * @attention This API is not meant to be used publicly. It is meant to be
127 * used by internal APIs of Mbed BLE.
128 *
129 * @param[in] startHandleIn The start handle of the discovered service in
130 * the peer's GATT server.
131 * @param[in] endHandleIn The end handle of the discovered service in the
132 * peer's GATT server.
133 */
134 void setup(
135 GattAttribute::Handle_t startHandleIn,
136 GattAttribute::Handle_t endHandleIn
137 ) {
138 startHandle = startHandleIn;
139 endHandle = endHandleIn;
140 }
141
142 /**
143 * Set the long UUID of the discovered service.
144 *
145 * @attention This API is not meant to be used publicly. It is meant to be
146 * used by internal APIs of Mbed BLE.
147 *
148 * @param[in] longUUID The bytes composing the long UUID of this discovered
149 * service.
150 * @param[in] order The byte ordering of @p longUUID.
151 */
153 UUID::LongUUIDBytes_t longUUID,
155 ) {
156 uuid.setupLong(longUUID, order);
157 }
158
159private:
160 /**
161 * UUID of the service.
162 */
163 UUID uuid;
164
165 /**
166 * Begining of the Service Handle Range.
167 */
168 GattAttribute::Handle_t startHandle;
169
170 /**
171 * Service Handle Range.
172 */
173 GattAttribute::Handle_t endHandle;
174};
175
176/**
177 * @}
178 * @}
179 * @}
180 */
181
182#endif /* MBED_DISCOVERED_SERVICE_H__ */
Representation of a GATT service discovered.
DiscoveredService()
Construct a DiscoveredService instance.
const GattAttribute::Handle_t & getEndHandle() const
Get the end handle of the discovered service in the peer's GATT server.
void setupLongUUID(UUID::LongUUIDBytes_t longUUID, UUID::ByteOrder_t order=UUID::MSB)
Set the long UUID of the discovered service.
void setup(const UUID &uuidIn, GattAttribute::Handle_t startHandleIn, GattAttribute::Handle_t endHandleIn)
Set information about the discovered service.
void setup(GattAttribute::Handle_t startHandleIn, GattAttribute::Handle_t endHandleIn)
Set the start and end handle of the discovered service.
const GattAttribute::Handle_t & getStartHandle() const
Get the start handle of the discovered service in the peer's GATT server.
const UUID & getUUID() const
Get the UUID of the discovered service.
Representation of a GattServer attribute.
ble::attribute_handle_t Handle_t
Representation of an attribute handle.
Representation of a Universally Unique Identifier (UUID).
Definition: common/UUID.h:76
void setupLong(const LongUUIDBytes_t longUUID, ByteOrder_t order=UUID::MSB)
Replace existing value with a 128-bit UUID.
Definition: common/UUID.h:264
uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID]
Type for a 128-bit UUID.
Definition: common/UUID.h:124
ByteOrder_t
Enumeration of byte ordering.
Definition: common/UUID.h:99
@ MSB
Most significant byte first (at the smallest address).
Definition: common/UUID.h:103