Mistake on this page?
Report an issue in GitHub or email us
gatt/GattService.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_GATT_SERVICE_H__
20 #define MBED_GATT_SERVICE_H__
21 
22 #include "ble/common/UUID.h"
23 #include "ble/gatt/GattCharacteristic.h"
24 
25 /**
26  * @addtogroup ble
27  * @{
28  * @addtogroup gatt
29  * @{
30  * @addtogroup server
31  * @{
32  */
33 
34 /**
35  * Representation of a GattServer service.
36  *
37  * A service is a cohesive collection of characteristics. It is identified by a
38  * UUID and starts at a specific handle of its GattServer.
39  */
40 class GattService {
41 public:
42  enum {
43  /**
44  * UUID of the Alert Notification service.
45  */
47 
48  /**
49  * UUID of the Battery service.
50  */
52 
53  /**
54  * UUID of the Blood Pressure service.
55  */
57 
58  /**
59  * UUID of the Current Time service.
60  */
62 
63  /**
64  * UUID of the Cycling Speed and Cadence (CSC) service.
65  */
67 
68  /**
69  * UUID of the Device Information Service (DIS).
70  */
72 
73  /**
74  * UUID of the environmental service.
75  */
77 
78  /**
79  * UUID of the Glucose service.
80  */
82 
83  /**
84  * UUID of the health thermometer.
85  */
87 
88  /**
89  * UUID of the Heart Rate service.
90  */
92 
93  /**
94  * UUID of the Human Interface Device (HID) service.
95  */
97 
98  /**
99  * UUID of the Immediate Alert service.
100  */
102 
103  /**
104  * UUID of the Link Loss service.
105  */
107 
108  /**
109  * UUID of the Next DST change service.
110  */
112 
113  /**
114  * UUID of the Phone Alert Status service.
115  */
117 
118  /**
119  * UUID of the Reference Time Update service.
120  */
122 
123  /**
124  * UUID of the Running Speed and Cadence (RSC) service.
125  */
127 
128  /**
129  * UUID of the Scan Parameter service.
130  */
132 
133  /**
134  * UUID of the TX power service.
135  */
137  };
138 
139 public:
140  /**
141  * Construct a GattService.
142  *
143  * @param[in] uuid The UUID assigned to this service.
144  * @param[in] characteristics A pointer to the array of characteristics that
145  * belongs to the service.
146  * @param[in] numCharacteristics The number of characteristics.
147  *
148  * @attention The characteristics of the service must remain valid while the
149  * GattServer uses the service.
150  */
152  const UUID &uuid,
153  GattCharacteristic *characteristics[],
154  unsigned numCharacteristics
155  ) :
156  _primaryServiceID(uuid),
157  _characteristicCount(numCharacteristics),
158  _characteristics(characteristics),
159  _handle(0) {
160  }
161 
162  /**
163  * Get this service's UUID.
164  *
165  * @return A reference to the service's UUID.
166  */
167  const UUID &getUUID() const
168  {
169  return _primaryServiceID;
170  }
171 
172  /**
173  * Get the handle of the service declaration attribute in the ATT table.
174  *
175  * @return The service's handle.
176  */
177  uint16_t getHandle() const
178  {
179  return _handle;
180  }
181 
182  /**
183  * Get the total number of characteristics within this service.
184  *
185  * @return The total number of characteristics within this service.
186  */
187  uint8_t getCharacteristicCount() const
188  {
189  return _characteristicCount;
190  }
191 
192  /**
193  * Set the handle of the service declaration attribute in the ATT table.
194  *
195  * @attention Application code must not use this API.
196  *
197  * @param[in] handle The service's handle.
198  */
199  void setHandle(uint16_t handle)
200  {
201  _handle = handle;
202  }
203 
204  /**
205  * Get this service's characteristic at a specific index.
206  *
207  * @param[in] index The index of the characteristic.
208  *
209  * @return A pointer to the characteristic at index @p index.
210  */
212  {
213  if (index >= _characteristicCount) {
214  return nullptr;
215  }
216 
217  return _characteristics[index];
218  }
219 
220 private:
221  /**
222  * This service's UUID.
223  */
224  UUID _primaryServiceID;
225 
226  /**
227  * Total number of characteristics within this service.
228  */
229  uint8_t _characteristicCount;
230 
231  /**
232  * An array with pointers to the characteristics added to this service.
233  */
234  GattCharacteristic **_characteristics;
235 
236  /**
237  * Handle of the service declaration attribute in the ATT table.
238  *
239  * @note The underlying BLE stack generally assigns this handle when the
240  * service is added to the ATT table.
241  */
242  uint16_t _handle;
243 };
244 
245 /**
246  * @}
247  * @}
248  * @}
249  */
250 
251 #endif /* ifndef MBED_GATT_SERVICE_H__ */
UUID of the Immediate Alert service.
const UUID & getUUID() const
Get this service's UUID.
UUID of the Human Interface Device (HID) service.
UUID of the TX power service.
UUID of the health thermometer.
UUID of the Cycling Speed and Cadence (CSC) service.
UUID of the Device Information Service (DIS).
UUID of the Blood Pressure service.
Representation of a Universally Unique Identifier (UUID).
Definition: common/UUID.h:76
UUID of the Alert Notification service.
GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics)
Construct a GattService.
GattCharacteristic * getCharacteristic(uint8_t index)
Get this service's characteristic at a specific index.
UUID of the Running Speed and Cadence (RSC) service.
UUID of the Glucose service.
Representation of a GattServer characteristic.
uint8_t getCharacteristicCount() const
Get the total number of characteristics within this service.
uint16_t getHandle() const
Get the handle of the service declaration attribute in the ATT table.
UUID of the Heart Rate service.
UUID of the Scan Parameter service.
UUID of the Next DST change service.
UUID of the Phone Alert Status service.
UUID of the Reference Time Update service.
UUID of the environmental service.
Representation of a GattServer service.
UUID of the Link Loss service.
UUID of the Battery service.
void setHandle(uint16_t handle)
Set the handle of the service declaration attribute in the ATT table.
UUID of the Current Time service.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.