• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 bluetooth {
46 class GattServerProfile {
47 public:
48     explicit GattServerProfile(
49         GattServerProfileCallback *pServerCallbackFunc, utility::Dispatcher *dispatcher, uint16_t maxMtu);
50     ~GattServerProfile();
51     void Enable() const;
52     void Disable() const;
53     int AddService(Service &service) const;
54     int CheckLegalityOfServiceDefinition(Service &service) const;
55     int RemoveService(uint16_t serviceHandle) const;
56     const std::string GetDBHash() const;
57     const std::map<uint16_t, GattDatabase::Service> &GetServices() const;
58     const GattDatabase::Service *GetService(uint16_t serviceHandle) const;
59     GattDatabase::Characteristic *GetCharacteristic(uint16_t valueHandle) const;
60     const GattDatabase::Descriptor *GetDescriptor(uint16_t valueHandle) const;
61     void SetAttributeValue(uint16_t valueHandle, GattDatabase::AttributeValue &value) const;
62     Buffer *GetAttributeValue(uint16_t handle) const;
63     const std::optional<std::reference_wrapper<GattDatabase::AttributeEntity>> GetAttributeEntity(
64         uint16_t handle) const;
65     void SendNotification(uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len) const;
66     void SendIndication(uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len) const;
67     void SendReadCharacteristicValueResp(
68         uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len, int result) const;
69     void SendReadUsingCharacteristicValueResp(
70         uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len, int result) const;
71     void SendReadBlobValueResp(
72         uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len, int result) const;
73     void SendWriteCharacteristicValueResp(uint16_t connectHandle, uint16_t handle, int result) const;
74     void SendReadDescriptorResp(
75         uint16_t connectHandle, uint16_t handle, const GattValue &value, size_t len, int result) const;
76     void SendWriteDescriptorResp(uint16_t connectHandle, uint16_t handle, int result) const;
77     void SendPrepareWriteValueResp(
78         PrepareWriteParam param, const GattValue &value, size_t len, int result) const;
79     static void SendExecuteWriteValueResp(uint16_t connectHandle);
80     static int ConvertResponseErrorCode(int errorCode);
81     DISALLOW_COPY_AND_ASSIGN(GattServerProfile);
82 
83 private:
84     DECLARE_IMPL();
85 };
86 }  // namespace bluetooth
87 
88 #endif  // GATT_SERVER_PROFILE_H
89