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_ag_observer.h"
18 #include "napi_bluetooth_event.h"
19
20 namespace OHOS {
21 namespace Bluetooth {
NapiHandsFreeAudioGatewayObserver()22 NapiHandsFreeAudioGatewayObserver::NapiHandsFreeAudioGatewayObserver()
23 : eventSubscribe_({STR_BT_HANDS_FREE_AUDIO_GATEWAY_OBSERVER_CONNECTION_STATE_CHANGE,
24 STR_BT_HANDS_FREE_AUDIO_GATEWAY_OBSERVER_SCO_STATE_CHANGE},
25 BT_MODULE_NAME)
26 {}
27
OnConnectionStateChanged(const BluetoothRemoteDevice & device,int state,int cause)28 void NapiHandsFreeAudioGatewayObserver::OnConnectionStateChanged(const BluetoothRemoteDevice &device,
29 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_AUDIO_GATEWAY_OBSERVER_CONNECTION_STATE_CHANGE, nativeObject);
35 }
36
OnScoStateChanged(const BluetoothRemoteDevice & device,int state,int reason)37 void NapiHandsFreeAudioGatewayObserver::OnScoStateChanged(const BluetoothRemoteDevice &device, int state, int reason)
38 {
39 HILOGI("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_AUDIO_GATEWAY_OBSERVER_SCO_STATE_CHANGE, nativeObject);
42 }
43
44 } // namespace Bluetooth
45 } // namespace OHOS