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 OnConnectionStateUpdate(const BluetoothRemoteDevice &device, int state) override; OnServiceAdded(GattService service,int ret)41 void OnServiceAdded(GattService service, int ret) override {} 42 void OnCharacteristicReadRequest(const BluetoothRemoteDevice &device, 43 GattCharacteristic &characteristic, int requestId) override; 44 void OnCharacteristicWriteRequest(const BluetoothRemoteDevice &device, 45 GattCharacteristic &characteristic, int requestId) override; 46 void OnDescriptorReadRequest(const BluetoothRemoteDevice &device, 47 GattDescriptor &descriptor, int requestId) override; 48 void OnDescriptorWriteRequest(const BluetoothRemoteDevice &device, 49 GattDescriptor &descriptor, int requestId) override; 50 void OnMtuUpdate(const BluetoothRemoteDevice &device, int mtu) override; 51 void OnNotificationCharacteristicChanged(const BluetoothRemoteDevice &device, 52 int result) override; OnConnectionParameterChanged(const BluetoothRemoteDevice & device,int interval,int latency,int timeout,int status)53 void OnConnectionParameterChanged(const BluetoothRemoteDevice &device, 54 int interval, int latency, int timeout, int status) override {} 55 56 NapiAsyncWorkMap asyncWorkMap_ {}; 57 NapiEventSubscribeModule eventSubscribe_; 58 NapiGattServerCallback(); 59 ~NapiGattServerCallback() override = default; 60 private: 61 }; 62 } // namespace Bluetooth 63 } // namespace OHOS 64 #endif /* NAPI_BLUETOOTH_GATT_SERVER_CALLBACK_H_ */