1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup Bluetooth 18 * @{ 19 * 20 * @brief Defines a bluetooth system that provides basic bluetooth connection and profile functions, 21 * including A2DP, AVRCP, BLE, GATT, HFP, MAP, PBAP, and SPP, etc. 22 * 23 * @since 6 24 * 25 */ 26 27 /** 28 * @file bluetooth_gatt_service.h 29 * 30 * @brief gatt service interface. 31 * 32 * @since 6 33 * 34 */ 35 36 #ifndef BLUETOOTH_GATT_SERVICE_H 37 #define BLUETOOTH_GATT_SERVICE_H 38 39 #include "bluetooth_gatt_characteristic.h" 40 41 namespace OHOS { 42 namespace Bluetooth { 43 /** A GATT-based Service type. 44 * Define GATT-based Service types. 45 */ 46 enum class GattServiceType : int { 47 PRIMARY, /**< primary service */ 48 SECONDARY, /**< secondary service */ 49 }; 50 51 /** 52 * @brief Class for Gatt Service API. 53 * 54 * @since 6 55 * 56 */ 57 class BLUETOOTH_API GattService { 58 public: 59 /** 60 * @brief The function to delete constructor of GattService. 61 * 62 * @since 6 63 * 64 */ 65 GattService() = delete; 66 /** 67 * @brief A constructor of GattService. 68 * 69 * @param uuid UUID of service. 70 * @param type Type of service. 71 * @since 6 72 * 73 */ 74 GattService(const UUID &uuid, const GattServiceType type); 75 /** 76 * @brief A constructor of GattService. 77 * 78 * @param uuid UUID of service. 79 * @param handle Handle of service. 80 * @param endHandle EndHandle of service. 81 * @param type Type of service. 82 * @since 6 83 * 84 */ 85 GattService(const UUID &uuid, uint16_t handle, uint16_t endHandle, const GattServiceType type); 86 87 /** 88 * @brief The function to add characteristic. 89 * 90 * @param characteristic Characteristic object to add. 91 * @since 6 92 * 93 */ 94 void AddCharacteristic(const GattCharacteristic &characteristic); 95 /** 96 * @brief The function to add include service. 97 * 98 * @param characteristic Service object to add. 99 * @since 6 100 * 101 */ 102 void AddService(GattService &service); 103 /** 104 * @brief The function to get characteristic by UUID. 105 * 106 * @param uuid UUID of characteristic. 107 * @return characteristic. 108 * @since 6 109 * 110 */ 111 GattCharacteristic *GetCharacteristic(const UUID &uuid); 112 /** 113 * @brief The function to get characteristic by characteristic value handle. 114 * 115 * @param handle handle of characteristic value. 116 * @return characteristic. 117 * @since 16 118 * 119 */ 120 GattCharacteristic *GetCharacteristic(const uint16_t handle); 121 /** 122 * @brief The function to get all characteristics. 123 * 124 * @return list of characteristics. 125 * @since 6 126 * 127 */ 128 std::vector<GattCharacteristic> &GetCharacteristics(); 129 /** 130 * @brief The function to get include services. 131 * 132 * @return list of include services. 133 * @since 6 134 * 135 */ 136 const std::vector<std::reference_wrapper<GattService>> &GetIncludedServices(); 137 /** 138 * @brief The function to get service's handle. 139 * 140 * @return handle. 141 * @since 6 142 * 143 */ 144 uint16_t GetHandle() const; 145 /** 146 * @brief The function to get service's type. 147 * 148 * @return bool primary or not. 149 * @since 6 150 * 151 */ 152 bool IsPrimary() const; 153 /** 154 * @brief The function to get service's UUID. 155 * 156 * @return UUID. 157 * @since 6 158 * 159 */ 160 const UUID &GetUuid() const; 161 162 GattService(const GattService &); 163 GattService &operator=(const GattService &) = default; 164 165 GattService(GattService &&); 166 GattService &operator=(GattService &&) = default; 167 168 private: 169 /** 170 * @brief The handle of service. 171 * 172 * @since 6 173 * 174 */ 175 uint16_t handle_; 176 /** 177 * @brief The endHandle of service. 178 * 179 * @since 6 180 * 181 */ 182 uint16_t endHandle_; 183 /** 184 * @brief The type of service. 185 * 186 * @since 6 187 * 188 */ 189 GattServiceType serviceType_; 190 /** 191 * @brief The list of current service's include services. 192 * 193 * @since 6 194 * 195 */ 196 std::vector<std::reference_wrapper<GattService>> includeServices_; 197 /** 198 * @brief The characteristics of service. 199 * 200 * @since 6 201 * 202 */ 203 std::vector<GattCharacteristic> characteristics_; 204 /** 205 * @brief The UUID of service. 206 * 207 * @since 6 208 * 209 */ 210 UUID uuid_; 211 }; 212 } // namespace Bluetooth 213 } // namespace OHOS 214 #endif // BLUETOOTH_GATT_SERVICE_H 215