• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_stub.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 #include "logger.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 DEFINE_LOG_TAG("FaultLogQueryResultStub");
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int FaultLogQueryResultStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
28     MessageParcel &reply, MessageOption &option)
29 {
30     std::u16string descripter = FaultLogQueryResultStub::GetDescriptor();
31     std::u16string remoteDescripter = data.ReadInterfaceToken();
32     if (descripter != remoteDescripter) {
33         HIVIEW_LOGE("read descriptor failed.");
34         return -1;
35     }
36 
37     switch (code) {
38         case static_cast<uint32_t>(FaultLogQueryResultInterfaceCode::HASNEXT): {
39             if (!reply.WriteBool(HasNext())) {
40                 HIVIEW_LOGE("failed to query HasNext.");
41                 return -1;
42             }
43             return 0;
44         }
45         case static_cast<uint32_t>(FaultLogQueryResultInterfaceCode::GETNEXT): {
46             auto result = GetNext();
47             if (result == nullptr) {
48                 HIVIEW_LOGE("failed to GetNext.");
49                 return -1;
50             }
51 
52             if (!result->Marshalling(reply)) {
53                 HIVIEW_LOGE("failed to write query result.");
54                 return ERR_FLATTEN_OBJECT;
55             }
56 
57             if (!reply.WriteFileDescriptor(result->fd)) {
58                 HIVIEW_LOGE("failed to write file descriptor.");
59                 return ERR_FLATTEN_OBJECT;
60             }
61             return 0;
62         }
63 
64         default:
65             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
66     }
67 }
68 } // namespace HiviewDFX
69 } // namespace OHOS
70