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