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_map_mse_observer_stub.h"
17 #include "bluetooth_log.h"
18
19 namespace OHOS {
20 namespace Bluetooth {
BluetoothMapMseObserverStub()21 BluetoothMapMseObserverStub::BluetoothMapMseObserverStub()
22 {
23 HILOGD("%{public}s start.", __func__);
24 memberFuncMap_[static_cast<uint32_t>(
25 IBluetoothMapMseObserver::Code::MSE_ON_CONNECTION_STATE_CHANGED)] =
26 &BluetoothMapMseObserverStub::OnConnectionStateChangedInner;
27 memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMseObserver::Code::MSE_ON_PERMISSION)] =
28 &BluetoothMapMseObserverStub::OnPermissionInner;
29 }
30
~BluetoothMapMseObserverStub()31 BluetoothMapMseObserverStub::~BluetoothMapMseObserverStub()
32 {
33 HILOGD("%{public}s start.", __func__);
34 memberFuncMap_.clear();
35 }
36
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)37 int BluetoothMapMseObserverStub::OnRemoteRequest(
38 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
39 {
40 HILOGI("BluetoothMapMseObserverStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d",
41 code,
42 option.GetFlags());
43 if (BluetoothMapMseObserverStub::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 (this->*memberFunc)(data, reply);
52 }
53 }
54 HILOGW("BluetoothMapMseObserverStub::OnRemoteRequest, default case, need check.");
55 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56 }
57
OnConnectionStateChangedInner(MessageParcel & data,MessageParcel & reply)58 ErrCode BluetoothMapMseObserverStub::OnConnectionStateChangedInner(MessageParcel &data, MessageParcel &reply)
59 {
60 HILOGI("BluetoothMapMseObserverStub::OnConnectionStateChangedInner Triggered!");
61 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());
62 if (!addr) {
63 return TRANSACTION_ERR;
64 }
65 int32_t status = data.ReadInt32();
66 OnConnectionStateChanged(*addr, status);
67 return NO_ERROR;
68 }
69
OnPermissionInner(MessageParcel & data,MessageParcel & reply)70 ErrCode BluetoothMapMseObserverStub::OnPermissionInner(MessageParcel &data, MessageParcel &reply)
71 {
72 HILOGI("BluetoothMapMseObserverStub::OnPermissionInner Triggered!");
73 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());
74 if (!addr) {
75 return TRANSACTION_ERR;
76 }
77 OnPermission(*addr);
78 return NO_ERROR;
79 }
80 } // namespace Bluetooth
81 } // namespace OHOS
82