1 /*
2 * Copyright (c) 2023 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 "download_asset_callback_stub.h"
17 #include "dfs_error.h"
18 #include "utils_log.h"
19
20 namespace OHOS::FileManagement::CloudSync {
21 using namespace std;
22
DownloadAssetCallbackStub()23 DownloadAssetCallbackStub::DownloadAssetCallbackStub()
24 {
25 opToInterfaceMap_[SERVICE_CMD_ON_DOWNLOAD_FINSHED] = [this](MessageParcel &data, MessageParcel &reply) {
26 return this->HandleOnFinished(data, reply);
27 };
28 }
29
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int32_t DownloadAssetCallbackStub::OnRemoteRequest(uint32_t code,
31 MessageParcel &data,
32 MessageParcel &reply,
33 MessageOption &option)
34 {
35 if (data.ReadInterfaceToken() != GetDescriptor()) {
36 return E_SERVICE_DESCRIPTOR_IS_EMPTY;
37 }
38 auto interfaceIndex = opToInterfaceMap_.find(code);
39 if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) {
40 LOGE("Cannot response request %d: unknown tranction", code);
41 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
42 }
43 auto memberFunc = interfaceIndex->second;
44 return memberFunc(data, reply);
45 }
46
HandleOnFinished(MessageParcel & data,MessageParcel & reply)47 int32_t DownloadAssetCallbackStub::HandleOnFinished(MessageParcel &data, MessageParcel &reply)
48 {
49 TaskId taskId = data.ReadUint64();
50 string uri = data.ReadString();
51 int32_t result = data.ReadInt32();
52 OnFinished(taskId, uri, result);
53 return E_OK;
54 }
55 } // namespace OHOS::FileManagement::CloudSync