• 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 
16 #ifndef FAULT_LOGGER_PIPE_H
17 #define FAULT_LOGGER_PIPE_H
18 
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 class FaultLoggerPipe {
27 public:
28     FaultLoggerPipe();
29     ~FaultLoggerPipe();
30 
31     int GetReadFd(void);
32     int GetWriteFd(void);
33 
34     void Close(int fd) const;
35 private:
36     bool Init(void);
37     void Destroy(void);
38 
39     int fds_[2] = {-1, -1};
40     bool init_;
41     bool write_;
42 };
43 
44 class FaultLoggerPipe2 {
45 public:
46     explicit FaultLoggerPipe2(uint64_t time);
47     ~FaultLoggerPipe2();
48 
49     std::unique_ptr<FaultLoggerPipe> faultLoggerPipeBuf_;
50     std::unique_ptr<FaultLoggerPipe> faultLoggerPipeRes_;
51     uint64_t time_;
52 };
53 
54 class FaultLoggerPipeMap {
55 public:
56     FaultLoggerPipeMap();
57     ~FaultLoggerPipeMap();
58 
59     bool Check(int pid, uint64_t time);
60     void Set(int pid, uint64_t time);
61     FaultLoggerPipe2* Get(int pid);
62     void Del(int pid);
63 
64 private:
65     bool Find(int pid) const;
66 
67 private:
68     std::map<int, std::unique_ptr<FaultLoggerPipe2> > faultLoggerPipes_;
69     std::mutex pipeMapsMutex_;
70 };
71 } // namespace HiviewDFX
72 } // namespace OHOS
73 #endif
74