1 /* 2 * Copyright (c) 2021-2022 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 /* This files contains header of secure module. */ 17 18 #ifndef _FAULT_LOGGER_PIPE_H 19 #define _FAULT_LOGGER_PIPE_H 20 21 #include <map> 22 #include <memory> 23 #include <string> 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 class FaultLoggerPipe { 28 public: 29 FaultLoggerPipe(); 30 ~FaultLoggerPipe(); 31 32 int GetReadFd(); 33 int GetWriteFd(); 34 35 void Close(int fd) const; 36 private: 37 bool Init(); 38 void Destroy(); 39 40 int pfds_[2] = {-1, -1}; 41 bool bInit_; 42 }; 43 44 class FaultLoggerPipe2 { 45 public: 46 FaultLoggerPipe2(std::unique_ptr<FaultLoggerPipe> pipeBuf, std::unique_ptr<FaultLoggerPipe> pipeRes); 47 FaultLoggerPipe2(); 48 ~FaultLoggerPipe2(); 49 50 std::unique_ptr<FaultLoggerPipe> faultLoggerPipeBuf_; 51 std::unique_ptr<FaultLoggerPipe> faultLoggerPipeRes_; 52 }; 53 54 class FaultLoggerPipeMap { 55 public: 56 FaultLoggerPipeMap(); 57 ~FaultLoggerPipeMap(); 58 59 void Set(int pid); 60 FaultLoggerPipe2* Get(int pid); 61 void Del(int pid); 62 63 private: 64 bool Find(int pid) const; 65 66 private: 67 std::map<int, std::unique_ptr<FaultLoggerPipe2> > faultLoggerPipes_; 68 }; 69 } // namespace HiviewDFX 70 } // namespace OHOS 71 #endif 72