• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         if (!ITypesUtil::Unmarshal(data, results)) {
82             ZLOGE("write descriptor failed");
83             return -1;
84         }
85         Completed(results);
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         if (!ITypesUtil::Unmarshal(data, results)) {
104             ZLOGE("write descriptor failed");
105             return -1;
106         }
107         Completed(results);
108         return 0;
109     }
110     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
111 }
112 } // namespace DistributedObject
113 } // namespace OHOS
114