logd: refactor LastLogTimes a bit
There's still plenty of work that can be done here, particularly
re-doing the locking so each LogReaderThread does not mutually exclude
the others, but that's out of the scope here.
This change primarily removes the public 'mTimes' from LogBuffer and
creates a new LogReaderList class instead. It would have merged this
into LogReader, but that creates a circular dependency.
This change also removes the need to reference LogReader or
LogReaderList from LogAudit, LogKLog, and LogListener, instead relying
on LogBuffer()::log() to call LogReaderList::NotifyNewLog().
Test: logging unit tests
Change-Id: Ia874b57a9ec1254af1295bfa6f7af2f92a75755b
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index 3c1ea5a..efcd2af 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -27,13 +27,21 @@
#include <sysutils/SocketClient.h>
#include "LogBufferElement.h"
-#include "LogReaderThread.h"
#include "LogStatistics.h"
#include "LogTags.h"
#include "LogWhiteBlackList.h"
typedef std::list<LogBufferElement*> LogBufferElementCollection;
+class LogReaderList;
+class LogReaderThread;
+
+enum class FlushToResult {
+ kSkip,
+ kStop,
+ kWrite,
+};
+
class LogBuffer {
LogBufferElementCollection mLogElements;
pthread_rwlock_t mLogElementsLock;
@@ -53,10 +61,8 @@
LogBufferElement* droppedElements[LOG_ID_MAX];
void log(LogBufferElement* elem);
- public:
- LastLogTimes& mTimes;
-
- LogBuffer(LastLogTimes* times, LogTags* tags, PruneList* prune, LogStatistics* stats);
+ public:
+ LogBuffer(LogReaderList* reader_list, LogTags* tags, PruneList* prune, LogStatistics* stats);
~LogBuffer();
void init();
@@ -68,7 +74,7 @@
uint64_t flushTo(SocketClient* writer, uint64_t start,
pid_t* lastTid, // &lastTid[LOG_ID_MAX] or nullptr
bool privileged, bool security,
- const std::function<int(const LogBufferElement* element)>& filter);
+ const std::function<FlushToResult(const LogBufferElement* element)>& filter);
bool clear(log_id_t id, uid_t uid = AID_ROOT);
unsigned long getSize(log_id_t id);
@@ -96,6 +102,7 @@
// there are no logs for the given log type. Requires mLogElementsLock to be held.
LogBufferElementCollection::iterator GetOldest(log_id_t log_id);
+ LogReaderList* reader_list_;
LogTags* tags_;
PruneList* prune_;
LogStatistics* stats_;