• 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_SERVER_CALLBACK_H_
16 #define NAPI_BLUETOOTH_GATT_SERVER_CALLBACK_H_
17 
18 #include "bluetooth_gatt_server.h"
19 #include "napi_bluetooth_utils.h"
20 
21 namespace OHOS {
22 namespace Bluetooth {
23 const std::string STR_BT_GATT_SERVER_CALLBACK_CHARACTERISTIC_READ = "characteristicRead";
24 const std::string STR_BT_GATT_SERVER_CALLBACK_CHARACTERISTIC_WRITE = "characteristicWrite";
25 const std::string STR_BT_GATT_SERVER_CALLBACK_DESCRIPTOR_READ = "descriptorRead";
26 const std::string STR_BT_GATT_SERVER_CALLBACK_DESCRIPTOR_WRITE = "descriptorWrite";
27 const std::string STR_BT_GATT_SERVER_CALLBACK_CONNECT_STATE_CHANGE = "connectStateChange";
28 
29 class NapiGattServerCallback : public GattServerCallback {
30 public:
31     void OnConnectionStateUpdate(const BluetoothRemoteDevice &device, int state) override;
OnServiceAdded(GattService * Service,int ret)32     void OnServiceAdded(GattService *Service, int ret) override {}
33     void OnCharacteristicReadRequest(const BluetoothRemoteDevice &device,
34         GattCharacteristic &characteristic, int requestId) override;
35     void OnCharacteristicWriteRequest(const BluetoothRemoteDevice &device,
36         GattCharacteristic &characteristic, int requestId) override;
37     void OnDescriptorReadRequest(const BluetoothRemoteDevice &device,
38         GattDescriptor &descriptor, int requestId) override;
39     void OnDescriptorWriteRequest(const BluetoothRemoteDevice &device,
40         GattDescriptor &descriptor, int requestId) override;
OnMtuUpdate(const BluetoothRemoteDevice & device,int mtu)41     void OnMtuUpdate(const BluetoothRemoteDevice &device, int mtu) override {}
OnNotificationCharacteristicChanged(const BluetoothRemoteDevice & device,int result)42     void OnNotificationCharacteristicChanged(const BluetoothRemoteDevice &device,
43         int result) override {}
OnConnectionParameterChanged(const BluetoothRemoteDevice & device,int interval,int latency,int timeout,int status)44     void OnConnectionParameterChanged(const BluetoothRemoteDevice &device,
45         int interval, int latency, int timeout, int status) override {}
46 
SetCallbackInfo(const std::string & type,std::shared_ptr<BluetoothCallbackInfo> callbackInfo)47     void SetCallbackInfo(const std::string &type, std::shared_ptr<BluetoothCallbackInfo> callbackInfo)
48     {
49         HILOGI("enter, type: %{public}s", type.c_str());
50         callbackInfos_[type] = callbackInfo;
51     }
52 
53     NapiGattServerCallback() = default;
54     ~NapiGattServerCallback() override = default;
55 
56 private:
57     std::map<std::string, std::shared_ptr<BluetoothCallbackInfo>> callbackInfos_ = {};
58 };
59 }  // namespace Bluetooth
60 }  // namespace OHOS
61 #endif /* NAPI_BLUETOOTH_GATT_SERVER_CALLBACK_H_ */