1 /*
2  * Copyright (C) 2023 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_ACCESS_OBSERVER_H
17 #define NAPI_BLUETOOTH_ACCESS_OBSERVER_H
18 
19 #include "bluetooth_host.h"
20 #include "napi_async_callback.h"
21 #include "napi_bluetooth_utils.h"
22 #include "napi_event_subscribe_module.h"
23 namespace OHOS {
24 namespace Bluetooth {
25 class NapiBluetoothAccessObserver : public BluetoothHostObserver {
26 public:
27     NapiBluetoothAccessObserver();
28     ~NapiBluetoothAccessObserver() override = default;
29 
30     void OnStateChanged(const int transport, const int status) override;
OnDiscoveryStateChanged(int status)31     void OnDiscoveryStateChanged(int status) override {};
OnDiscoveryResult(const BluetoothRemoteDevice & device,int rssi,const std::string deviceName,int deviceClass)32     void OnDiscoveryResult(
33         const BluetoothRemoteDevice &device, int rssi, const std::string deviceName, int deviceClass) override {};
OnPairRequested(const BluetoothRemoteDevice & device)34     void OnPairRequested(const BluetoothRemoteDevice &device) override {};
OnPairConfirmed(const BluetoothRemoteDevice & device,int reqType,int number)35     void OnPairConfirmed(const BluetoothRemoteDevice &device, int reqType, int number) override {};
OnScanModeChanged(int mode)36     void OnScanModeChanged(int mode) override {};
OnDeviceNameChanged(const std::string & deviceName)37     void OnDeviceNameChanged(const std::string &deviceName) override {};
OnDeviceAddrChanged(const std::string & address)38     void OnDeviceAddrChanged(const std::string &address) override {};
39 
40 private:
41     bool DealStateChange(const int transport, const int status, BluetoothState &state);
42     void EnableBt();
43     void DisableBle();
44     void GetBrStateByStatus(const int status, BluetoothState &state, bool &isCallback);
45     void GetBleStateByStatus(const int status, BluetoothState &state);
46 
47     friend class NapiAccess;
48     NapiEventSubscribeModule eventSubscribe_;
49 };
50 }  // namespace Bluetooth
51 }  // namespace OHOS
52 #endif  // NAPI_BLUETOOTH_ACCESS_OBSERVER_H
53