blob: 859d7400c250592acff176cd1f77e0d04b5ae1bf [file] [log] [blame]
Mark Salyzyn12bac902014-02-26 09:50:16 -08001/*
Tom Cherry0281b202020-05-12 13:16:41 -07002 * Copyright (C) 2020 The Android Open Source Project
Mark Salyzyn12bac902014-02-26 09:50:16 -08003 *
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 Cherry04ad4582020-05-01 16:13:18 -070017#pragma once
Mark Salyzyn12bac902014-02-26 09:50:16 -080018
19#include <sys/types.h>
20
Tom Cherry0281b202020-05-12 13:16:41 -070021#include <functional>
Mark Salyzyn9a400aa2015-08-19 13:41:51 -070022
Tom Cherry0281b202020-05-12 13:16:41 -070023#include <log/log.h>
Tom Cherrybaa25a22020-05-27 14:43:19 -070024#include <log/log_read.h>
Mark Salyzyn276d5352014-06-12 11:16:16 -070025
Tom Cherrybaa25a22020-05-27 14:43:19 -070026#include "LogWriter.h"
Tom Cherryadf2e442020-05-14 19:25:05 -070027
Tom Cherryc92cbf62020-05-27 10:46:37 -070028enum class FilterResult {
Tom Cherry5ecfbf02020-05-11 16:29:29 -070029 kSkip,
30 kStop,
31 kWrite,
32};
33
Tom Cherryc49573f2019-06-28 13:37:10 -070034class LogBuffer {
Tom Cherry5ecfbf02020-05-11 16:29:29 -070035 public:
Tom Cherry0281b202020-05-12 13:16:41 -070036 virtual ~LogBuffer() {}
Mark Salyzyn12bac902014-02-26 09:50:16 -080037
Tom Cherry0281b202020-05-12 13:16:41 -070038 virtual void Init() = 0;
39
40 virtual int Log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid,
41 const char* msg, uint16_t len) = 0;
Mark Salyzynbec7b2d2017-03-31 10:48:39 -070042 // lastTid is an optional context to help detect if the last previous
43 // valid message was from the same source so we can differentiate chatty
44 // filter types (identical or expired)
Tom Cherryadf2e442020-05-14 19:25:05 -070045 static const uint64_t FLUSH_ERROR = 0;
Tom Cherrybaa25a22020-05-27 14:43:19 -070046 virtual uint64_t FlushTo(LogWriter* writer, uint64_t start,
47 pid_t* last_tid, // nullable
48 const std::function<FilterResult(log_id_t log_id, pid_t pid,
49 uint64_t sequence, log_time realtime,
50 uint16_t dropped_count)>& filter) = 0;
Mark Salyzyn12bac902014-02-26 09:50:16 -080051
Tom Cherry0281b202020-05-12 13:16:41 -070052 virtual bool Clear(log_id_t id, uid_t uid) = 0;
53 virtual unsigned long GetSize(log_id_t id) = 0;
54 virtual int SetSize(log_id_t id, unsigned long size) = 0;
Tom Cherry0bf66db2020-05-21 13:56:33 -070055
56 virtual uint64_t sequence() const = 0;
Tom Cherry0281b202020-05-12 13:16:41 -070057};