• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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_BLE_SCANNER_H_
16 #define NAPI_BLUETOOTH_BLE_SCANNER_H_
17 
18 #include "bluetooth_ble_central_manager.h"
19 #include "napi_bluetooth_ble_central_manager_callback.h"
20 
21 namespace OHOS {
22 namespace Bluetooth {
23 
24 class NapiBleScanner {
25 public:
26     static napi_value CreateBleScanner(napi_env env, napi_callback_info info);
27     static void DefineBleScannerJSClass(napi_env env);
28     static napi_value BleScannerConstructor(napi_env env, napi_callback_info info);
29 
30     static napi_value StartScan(napi_env env, napi_callback_info info);
31     static napi_value StopScan(napi_env env, napi_callback_info info);
32     static napi_value On(napi_env env, napi_callback_info info);
33     static napi_value Off(napi_env env, napi_callback_info info);
34 
GetBleCentralManager()35     std::shared_ptr<BleCentralManager> &GetBleCentralManager()
36     {
37         return bleCentralManager_;
38     }
39 
GetCallback()40     std::shared_ptr<NapiBluetoothBleCentralManagerCallback> GetCallback()
41     {
42         return callback_;
43     }
44 
NapiBleScanner()45     NapiBleScanner()
46     {
47         callback_ = std::make_shared<NapiBluetoothBleCentralManagerCallback>(true);
48         bleCentralManager_ = std::make_shared<BleCentralManager>(callback_);
49     }
50     ~NapiBleScanner() = default;
51 
52     static thread_local napi_ref consRef_;
53 private:
54     std::shared_ptr<BleCentralManager> bleCentralManager_ = nullptr;
55     std::shared_ptr<NapiBluetoothBleCentralManagerCallback> callback_ = nullptr;
56 };
57 } // namespace Bluetooth
58 } // namespace OHOS
59 #endif /* NAPI_BLUETOOTH_BLE_SCANNER_H_ */