| 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> | 
| Mark Salyzyn | 0dd4431 | 2016-09-28 15:54:45 -0700 | [diff] [blame] | 24 | #include <sysutils/SocketClient.h> | 
| Mark Salyzyn | 1a240b4 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 25 |  | 
| Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 26 | #include "LogBufferElement.h" | 
| Tom Cherry | 68630a0 | 2020-05-11 16:29:29 -0700 | [diff] [blame] | 27 |  | 
| Tom Cherry | 283c9a1 | 2020-05-14 19:25:05 -0700 | [diff] [blame] | 28 | class LogWriter; | 
|  | 29 |  | 
| Tom Cherry | 68630a0 | 2020-05-11 16:29:29 -0700 | [diff] [blame] | 30 | enum class FlushToResult { | 
|  | 31 | kSkip, | 
|  | 32 | kStop, | 
|  | 33 | kWrite, | 
|  | 34 | }; | 
|  | 35 |  | 
| Tom Cherry | 3096818 | 2019-06-28 13:37:10 -0700 | [diff] [blame] | 36 | class LogBuffer { | 
| Tom Cherry | 68630a0 | 2020-05-11 16:29:29 -0700 | [diff] [blame] | 37 | public: | 
| Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 38 | virtual ~LogBuffer() {} | 
| Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 39 |  | 
| Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 40 | virtual void Init() = 0; | 
|  | 41 |  | 
|  | 42 | virtual int Log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, | 
|  | 43 | const char* msg, uint16_t len) = 0; | 
| Mark Salyzyn | ae2abf1 | 2017-03-31 10:48:39 -0700 | [diff] [blame] | 44 | // lastTid is an optional context to help detect if the last previous | 
|  | 45 | // valid message was from the same source so we can differentiate chatty | 
|  | 46 | // filter types (identical or expired) | 
| Tom Cherry | 283c9a1 | 2020-05-14 19:25:05 -0700 | [diff] [blame] | 47 | static const uint64_t FLUSH_ERROR = 0; | 
| Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 48 | virtual uint64_t FlushTo( | 
| Tom Cherry | 283c9a1 | 2020-05-14 19:25:05 -0700 | [diff] [blame] | 49 | LogWriter* writer, uint64_t start, | 
| Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 50 | pid_t* last_tid,  // nullable | 
| Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 51 | const std::function<FlushToResult(const LogBufferElement* element)>& filter) = 0; | 
| Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 52 |  | 
| Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 53 | virtual bool Clear(log_id_t id, uid_t uid) = 0; | 
|  | 54 | virtual unsigned long GetSize(log_id_t id) = 0; | 
|  | 55 | virtual int SetSize(log_id_t id, unsigned long size) = 0; | 
|  | 56 | }; |