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 <shared_mutex> 19 #include "bluetooth_gatt_client.h" 20 #include "napi_async_callback.h" 21 #include "napi_bluetooth_utils.h" 22 #include "napi_bluetooth_ble_utils.h" 23 #include "napi_event_subscribe_module.h" 24 25 namespace OHOS { 26 namespace Bluetooth { 27 28 const char * const STR_BT_GATT_CLIENT_CALLBACK_BLE_CHARACTERISTIC_CHANGE = "BLECharacteristicChange"; 29 const char * const STR_BT_GATT_CLIENT_CALLBACK_BLE_CONNECTIION_STATE_CHANGE = "BLEConnectionStateChange"; 30 const char * const STR_BT_GATT_CLIENT_CALLBACK_BLE_MTU_CHANGE = "BLEMtuChange"; 31 class NapiGattClient; 32 33 class NapiGattClientCallback : public GattClientCallback { 34 public: 35 void OnConnectionStateChanged(int connectionState, int ret) override; 36 void OnCharacteristicChanged(const GattCharacteristic &characteristic) override; 37 void OnCharacteristicReadResult(const GattCharacteristic &characteristic, int ret) override; 38 void OnCharacteristicWriteResult(const GattCharacteristic &characteristic, int ret) override; 39 void OnDescriptorReadResult(const GattDescriptor &descriptor, int ret) override; 40 void OnDescriptorWriteResult(const GattDescriptor &descriptor, int ret) override; 41 void OnMtuUpdate(int mtu, int ret) override; 42 void OnServicesDiscovered(int status) override; OnConnectionParameterChanged(int interval,int latency,int timeout,int status)43 void OnConnectionParameterChanged(int interval, int latency, int timeout, int status) override {} 44 void OnSetNotifyCharacteristic(const GattCharacteristic &characteristic, int status) override; 45 void OnReadRemoteRssiValueResult(int rssi, int status) override; 46 47 NapiGattClientCallback(); 48 ~NapiGattClientCallback() override = default; 49 50 NapiAsyncWorkMap asyncWorkMap_ {}; 51 private: 52 friend class NapiGattClient; 53 NapiEventSubscribeModule eventSubscribe_; 54 55 std::string deviceAddr_ = INVALID_MAC_ADDRESS; 56 }; 57 } // namespace Bluetooth 58 } // namespace OHOS 59 #endif /* NAPI_BLUETOOTH_GATT_CLIENT_CALLBACK_H_ */