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 #ifndef EVENT_LOGGER_EVENT_LOG_CATCHER_H 16 #define EVENT_LOGGER_EVENT_LOG_CATCHER_H 17 #include <ctime> 18 #include <string> 19 namespace OHOS { 20 namespace HiviewDFX { 21 // do not dynamic alloc any memory in sub class, may cause leakage 22 class EventLogCatcher { 23 public: 24 struct TerminalBinder { 25 int pid; 26 int tid; 27 std::string threadStack; 28 }; 29 std::string name_ = ""; 30 TerminalBinder terminalBinder_ = {0, 0, ""}; 31 EventLogCatcher()32 EventLogCatcher() {}; 33 int GetLogSize() const; 34 void SetLogSize(int size); 35 void Stop(); ~EventLogCatcher()36 virtual ~EventLogCatcher() {}; 37 // Initialize a logcater and check whether all parameters are matching the log type 38 virtual bool Initialize(const std::string &strParam1, int intParam1, int intParam2); 39 // start catch the log 40 // return the bytes that caught 41 virtual int Catch(int fd, int jsonFd); 42 // return a string that describe the log catcher 43 // should not be longer than 256 bytes 44 virtual std::string GetDescription() const; 45 int GetFdSize(int32_t fd); 46 std::string GetName() const; 47 protected: 48 int logSize_ = -1; 49 time_t catcherStartTime_ = -1; 50 bool useStreamFilter_ = false; 51 volatile bool needStop_ = false; 52 std::string description_ = ""; 53 }; 54 } // namespace HiviewDFX 55 } // namespace OHOS 56 #endif // EVENT_LOGGER_LOG_CATCHER_H 57