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 
16 #include "bluetooth_a2dp_sink_observer_proxy.h"
17 #include "bluetooth_log.h"
18 
19 namespace OHOS {
20 namespace Bluetooth {
OnConnectionStateChanged(const RawAddress & device,int state,int cause)21 void BluetoothA2dpSinkObserverProxy::OnConnectionStateChanged(const RawAddress &device, int state, int cause)
22 {
23     MessageParcel data;
24     if (!data.WriteInterfaceToken(BluetoothA2dpSinkObserverProxy::GetDescriptor())) {
25         HILOGE("BluetoothA2dpSinkObserverProxy::OnConnectionStateChanged WriteInterfaceToken error");
26         return;
27     }
28     if (!data.WriteString(device.GetAddress())) {
29         HILOGE("BluetoothA2dpSinkObserverProxy::OnConnectionStateChanged write device error");
30         return;
31     }
32     if (!data.WriteInt32(state)) {
33         HILOGE("BluetoothA2dpSinkObserverProxy::OnConnectionStateChanged state error");
34         return;
35     }
36     if (!data.WriteInt32(cause)) {
37         HILOGE("BluetoothA2dpSinkObserverProxy::OnConnectionStateChanged cause error");
38         return;
39     }
40 
41     MessageParcel reply;
42     MessageOption option {
43         MessageOption::TF_ASYNC
44     };
45 
46     int ret = Remote()->SendRequest(
47         BluetoothA2dpSinkObserverInterfaceCode::BT_A2DP_SINK_OBSERVER_CONNECTION_STATE_CHANGED, data, reply, option);
48     if (ret != NO_ERROR) {
49         HILOGE("BluetoothA2dpSinkProxy::OnPlayingStateChanged done fail");
50         return;
51     }
52 }
53 
54 }  // namespace Bluetooth
55 }  // namespace OHOS