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