• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_bluetooth_utils.h"
21 namespace OHOS {
22 namespace Bluetooth {
23 class NapiBluetoothAccessObserver : public BluetoothHostObserver {
24 public:
25     std::shared_ptr<BluetoothCallbackInfo> stateChangeCallback;
26     NapiBluetoothAccessObserver() = default;
27     ~NapiBluetoothAccessObserver() override = default;
28 
29     void OnStateChanged(const int transport, const int status) override;
OnDiscoveryStateChanged(int status)30     void OnDiscoveryStateChanged(int status) override {};
OnDiscoveryResult(const BluetoothRemoteDevice & device)31     void OnDiscoveryResult(const BluetoothRemoteDevice &device) override {};
OnPairRequested(const BluetoothRemoteDevice & device)32     void OnPairRequested(const BluetoothRemoteDevice &device) override {};
OnPairConfirmed(const BluetoothRemoteDevice & device,int reqType,int number)33     void OnPairConfirmed(const BluetoothRemoteDevice &device, int reqType, int number) override {};
OnScanModeChanged(int mode)34     void OnScanModeChanged(int mode) override {};
OnDeviceNameChanged(const std::string & deviceName)35     void OnDeviceNameChanged(const std::string &deviceName) override {};
OnDeviceAddrChanged(const std::string & address)36     void OnDeviceAddrChanged(const std::string &address) override {};
37 
38 private:
39     bool DealStateChange(const int transport, const int status, BluetoothState &state);
40     void UvQueueWorkOnStateChanged(uv_work_t *work, BluetoothState &state);
41     void EnableBt();
42     void DisableBle();
43     void GetBrStateByStauts(const int status, BluetoothState &state, bool &isCallback);
44     void GetBleStateByStauts(const int status, BluetoothState &state);
45 };
46 }  // namespace Bluetooth
47 }  // namespace OHOS
48 #endif  // NAPI_BLUETOOTH_ACCESS_OBSERVER_H
49