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 #ifndef LOG_TAG
16 #define LOG_TAG "bt_ipc_avrcp_tg_observer_stub"
17 #endif
18
19 #include "bluetooth_avrcp_tg_observer_stub.h"
20 #include "bluetooth_log.h"
21
22 namespace OHOS {
23 namespace Bluetooth {
BluetoothAvrcpTgObserverStub()24 BluetoothAvrcpTgObserverStub::BluetoothAvrcpTgObserverStub()
25 {
26 HILOGD("start.");
27 memberFuncMap_[static_cast<uint32_t>(
28 BluetoothAvrcpTgObserverInterfaceCode::BT_AVRCP_TG_OBSERVER_CONNECTION_STATE_CHANGED)] =
29 BluetoothAvrcpTgObserverStub::OnConnectionStateChangedInner;
30 }
31
~BluetoothAvrcpTgObserverStub()32 BluetoothAvrcpTgObserverStub::~BluetoothAvrcpTgObserverStub()
33 {
34 HILOGD("start.");
35 memberFuncMap_.clear();
36 }
37
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)38 int BluetoothAvrcpTgObserverStub::OnRemoteRequest(
39 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
40 {
41 HILOGD("BluetoothAvrcpTgObserverStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d",
42 code, option.GetFlags());
43 if (BluetoothAvrcpTgObserverStub::GetDescriptor() != data.ReadInterfaceToken()) {
44 HILOGI("local descriptor is not equal to remote");
45 return ERR_INVALID_STATE;
46 }
47 auto itFunc = memberFuncMap_.find(code);
48 if (itFunc != memberFuncMap_.end()) {
49 auto memberFunc = itFunc->second;
50 if (memberFunc != nullptr) {
51 return memberFunc(this, data, reply);
52 }
53 }
54 HILOGW("BluetoothAvrcpTgObserverStub::OnRemoteRequest, default case, need check.");
55 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56 }
57
OnConnectionStateChangedInner(BluetoothAvrcpTgObserverStub * stub,MessageParcel & data,MessageParcel & reply)58 ErrCode BluetoothAvrcpTgObserverStub::OnConnectionStateChangedInner(
59 BluetoothAvrcpTgObserverStub *stub, MessageParcel &data, MessageParcel &reply)
60 {
61 HILOGI("BluetoothAvrcpTgObserverStub::OnConnectionStateChangedInner Triggered!");
62 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());
63 if (!addr) {
64 return TRANSACTION_ERR;
65 }
66 int state = data.ReadInt32();
67 int cause = data.ReadInt32();
68
69 stub->OnConnectionStateChanged(*addr, state, cause);
70 return NO_ERROR;
71 }
72 } // namespace Bluetooth
73 } // namespace OHOS