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 #define LOG_TAG "ObjectCallbackStub"
17 #include "object_callback_stub.h"
18 #include <ipc_skeleton.h>
19 #include "itypes_util.h"
20 #include "log_print.h"
21
22 namespace OHOS {
23 namespace DistributedObject {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int ObjectSaveCallbackStub::OnRemoteRequest(
25 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
26 {
27 ZLOGI("code:%{public}u, callingPid:%{public}d", code, IPCSkeleton::GetCallingPid());
28 auto localDescriptor = GetDescriptor();
29 auto remoteDescriptor = data.ReadInterfaceToken();
30 if (remoteDescriptor != localDescriptor) {
31 ZLOGE("interface token is not equal");
32 return -1;
33 }
34 if (code == COMPLETED) {
35 std::map<std::string, int32_t> results;
36 if (!ITypesUtil::Unmarshal(data, results)) {
37 ZLOGE("Unmarshalling failed");
38 return -1;
39 }
40 Completed(results);
41 return 0;
42 }
43 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
44 }
45
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)46 int ObjectRevokeSaveCallbackStub::OnRemoteRequest(
47 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
48 {
49 ZLOGI("code:%{public}u, callingPid:%{public}d", code, IPCSkeleton::GetCallingPid());
50 auto localDescriptor = GetDescriptor();
51 auto remoteDescriptor = data.ReadInterfaceToken();
52 if (remoteDescriptor != localDescriptor) {
53 ZLOGE("interface token is not equal");
54 return -1;
55 }
56 if (code == COMPLETED) {
57 int32_t status;
58 if (!ITypesUtil::Unmarshal(data, status)) {
59 ZLOGE("write descriptor failed");
60 return -1;
61 }
62 Completed(status);
63 return 0;
64 }
65 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
66 }
67
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)68 int ObjectRetrieveCallbackStub::OnRemoteRequest(
69 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
70 {
71 ZLOGI("code:%{public}u, callingPid:%{public}d", code, IPCSkeleton::GetCallingPid());
72 auto localDescriptor = GetDescriptor();
73 auto remoteDescriptor = data.ReadInterfaceToken();
74 if (remoteDescriptor != localDescriptor) {
75 ZLOGE("interface token is not equal");
76 return -1;
77 }
78 if (code == COMPLETED) {
79 std::map<std::string, std::vector<uint8_t>> results;
80 bool allReady;
81 if (!ITypesUtil::Unmarshal(data, results, allReady)) {
82 ZLOGE("write descriptor failed");
83 return -1;
84 }
85 Completed(results, allReady);
86 return 0;
87 }
88 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
89 }
90
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)91 int ObjectChangeCallbackStub::OnRemoteRequest(
92 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
93 {
94 ZLOGI("code:%{public}u, callingPid:%{public}d", code, IPCSkeleton::GetCallingPid());
95 auto localDescriptor = GetDescriptor();
96 auto remoteDescriptor = data.ReadInterfaceToken();
97 if (remoteDescriptor != localDescriptor) {
98 ZLOGE("interface token is not equal");
99 return -1;
100 }
101 if (code == COMPLETED) {
102 std::map<std::string, std::vector<uint8_t>> results;
103 bool allReady;
104 if (!ITypesUtil::Unmarshal(data, results, allReady)) {
105 ZLOGE("write descriptor failed");
106 return -1;
107 }
108 Completed(results, allReady);
109 return 0;
110 }
111 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
112 }
113 } // namespace DistributedObject
114 } // namespace OHOS
115