1 /*
2 * Copyright (c) 2021-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 #include "faultlog_query_result_proxy.h"
16
17 #include "ipc_types.h"
18 #include "message_parcel.h"
19
20 #include "faultlog_info_ohos.h"
21 #include "hiviewfaultlogger_ipc_interface_code.h"
22
23 namespace OHOS {
24 namespace HiviewDFX {
HasNext()25 bool FaultLogQueryResultProxy::HasNext()
26 {
27 sptr<IRemoteObject> remote = Remote();
28 if (remote == nullptr) {
29 return false;
30 }
31
32 MessageParcel data;
33 MessageParcel reply;
34 MessageOption option;
35 if (!data.WriteInterfaceToken(FaultLogQueryResultProxy::GetDescriptor())) {
36 return false;
37 }
38
39 if (remote->SendRequest(static_cast<uint32_t>(FaultLogQueryResultInterfaceCode::HASNEXT),
40 data, reply, option) != ERR_OK) {
41 return false;
42 }
43
44 bool hasNext = false;
45 if (!reply.ReadBool(hasNext)) {
46 return false;
47 }
48 return hasNext;
49 }
50
GetNext()51 sptr<FaultLogInfoOhos> FaultLogQueryResultProxy::GetNext()
52 {
53 sptr<IRemoteObject> remote = Remote();
54 if (remote == nullptr) {
55 return nullptr;
56 }
57
58 MessageParcel data;
59 MessageParcel reply;
60 MessageOption option;
61 if (!data.WriteInterfaceToken(FaultLogQueryResultProxy::GetDescriptor())) {
62 return nullptr;
63 }
64
65 if (remote->SendRequest(static_cast<uint32_t>(FaultLogQueryResultInterfaceCode::GETNEXT),
66 data, reply, option) != ERR_OK) {
67 return nullptr;
68 }
69
70 sptr<FaultLogInfoOhos> ret = FaultLogInfoOhos::Unmarshalling(reply);
71 if (ret != nullptr && reply.ContainFileDescriptors()) {
72 ret->fd = reply.ReadFileDescriptor();
73 }
74 return ret;
75 }
76 } // namespace HiviewDFX
77 } // namespace OHOS
78