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