1 /* 2 * Copyright (C) 2021-2022 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 16 #ifndef NAPI_BLUETOOTH_BLE_CENTRAL_MANAGER_H 17 #define NAPI_BLUETOOTH_BLE_CENTRAL_MANAGER_H 18 19 #include "bluetooth_ble_central_manager.h" 20 #include "napi_async_callback.h" 21 #include "napi_bluetooth_ble_utils.h" 22 #include "napi_event_subscribe_module.h" 23 24 namespace OHOS { 25 namespace Bluetooth { 26 class NapiBluetoothBleCentralManagerCallback : public BleCentralManagerCallback { 27 public: 28 NapiBluetoothBleCentralManagerCallback(bool isLatestNapiBleScannerObj); 29 ~NapiBluetoothBleCentralManagerCallback() override = default; 30 31 static NapiBluetoothBleCentralManagerCallback &GetInstance(void); 32 33 void OnScanCallback(const BleScanResult &result) override; 34 void OnFoundOrLostCallback(const BleScanResult &result, uint8_t callbackType) override; 35 void OnBleBatchScanResultsEvent(const std::vector<BleScanResult> &results) override; 36 void OnStartOrStopScanEvent(int resultCode, bool isStartScan) override; OnNotifyMsgReportFromLpDevice(const UUID & uuid,int msgType,const std::vector<uint8_t> & value)37 void OnNotifyMsgReportFromLpDevice(const UUID &uuid, int msgType, const std::vector<uint8_t> &value) override {}; 38 39 void ConvertScanReportType(ScanReportType &scanReportType, uint8_t callbackType); 40 NapiEventSubscribeModule eventSubscribe_; 41 NapiAsyncWorkMap asyncWorkMap_ {}; 42 bool isLatestNapiBleScannerObj_ = false; 43 44 private: 45 void UvQueueWorkOnScanCallback(uv_work_t *work, std::shared_ptr<BleScanResult> &result); 46 void UvQueueWorkOnBleBatchScanResultsEvent(uv_work_t *work, const std::vector<BleScanResult> &results); 47 }; 48 } // namespace Bluetooth 49 } // namespace OHOS 50 #endif // NAPI_BLUETOOTH_BLE_CENTRAL_MANAGER_H 51