1 /*
2 * Copyright (C) 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_opp_observer_stub"
17 #endif
18
19 #include "bluetooth_errorcode.h"
20 #include "bluetooth_opp_observer_stub.h"
21 #include "bluetooth_log.h"
22
23 namespace OHOS {
24 namespace Bluetooth {
25
BluetoothOppObserverStub()26 BluetoothOppObserverStub::BluetoothOppObserverStub()
27 {
28 HILOGI("start.");
29 memberFuncMap_[static_cast<uint32_t>(
30 BluetoothOppObserverInterfaceCode::OPP_ON_RECEIVE_INCOMING_FILE_CHANGED)] =
31 BluetoothOppObserverStub::OnReceiveIncomingFileChangedInner;
32 memberFuncMap_[static_cast<uint32_t>(
33 BluetoothOppObserverInterfaceCode::OPP_ON_TRANSFER_STATE_CHANGED)] =
34 BluetoothOppObserverStub::OnTransferStateChangedInner;
35 }
36
~BluetoothOppObserverStub()37 BluetoothOppObserverStub::~BluetoothOppObserverStub()
38 {
39 HILOGI("start.");
40 memberFuncMap_.clear();
41 }
42
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)43 int32_t BluetoothOppObserverStub::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 (BluetoothOppObserverStub::GetDescriptor() != data.ReadInterfaceToken()) {
48 HILOGI("local descriptor is not equal to remote");
49 return ERR_INVALID_STATE;
50 }
51
52 auto itFunc = memberFuncMap_.find(code);
53 if (itFunc != memberFuncMap_.end()) {
54 auto memberFunc = itFunc->second;
55 if (memberFunc != nullptr) {
56 return memberFunc(this, data, reply);
57 }
58 }
59 HILOGW("OnRemoteRequest, default case, need check.");
60 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
61 }
62
OnReceiveIncomingFileChangedInner(BluetoothOppObserverStub * stub,MessageParcel & data,MessageParcel & reply)63 int32_t BluetoothOppObserverStub::OnReceiveIncomingFileChangedInner(BluetoothOppObserverStub *stub,
64 MessageParcel &data, MessageParcel &reply)
65 {
66 HILOGD("Enter.");
67 std::shared_ptr<BluetoothIOppTransferInformation> oppInformation(
68 data.ReadParcelable<BluetoothIOppTransferInformation>());
69 CHECK_AND_RETURN_LOG_RET((oppInformation != nullptr), BT_ERR_INTERNAL_ERROR, "Read oppInformation error");
70 stub->OnReceiveIncomingFileChanged(*oppInformation);
71 return BT_NO_ERROR;
72 }
73
OnTransferStateChangedInner(BluetoothOppObserverStub * stub,MessageParcel & data,MessageParcel & reply)74 int32_t BluetoothOppObserverStub::OnTransferStateChangedInner(BluetoothOppObserverStub *stub,
75 MessageParcel &data, MessageParcel &reply)
76 {
77 HILOGD("Enter.");
78 std::shared_ptr<BluetoothIOppTransferInformation> oppInformation(
79 data.ReadParcelable<BluetoothIOppTransferInformation>());
80 CHECK_AND_RETURN_LOG_RET((oppInformation != nullptr), BT_ERR_INTERNAL_ERROR, "Read oppInformation error");
81 stub->OnTransferStateChanged(*oppInformation);
82 return BT_NO_ERROR;
83 }
84 } // namespace Bluetooth
85 } // namespace OHOS