1 /*
2 * Copyright (c) 2021 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 <hdf_log.h>
16 #include "raw_address.h"
17 #include "bluetooth_a2dp_audio_src_observer_stub.h"
18
19 namespace OHOS {
20 namespace Bluetooth {
21 using namespace OHOS::bluetooth;
BluetoothA2dpAudioSrcObserverStub()22 BluetoothA2dpAudioSrcObserverStub::BluetoothA2dpAudioSrcObserverStub()
23 {
24 HDF_LOGI("%{public}s start.", __func__);
25 funcMap_[static_cast<uint32_t>(IBluetoothA2dpSourceObserver::Code::BT_A2DP_SRC_OBSERVER_CONNECTION_STATE_CHANGED)] =
26 &BluetoothA2dpAudioSrcObserverStub::OnConnectionStateChangedInner;
27 funcMap_[static_cast<uint32_t>(IBluetoothA2dpSourceObserver::Code::BT_A2DP_SRC_OBSERVER_PLAYING_STATUS_CHANGED)] =
28 &BluetoothA2dpAudioSrcObserverStub::OnPlayingStatusChangedInner;
29 funcMap_[static_cast<uint32_t>(IBluetoothA2dpSourceObserver::Code::BT_A2DP_SRC_OBSERVER_CONFIGURATION_CHANGED)] =
30 &BluetoothA2dpAudioSrcObserverStub::OnConfigurationChangedInner;
31 }
32
~BluetoothA2dpAudioSrcObserverStub()33 BluetoothA2dpAudioSrcObserverStub::~BluetoothA2dpAudioSrcObserverStub()
34 {
35 HDF_LOGI("%{public}s start.", __func__);
36 funcMap_.clear();
37 }
38
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int BluetoothA2dpAudioSrcObserverStub::OnRemoteRequest(
40 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
41 {
42 HDF_LOGI("BluetoothA2dpAudioSrcObserverStub::OnRemoteRequest, cmd=%{public}d, flags= %d", code, option.GetFlags());
43 std::u16string descriptor = BluetoothA2dpAudioSrcObserverStub::GetDescriptor();
44 std::u16string remoteDescriptor = data.ReadInterfaceToken();
45 if (descriptor != remoteDescriptor) {
46 HDF_LOGE("local descriptor is not equal to remote");
47 return ERR_INVALID_STATE;
48 }
49 auto itFunc = funcMap_.find(code);
50 if (itFunc != funcMap_.end()) {
51 auto memberFunc = itFunc->second;
52 if (memberFunc != nullptr) {
53 return (this->*memberFunc)(data, reply);
54 }
55 }
56 HDF_LOGI("BluetoothA2dpAudioSrcObserverStub::OnRemoteRequest, default case, need check.");
57 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
58 }
59
OnConnectionStateChangedInner(MessageParcel & data,MessageParcel & reply)60 ErrCode BluetoothA2dpAudioSrcObserverStub::OnConnectionStateChangedInner(MessageParcel &data, MessageParcel &reply)
61 {
62 std::string addr = data.ReadString();
63 int state = data.ReadInt32();
64 HDF_LOGI("BluetoothA2dpAudioSrcObserverStub::OnConnectionStateChangedInner");
65 OnConnectionStateChanged(RawAddress(addr), state);
66
67 return NO_ERROR;
68 }
69
OnPlayingStatusChangedInner(MessageParcel & data,MessageParcel & reply)70 ErrCode BluetoothA2dpAudioSrcObserverStub::OnPlayingStatusChangedInner(MessageParcel &data, MessageParcel &reply)
71 {
72 std::string addr = data.ReadString();
73 int playingState = data.ReadInt32();
74 int error = data.ReadInt32();
75 HDF_LOGI("BluetoothA2dpAudioSrcObserverStub::OnPlayingStatusChangedInner");
76 OnPlayingStatusChanged(RawAddress(addr), playingState, error);
77
78 return NO_ERROR;
79 }
80
OnConfigurationChangedInner(MessageParcel & data,MessageParcel & reply)81 ErrCode BluetoothA2dpAudioSrcObserverStub::OnConfigurationChangedInner(MessageParcel &data, MessageParcel &reply)
82 {
83 std::string addr = data.ReadString();
84 BluetoothA2dpCodecInfo info = *data.ReadParcelable<BluetoothA2dpCodecInfo>();
85 int error = data.ReadInt32();
86 HDF_LOGI("BluetoothA2dpAudioSrcObserverStub::OnConfigurationChangedInner");
87 OnConfigurationChanged(RawAddress(addr), info, error);
88
89 return NO_ERROR;
90 }
91 }
92 }