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 "dfsu_memory_guard.h"
20 #include "utils_log.h"
21
22 namespace OHOS {
23 namespace FileManagement {
24 namespace CloudFile {
CloudDaemonStub()25 CloudDaemonStub::CloudDaemonStub()
26 {
27 opToInterfaceMap_[static_cast<uint32_t>(CloudFileDaemonInterfaceCode::CLOUD_DAEMON_CMD_START_FUSE)] =
28 &CloudDaemonStub::HandleStartFuseInner;
29 }
30
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t CloudDaemonStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
32 MessageParcel &reply, MessageOption &option)
33 {
34 CloudSync::DfsuMemoryGuard cacheGuard;
35 if (data.ReadInterfaceToken() != GetDescriptor()) {
36 return CLOUD_DAEMON_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 return (this->*(interfaceIndex->second))(data, reply);
44 }
45
HandleStartFuseInner(MessageParcel & data,MessageParcel & reply)46 int32_t CloudDaemonStub::HandleStartFuseInner(MessageParcel &data, MessageParcel &reply)
47 {
48 LOGI("Begin StartFuseInner");
49 auto userId = data.ReadInt32();
50 auto fd = data.ReadFileDescriptor();
51 auto path = data.ReadString();
52 int32_t res = StartFuse(userId, int32_t(fd), path);
53 reply.WriteInt32(res);
54 LOGI("End StartFuseInner");
55 return res;
56 }
57 } // namespace CloudFile
58 } // namespace FileManagement
59 } // namespace OHOS
60