Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1 | /* |
Tom Cherry | 0281b20 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 2 | * Copyright (C) 2020 The Android Open Source Project |
Mark Salyzyn | 12bac90 | 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 | 04ad458 | 2020-05-01 16:13:18 -0700 | [diff] [blame] | 17 | #pragma once |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 18 | |
| 19 | #include <sys/types.h> |
| 20 | |
Tom Cherry | 0281b20 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 21 | #include <functional> |
Tom Cherry | 154b63a | 2020-10-05 11:35:59 -0700 | [diff] [blame] | 22 | #include <memory> |
Mark Salyzyn | 9a400aa | 2015-08-19 13:41:51 -0700 | [diff] [blame] | 23 | |
Tom Cherry | c5c9eba | 2020-10-06 10:22:35 -0700 | [diff] [blame] | 24 | #include <android-base/thread_annotations.h> |
Tom Cherry | 0281b20 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 25 | #include <log/log.h> |
Tom Cherry | baa25a2 | 2020-05-27 14:43:19 -0700 | [diff] [blame] | 26 | #include <log/log_read.h> |
Mark Salyzyn | 276d535 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 27 | |
Tom Cherry | baa25a2 | 2020-05-27 14:43:19 -0700 | [diff] [blame] | 28 | #include "LogWriter.h" |
Tom Cherry | c5c9eba | 2020-10-06 10:22:35 -0700 | [diff] [blame] | 29 | #include "LogdLock.h" |
Tom Cherry | adf2e44 | 2020-05-14 19:25:05 -0700 | [diff] [blame] | 30 | |
Tom Cherry | d444ab4 | 2020-05-28 12:38:21 -0700 | [diff] [blame] | 31 | // A mask to represent which log buffers a reader is watching, values are (1 << LOG_ID_MAIN), etc. |
| 32 | using LogMask = uint32_t; |
| 33 | constexpr uint32_t kLogMaskAll = 0xFFFFFFFF; |
| 34 | |
| 35 | // State that a LogBuffer may want to persist across calls to FlushTo(). |
| 36 | class FlushToState { |
| 37 | public: |
| 38 | FlushToState(uint64_t start, LogMask log_mask) : start_(start), log_mask_(log_mask) {} |
| 39 | virtual ~FlushToState() {} |
| 40 | |
| 41 | uint64_t start() const { return start_; } |
| 42 | void set_start(uint64_t start) { start_ = start; } |
| 43 | |
| 44 | LogMask log_mask() const { return log_mask_; } |
| 45 | |
| 46 | private: |
| 47 | uint64_t start_; |
| 48 | LogMask log_mask_; |
| 49 | }; |
| 50 | |
| 51 | // Enum for the return values of the `filter` function passed to FlushTo(). |
Tom Cherry | c92cbf6 | 2020-05-27 10:46:37 -0700 | [diff] [blame] | 52 | enum class FilterResult { |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame] | 53 | kSkip, |
| 54 | kStop, |
| 55 | kWrite, |
| 56 | }; |
| 57 | |
Tom Cherry | c49573f | 2019-06-28 13:37:10 -0700 | [diff] [blame] | 58 | class LogBuffer { |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame] | 59 | public: |
Tom Cherry | 0281b20 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 60 | virtual ~LogBuffer() {} |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 61 | |
Tom Cherry | 0281b20 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 62 | virtual void Init() = 0; |
| 63 | |
| 64 | virtual int Log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, |
| 65 | const char* msg, uint16_t len) = 0; |
Tom Cherry | d444ab4 | 2020-05-28 12:38:21 -0700 | [diff] [blame] | 66 | |
Tom Cherry | c5c9eba | 2020-10-06 10:22:35 -0700 | [diff] [blame] | 67 | virtual std::unique_ptr<FlushToState> CreateFlushToState(uint64_t start, LogMask log_mask) |
| 68 | REQUIRES(logd_lock) = 0; |
Tom Cherry | ca4b25d | 2020-05-28 20:02:42 -0700 | [diff] [blame] | 69 | virtual bool FlushTo( |
| 70 | LogWriter* writer, FlushToState& state, |
| 71 | const std::function<FilterResult(log_id_t log_id, pid_t pid, uint64_t sequence, |
Tom Cherry | c5c9eba | 2020-10-06 10:22:35 -0700 | [diff] [blame] | 72 | log_time realtime)>& filter) REQUIRES(logd_lock) = 0; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 73 | |
Tom Cherry | 0281b20 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 74 | virtual bool Clear(log_id_t id, uid_t uid) = 0; |
Tom Cherry | 8022895 | 2020-08-05 12:14:45 -0700 | [diff] [blame] | 75 | virtual size_t GetSize(log_id_t id) = 0; |
| 76 | virtual bool SetSize(log_id_t id, size_t size) = 0; |
Tom Cherry | 0bf66db | 2020-05-21 13:56:33 -0700 | [diff] [blame] | 77 | |
| 78 | virtual uint64_t sequence() const = 0; |
Tom Cherry | d444ab4 | 2020-05-28 12:38:21 -0700 | [diff] [blame] | 79 | }; |