1 /* 2 * Copyright (C) 2021-2022 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 Graphic 18 * @{ 19 * 20 * @brief Defines a lightweight graphics system that provides basic UI and container views, 21 * including buttons, images, labels, lists, animators, scroll views, swipe views, and layouts. 22 * This system also provides the Design for X (DFX) capability to implement features such as 23 * view rendering, animation, and input event distribution. 24 * 25 * @since 1.0 26 * @version 1.0 27 */ 28 29 /** 30 * @file gatt_client_profile.h 31 * 32 * @brief Declares function of gatt client definition. 33 * 34 * @since 1.0 35 * @version 1.0 36 */ 37 #ifndef GATT_SERVER_PROFILE_H 38 #define GATT_SERVER_PROFILE_H 39 40 #include "dispatcher.h" 41 #include "gatt_database.h" 42 #include "gatt_profile_defines.h" 43 #include "gatt_server_profile_callback.h" 44 45 namespace OHOS { 46 namespace bluetooth { 47 class GattServerProfile { 48 public: 49 explicit GattServerProfile( 50 GattServerProfileCallback *pServerCallbackFunc, utility::Dispatcher *dispatcher, uint16_t maxMtu); 51 ~GattServerProfile(); 52 void Enable() const; 53 void Disable() const; 54 int AddService(Service &service) const; 55 int CheckLegalityOfServiceDefinition(Service &service) const; 56 int RemoveService(uint16_t serviceHandle) const; 57 const std::string GetDBHash() const; 58 const std::map<uint16_t, GattDatabase::Service> &GetServices() const; 59 const GattDatabase::Service *GetService(uint16_t serviceHandle) const; 60 GattDatabase::Characteristic *GetCharacteristic(uint16_t valueHandle) const; 61 const GattDatabase::Descriptor *GetDescriptor(uint16_t valueHandle) const; 62 void SetAttributeValue(uint16_t valueHandle, GattDatabase::AttributeValue &value) const; 63 Buffer *GetAttributeValue(uint16_t handle) const; 64 const std::optional<std::reference_wrapper<GattDatabase::AttributeEntity>> GetAttributeEntity( 65 uint16_t handle) const; 66 void SendNotification(uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len) const; 67 void SendIndication(uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len) const; 68 void SendReadCharacteristicValueResp( 69 uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len, int result) const; 70 void SendReadUsingCharacteristicValueResp( 71 uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len, int result) const; 72 void SendReadBlobValueResp( 73 uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len, int result) const; 74 void SendWriteCharacteristicValueResp(uint16_t connectHandle, uint16_t handle, int result) const; 75 void SendReadDescriptorResp( 76 uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len, int result) const; 77 void SendWriteDescriptorResp(uint16_t connectHandle, uint16_t handle, int result) const; 78 void SendPrepareWriteValueResp( 79 PrepareWriteParam param, const GattValue &value, size_t len, int result) const; 80 static void SendExecuteWriteValueResp(uint16_t connectHandle); 81 static int ConvertResponseErrorCode(int errorCode); 82 BT_DISALLOW_COPY_AND_ASSIGN(GattServerProfile); 83 84 private: 85 DECLARE_IMPL(); 86 }; 87 } // namespace bluetooth 88 } // namespace OHOS 89 90 #endif // GATT_SERVER_PROFILE_H 91