• 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 #include "napi_bluetooth_ble_utils.h"
21 #include "napi_async_callback.h"
22 #include "napi_event_subscribe_module.h"
23 
24 namespace OHOS {
25 namespace Bluetooth {
26 const char * const STR_BT_GATT_SERVER_CALLBACK_CHARACTERISTIC_READ = "characteristicRead";
27 const char * const STR_BT_GATT_SERVER_CALLBACK_CHARACTERISTIC_WRITE = "characteristicWrite";
28 const char * const STR_BT_GATT_SERVER_CALLBACK_DESCRIPTOR_READ = "descriptorRead";
29 const char * const STR_BT_GATT_SERVER_CALLBACK_DESCRIPTOR_WRITE = "descriptorWrite";
30 
31 #ifdef BLUETOOTH_API_SINCE_10
32 const char * const STR_BT_GATT_SERVER_CALLBACK_CONNECT_STATE_CHANGE = "connectionStateChange";
33 #else
34 const char * const STR_BT_GATT_SERVER_CALLBACK_CONNECT_STATE_CHANGE = "connectStateChange";
35 #endif
36 const char * const STR_BT_GATT_SERVER_CALLBACK_MTU_CHANGE = "BLEMtuChange";
37 
38 class NapiGattServerCallback : public GattServerCallback {
39 public:
40     void OnConnectionStateUpdateWithReason(
41         const BluetoothRemoteDevice &device, int state, int disconnectReason) override;
OnServiceAdded(GattService service,int ret)42     void OnServiceAdded(GattService service, int ret) override {}
43     void OnCharacteristicReadRequest(const BluetoothRemoteDevice &device,
44         GattCharacteristic &characteristic, int requestId) override;
45     void OnCharacteristicWriteRequest(const BluetoothRemoteDevice &device,
46         GattCharacteristic &characteristic, int requestId) override;
47     void OnDescriptorReadRequest(const BluetoothRemoteDevice &device,
48         GattDescriptor &descriptor, int requestId) override;
49     void OnDescriptorWriteRequest(const BluetoothRemoteDevice &device,
50         GattDescriptor &descriptor, int requestId) override;
51     void OnMtuUpdate(const BluetoothRemoteDevice &device, int mtu) override;
52     void OnNotificationCharacteristicChanged(const BluetoothRemoteDevice &device,
53         int result) override;
OnConnectionParameterChanged(const BluetoothRemoteDevice & device,int interval,int latency,int timeout,int status)54     void OnConnectionParameterChanged(const BluetoothRemoteDevice &device,
55         int interval, int latency, int timeout, int status) override {}
56 
57     NapiAsyncWorkMap asyncWorkMap_ {};
58     NapiEventSubscribeModule eventSubscribe_;
59     NapiGattServerCallback();
60     ~NapiGattServerCallback() override = default;
61 private:
62 };
63 }  // namespace Bluetooth
64 }  // namespace OHOS
65 #endif /* NAPI_BLUETOOTH_GATT_SERVER_CALLBACK_H_ */