• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <uv.h>
16 #include "bluetooth_utils.h"
17 #include "napi_bluetooth_hfp_hf_observer.h"
18 #include "napi_bluetooth_event.h"
19 #include "napi_event_subscribe_module.h"
20 
21 namespace OHOS {
22 namespace Bluetooth {
NapiHandsFreeUnitObserver()23 NapiHandsFreeUnitObserver::NapiHandsFreeUnitObserver()
24     : eventSubscribe_({STR_BT_HANDS_FREE_UNIT_OBSERVER_CONNECTION_STATE_CHANGE,
25         STR_BT_HANDS_FREE_UNIT_OBSERVER_SCO_STATE_CHANGE},
26         BT_MODULE_NAME)
27 {}
28 
OnConnectionStateChanged(const BluetoothRemoteDevice & device,int state,int cause)29 void NapiHandsFreeUnitObserver::OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state, int cause)
30 {
31     HILOGD("enter, remote device address: %{public}s, state: %{public}d, cause: %{public}d",
32         GET_ENCRYPT_ADDR(device), state, cause);
33     auto nativeObject = std::make_shared<NapiNativeStateChangeParam>(device.GetDeviceAddr(), state, cause);
34     eventSubscribe_.PublishEvent(STR_BT_HANDS_FREE_UNIT_OBSERVER_CONNECTION_STATE_CHANGE, nativeObject);
35 }
36 
OnScoStateChanged(const BluetoothRemoteDevice & device,int state)37 void NapiHandsFreeUnitObserver::OnScoStateChanged(const BluetoothRemoteDevice &device, int state)
38 {
39     HILOGI("enter, remote device address: %{public}s, state: %{public}d", GET_ENCRYPT_ADDR(device), state);
40     auto nativeObject = std::make_shared<NapiNativeStateChangeParam>(device.GetDeviceAddr(), state);
41     eventSubscribe_.PublishEvent(STR_BT_HANDS_FREE_UNIT_OBSERVER_SCO_STATE_CHANGE, nativeObject);
42 }
43 
44 } // namespace Bluetooth
45 } // namespace OHOS