• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     funcMap_[static_cast<uint32_t>(IBluetoothA2dpSourceObserver::Code::BT_A2DP_SRC_OBSERVER_MEDIASTACK_CHANGED)] =
32         &BluetoothA2dpAudioSrcObserverStub::OnMediaStackChangedInner;
33 }
34 
~BluetoothA2dpAudioSrcObserverStub()35 BluetoothA2dpAudioSrcObserverStub::~BluetoothA2dpAudioSrcObserverStub()
36 {
37     HDF_LOGI("%{public}s start.", __func__);
38     funcMap_.clear();
39 }
40 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)41 int BluetoothA2dpAudioSrcObserverStub::OnRemoteRequest(
42     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
43 {
44     HDF_LOGI("BluetoothA2dpAudioSrcObserverStub::OnRemoteRequest, cmd=%{public}d, flags= %d", code, option.GetFlags());
45     std::u16string descriptor = BluetoothA2dpAudioSrcObserverStub::GetDescriptor();
46     std::u16string remoteDescriptor = data.ReadInterfaceToken();
47     if (descriptor != remoteDescriptor) {
48         HDF_LOGE("local descriptor is not equal to remote");
49         return ERR_INVALID_STATE;
50     }
51     auto itFunc = funcMap_.find(code);
52     if (itFunc != funcMap_.end()) {
53         auto memberFunc = itFunc->second;
54         if (memberFunc != nullptr) {
55             return (this->*memberFunc)(data, reply);
56         }
57     }
58     HDF_LOGI("BluetoothA2dpAudioSrcObserverStub::OnRemoteRequest, default case, need check.");
59     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
60 }
61 
OnConnectionStateChangedInner(MessageParcel & data,MessageParcel & reply)62 ErrCode BluetoothA2dpAudioSrcObserverStub::OnConnectionStateChangedInner(MessageParcel &data, MessageParcel &reply)
63 {
64     std::string addr = data.ReadString();
65     int state = data.ReadInt32();
66     HDF_LOGI("BluetoothA2dpAudioSrcObserverStub::OnConnectionStateChangedInner");
67     OnConnectionStateChanged(RawAddress(addr), state);
68 
69     return NO_ERROR;
70 }
71 
OnPlayingStatusChangedInner(MessageParcel & data,MessageParcel & reply)72 ErrCode BluetoothA2dpAudioSrcObserverStub::OnPlayingStatusChangedInner(MessageParcel &data, MessageParcel &reply)
73 {
74     std::string addr = data.ReadString();
75     int playingState = data.ReadInt32();
76     int error = data.ReadInt32();
77     HDF_LOGI("BluetoothA2dpAudioSrcObserverStub::OnPlayingStatusChangedInner");
78     OnPlayingStatusChanged(RawAddress(addr), playingState, error);
79 
80     return NO_ERROR;
81 }
82 
OnConfigurationChangedInner(MessageParcel & data,MessageParcel & reply)83 ErrCode BluetoothA2dpAudioSrcObserverStub::OnConfigurationChangedInner(MessageParcel &data, MessageParcel &reply)
84 {
85     std::string addr = data.ReadString();
86     BluetoothA2dpCodecInfo info = *data.ReadParcelable<BluetoothA2dpCodecInfo>();
87     int error = data.ReadInt32();
88     HDF_LOGI("BluetoothA2dpAudioSrcObserverStub::OnConfigurationChangedInner");
89     OnConfigurationChanged(RawAddress(addr), info, error);
90 
91     return NO_ERROR;
92 }
93 
OnMediaStackChangedInner(MessageParcel & data,MessageParcel & reply)94 int32_t BluetoothA2dpAudioSrcObserverStub::OnMediaStackChangedInner(MessageParcel &data, MessageParcel &reply)
95 {
96     std::string addr = data.ReadString();
97     int action = data.ReadInt32();
98     HDF_LOGI("BluetoothA2dpAudioSrcObserverStub::OnMediaStackChangedInner");
99     OnMediaStackChanged(RawAddress(addr), action);
100 
101     return NO_ERROR;
102 }
103 }
104 }