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 "ipc/cloud_daemon_stub.h"
17
18 #include "cloud_file_daemon_interface_code.h"
19 #include "dfs_error.h"
20 #include "dfsu_memory_guard.h"
21 #include "utils_log.h"
22
23 namespace OHOS {
24 namespace FileManagement {
25 namespace CloudFile {
CloudDaemonStub()26 CloudDaemonStub::CloudDaemonStub()
27 {
28 opToInterfaceMap_[static_cast<uint32_t>(CloudFileDaemonInterfaceCode::CLOUD_DAEMON_CMD_START_FUSE)] =
29 [this](MessageParcel &data, MessageParcel &reply) {
30 return this->HandleStartFuseInner(data, reply);
31 };
32 }
33
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int32_t CloudDaemonStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
35 MessageParcel &reply, MessageOption &option)
36 {
37 CloudSync::DfsuMemoryGuard cacheGuard;
38 if (data.ReadInterfaceToken() != GetDescriptor()) {
39 return CLOUD_DAEMON_DESCRIPTOR_IS_EMPTY;
40 }
41 auto interfaceIndex = opToInterfaceMap_.find(code);
42 if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) {
43 LOGE("Cannot response request %d: unknown tranction", code);
44 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
45 }
46 auto memberFunc = interfaceIndex->second;
47 return memberFunc(data, reply);
48 }
49
HandleStartFuseInner(MessageParcel & data,MessageParcel & reply)50 int32_t CloudDaemonStub::HandleStartFuseInner(MessageParcel &data, MessageParcel &reply)
51 {
52 LOGI("Begin StartFuseInner");
53 auto userId = data.ReadInt32();
54 auto fd = data.ReadFileDescriptor();
55 auto path = data.ReadString();
56 int32_t res = StartFuse(userId, int32_t(fd), path);
57 reply.WriteInt32(res);
58 LOGI("End StartFuseInner");
59 return E_OK;
60 }
61 } // namespace CloudFile
62 } // namespace FileManagement
63 } // namespace OHOS
64