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 23 namespace OHOS { 24 namespace Bluetooth { 25 class NapiBluetoothBleCentralManagerCallback : public BleCentralManagerCallback { 26 public: 27 NapiBluetoothBleCentralManagerCallback() = default; 28 ~NapiBluetoothBleCentralManagerCallback() override = default; 29 30 static NapiBluetoothBleCentralManagerCallback &GetInstance(void); 31 32 void OnScanCallback(const BleScanResult &result) override; 33 void OnBleBatchScanResultsEvent(const std::vector<BleScanResult> &results) override; 34 void OnStartOrStopScanEvent(int resultCode, bool isStartScan) override; OnNotifyMsgReportFromLpDevice(const UUID & uuid,int msgType,const std::vector<uint8_t> & value)35 void OnNotifyMsgReportFromLpDevice(const UUID &uuid, int msgType, const std::vector<uint8_t> &value) override {}; 36 37 void SetNapiScanCallback(const std::shared_ptr<NapiCallback> &callback); 38 private: 39 std::mutex callbackMutex_ {}; 40 std::shared_ptr<NapiCallback> napiScanCallback_ {nullptr}; 41 void UvQueueWorkOnScanCallback(uv_work_t *work, std::shared_ptr<BleScanResult> &result); 42 void UvQueueWorkOnBleBatchScanResultsEvent(uv_work_t *work, const std::vector<BleScanResult> &results); 43 }; 44 } // namespace Bluetooth 45 } // namespace OHOS 46 #endif // NAPI_BLUETOOTH_BLE_CENTRAL_MANAGER_H 47