1 /*
2 * Copyright (c) 2024 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 "asset_send_callback_proxy.h"
17
18 #include "asset/asset_callback_interface_code.h"
19 #include "dfs_error.h"
20 #include "iservice_registry.h"
21 #include "system_ability_definition.h"
22 #include "utils_log.h"
23
24 namespace OHOS {
25 namespace Storage {
26 namespace DistributedFile {
27 using namespace std;
28 using namespace OHOS::Storage;
29 using namespace OHOS::FileManagement;
30
OnSendResult(const sptr<AssetObj> & assetObj,int32_t result)31 int32_t AssetSendCallbackProxy::OnSendResult(const sptr<AssetObj> &assetObj, int32_t result)
32 {
33 MessageParcel data;
34 MessageParcel reply;
35 MessageOption option;
36 if (!data.WriteInterfaceToken(GetDescriptor())) {
37 LOGE("Failed to write interface token");
38 return E_BROKEN_IPC;
39 }
40
41 if (!data.WriteParcelable(assetObj)) {
42 LOGE("Failed to send the assetInfoObj");
43 return E_INVAL_ARG;
44 }
45
46 if (!data.WriteInt32(result)) {
47 LOGE("Failed to send result");
48 return E_INVAL_ARG;
49 }
50 auto remote = Remote();
51 if (remote == nullptr) {
52 LOGE("remote is nullptr");
53 return E_BROKEN_IPC;
54 }
55 int32_t ret = remote->SendRequest(
56 static_cast<uint32_t>(AssetCallbackInterfaceCode::ASSET_CALLBACK_ON_SEND_RESULT), data, reply, option);
57 if (ret != E_OK) {
58 LOGE("Failed to send out the request, errno:%{public}d", errno);
59 return E_BROKEN_IPC;
60 }
61 return reply.ReadInt32();
62 }
63 } // namespace DistributedFile
64 } // namespace Storage
65 } // namespace OHOS