Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1 | /* |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 2 | * Copyright (C) 2020 The Android Open Source Project |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Tom Cherry | 1a12ae3 | 2020-05-01 16:13:18 -0700 | [diff] [blame] | 17 | #pragma once |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 18 | |
| 19 | #include <sys/types.h> |
| 20 | |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 21 | #include <functional> |
Mark Salyzyn | 94a89c4 | 2015-08-19 13:41:51 -0700 | [diff] [blame] | 22 | |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 23 | #include <log/log.h> |
Tom Cherry | 70fadea | 2020-05-27 14:43:19 -0700 | [diff] [blame] | 24 | #include <log/log_read.h> |
Mark Salyzyn | 1a240b4 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 25 | |
Tom Cherry | 70fadea | 2020-05-27 14:43:19 -0700 | [diff] [blame] | 26 | #include "LogWriter.h" |
Tom Cherry | 283c9a1 | 2020-05-14 19:25:05 -0700 | [diff] [blame] | 27 | |
Tom Cherry | 855c7c8 | 2020-05-28 12:38:21 -0700 | [diff] [blame^] | 28 | // A mask to represent which log buffers a reader is watching, values are (1 << LOG_ID_MAIN), etc. |
| 29 | using LogMask = uint32_t; |
| 30 | constexpr uint32_t kLogMaskAll = 0xFFFFFFFF; |
| 31 | |
| 32 | // State that a LogBuffer may want to persist across calls to FlushTo(). |
| 33 | class FlushToState { |
| 34 | public: |
| 35 | FlushToState(uint64_t start, LogMask log_mask) : start_(start), log_mask_(log_mask) {} |
| 36 | virtual ~FlushToState() {} |
| 37 | |
| 38 | uint64_t start() const { return start_; } |
| 39 | void set_start(uint64_t start) { start_ = start; } |
| 40 | |
| 41 | LogMask log_mask() const { return log_mask_; } |
| 42 | |
| 43 | private: |
| 44 | uint64_t start_; |
| 45 | LogMask log_mask_; |
| 46 | }; |
| 47 | |
| 48 | // Enum for the return values of the `filter` function passed to FlushTo(). |
Tom Cherry | 3e61a13 | 2020-05-27 10:46:37 -0700 | [diff] [blame] | 49 | enum class FilterResult { |
Tom Cherry | 68630a0 | 2020-05-11 16:29:29 -0700 | [diff] [blame] | 50 | kSkip, |
| 51 | kStop, |
| 52 | kWrite, |
| 53 | }; |
| 54 | |
Tom Cherry | 3096818 | 2019-06-28 13:37:10 -0700 | [diff] [blame] | 55 | class LogBuffer { |
Tom Cherry | 68630a0 | 2020-05-11 16:29:29 -0700 | [diff] [blame] | 56 | public: |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 57 | virtual ~LogBuffer() {} |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 58 | |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 59 | virtual void Init() = 0; |
| 60 | |
| 61 | virtual int Log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, |
| 62 | const char* msg, uint16_t len) = 0; |
Tom Cherry | 855c7c8 | 2020-05-28 12:38:21 -0700 | [diff] [blame^] | 63 | |
| 64 | virtual std::unique_ptr<FlushToState> CreateFlushToState(uint64_t start, LogMask log_mask) = 0; |
| 65 | virtual bool FlushTo(LogWriter* writer, FlushToState& state, |
| 66 | const std::function<FilterResult(log_id_t log_id, pid_t pid, |
| 67 | uint64_t sequence, log_time realtime, |
| 68 | uint16_t dropped_count)>& filter) = 0; |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 69 | |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 70 | virtual bool Clear(log_id_t id, uid_t uid) = 0; |
| 71 | virtual unsigned long GetSize(log_id_t id) = 0; |
| 72 | virtual int SetSize(log_id_t id, unsigned long size) = 0; |
Tom Cherry | a3c5ff5 | 2020-05-21 13:56:33 -0700 | [diff] [blame] | 73 | |
| 74 | virtual uint64_t sequence() const = 0; |
Tom Cherry | 855c7c8 | 2020-05-28 12:38:21 -0700 | [diff] [blame^] | 75 | }; |