• 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 #ifndef NAPI_BLUETOOTH_GATT_CLIENT_CALLBACK_H_
16 #define NAPI_BLUETOOTH_GATT_CLIENT_CALLBACK_H_
17 
18 #include "bluetooth_gatt_client.h"
19 #include "napi_bluetooth_utils.h"
20 
21 namespace OHOS {
22 namespace Bluetooth {
23 const std::string STR_BT_GATT_CLIENT_CALLBACK_BLE_CHARACTERISTIC_CHANGE = "BLECharacteristicChange";
24 const std::string STR_BT_GATT_CLIENT_CALLBACK_BLE_CONNECTIION_STATE_CHANGE = "BLEConnectionStateChange";
25 class NapiGattClient;
26 
27 class NapiGattClientCallback : public GattClientCallback {
28 public:
29     void OnConnectionStateChanged(int connectionState, int ret) override;
30     void OnCharacteristicChanged(const GattCharacteristic &characteristic) override;
31     void OnCharacteristicReadResult(const GattCharacteristic &characteristic, int ret)  override;
OnCharacteristicWriteResult(const GattCharacteristic & characteristic,int ret)32     void OnCharacteristicWriteResult(const GattCharacteristic &characteristic, int ret) override {}
33     void OnDescriptorReadResult(const GattDescriptor &descriptor, int ret) override;
OnDescriptorWriteResult(const GattDescriptor & descriptor,int ret)34     void OnDescriptorWriteResult(const GattDescriptor &descriptor, int ret) override {}
OnMtuUpdate(int mtu,int ret)35     void OnMtuUpdate(int mtu, int ret) override {}
36     void OnServicesDiscovered(int status) override;
OnConnectionParameterChanged(int interval,int latency,int timeout,int status)37     void OnConnectionParameterChanged(int interval, int latency, int timeout, int status) override {}
OnSetNotifyCharacteristic(int status)38     void OnSetNotifyCharacteristic(int status) override {}
39 
SetCallbackInfo(const std::string & type,std::shared_ptr<BluetoothCallbackInfo> callbackInfo)40     void SetCallbackInfo(const std::string &type, std::shared_ptr<BluetoothCallbackInfo> callbackInfo)
41     {
42         callbackInfos_[type] = callbackInfo;
43     }
SetClient(NapiGattClient * client)44     void SetClient(NapiGattClient *client)
45     {
46         client_ = client;
47     }
48     NapiGattClientCallback() = default;
49     virtual ~NapiGattClientCallback() = default;
50 
51 private:
52     std::map<std::string, std::shared_ptr<BluetoothCallbackInfo>> callbackInfos_ = {};
53     NapiGattClient *client_ = nullptr;
54 };
55 }  // namespace Bluetooth
56 }  // namespace OHOS
57 #endif /* NAPI_BLUETOOTH_GATT_CLIENT_CALLBACK_H_ */