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_ohos.h" 16 17 #include <fcntl.h> 18 #include <sys/stat.h> 19 20 #include "file_util.h" 21 22 #include "faultlog_info_ohos.h" 23 #include "faultlog_query_result_inner.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { GetNext()27sptr<FaultLogInfoOhos> FaultLogQueryResultOhos::GetNext() 28 { 29 if (result_ == nullptr) { 30 return nullptr; 31 } 32 33 sptr<FaultLogInfoOhos> ret; 34 auto info = result_->GetNext(); 35 if (info != nullptr) { 36 ret = new FaultLogInfoOhos(); 37 ret->time = info->time; 38 ret->uid = info->id; 39 ret->pid = info->pid; 40 ret->faultLogType = info->faultLogType; 41 ret->module = info->module; 42 ret->summary = info->summary; 43 ret->reason = info->reason; 44 ret->logPath = info->logPath; 45 ret->sectionMaps = info->sectionMap; 46 std::string realPath; 47 if ((!info->logPath.empty()) && OHOS::HiviewDFX::FileUtil::PathToRealPath(info->logPath, realPath)) { 48 ret->fd = TEMP_FAILURE_RETRY(open(realPath.c_str(), O_RDONLY)); 49 } else { 50 ret->fd = -1; 51 } 52 } 53 return ret; 54 } 55 HasNext()56bool FaultLogQueryResultOhos::HasNext() 57 { 58 if (result_ == nullptr) { 59 return false; 60 } 61 62 return result_->HasNext(); 63 } 64 } // namespace HiviewDFX 65 } // namespace OHOS 66