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 16 #ifndef FAULT_LOGGER_PIPE_H 17 #define FAULT_LOGGER_PIPE_H 18 19 #include <cstdint> 20 #include <list> 21 22 #include "dfx_socket_request.h" 23 24 namespace OHOS { 25 namespace HiviewDFX { 26 class FaultLoggerPipe { 27 public: 28 FaultLoggerPipe(); 29 ~FaultLoggerPipe(); 30 FaultLoggerPipe(const FaultLoggerPipe&) = delete; 31 FaultLoggerPipe& operator=(const FaultLoggerPipe&) = delete; 32 FaultLoggerPipe(FaultLoggerPipe&& rhs) noexcept; 33 FaultLoggerPipe& operator=(FaultLoggerPipe&& rhs) noexcept; 34 int GetReadFd() const; 35 int GetWriteFd(); 36 private: 37 static void Close(int& fd); 38 bool write_{false}; 39 int readFd_{-1}; 40 int writeFd_{-1}; 41 }; 42 43 enum class PipeFdUsage { 44 BUFFER_FD = 0, 45 RESULT_FD = 1, 46 }; 47 48 class FaultLoggerPipePair { 49 public: 50 int32_t GetPipeFd(PipeFdUsage usage, FaultLoggerPipeType pipeType); 51 FaultLoggerPipePair(int32_t pid, uint64_t requestTime); 52 FaultLoggerPipePair(FaultLoggerPipePair&&) noexcept = default; 53 FaultLoggerPipePair& operator=(FaultLoggerPipePair&&) noexcept = default; 54 static FaultLoggerPipePair& CreateSdkDumpPipePair(int pid, uint64_t requestTime); 55 static bool CheckSdkDumpRecord(int pid, uint64_t checkTime); 56 static FaultLoggerPipePair* GetSdkDumpPipePair(int pid); 57 static void DelSdkDumpPipePair(int pid); 58 private: 59 FaultLoggerPipePair(const FaultLoggerPipePair&) = delete; 60 FaultLoggerPipePair& operator=(const FaultLoggerPipePair&) = delete; 61 bool IsValid(uint64_t checkTime) const; 62 int32_t pid_; 63 uint64_t requestTime_; 64 FaultLoggerPipe faultLoggerPipeBuf_; 65 FaultLoggerPipe faultLoggerPipeRes_; 66 static std::list<FaultLoggerPipePair> sdkDumpPipes_; 67 }; 68 } // namespace HiviewDFX 69 } // namespace OHOS 70 #endif // FAULT_LOGGER_PIPE_H 71