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