From 3096818c8e1611b1a21d480ecca3d54761e33e1e Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Fri, 28 Jun 2019 13:37:10 -0700 Subject: [PATCH] Revert "Modularize logd." logd isn't meant to be modularized. The previous user was using a small subset of LogListener.cpp, which is now copied into their project. Test: liblog, logd unit tests This reverts commit fafea32468e0d59c1ce2eb845dd07a0b4e746cf0. Change-Id: I05ec764db2d9395f2d5b69a1a610c9c55240ab3a --- logd/Android.bp | 1 - logd/LogBuffer.h | 9 ++++----- logd/LogBufferInterface.cpp | 21 ------------------- logd/LogBufferInterface.h | 40 ------------------------------------- logd/LogListener.cpp | 16 ++++++--------- logd/LogListener.h | 4 ++-- 6 files changed, 12 insertions(+), 79 deletions(-) delete mode 100644 logd/LogBufferInterface.cpp delete mode 100644 logd/LogBufferInterface.h diff --git a/logd/Android.bp b/logd/Android.bp index 9b8625821..b337b7c2a 100644 --- a/logd/Android.bp +++ b/logd/Android.bp @@ -39,7 +39,6 @@ cc_library_static { "FlushCommand.cpp", "LogBuffer.cpp", "LogBufferElement.cpp", - "LogBufferInterface.cpp", "LogTimes.cpp", "LogStatistics.cpp", "LogWhiteBlackList.cpp", diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h index 404433fb6..c2d5b9734 100644 --- a/logd/LogBuffer.h +++ b/logd/LogBuffer.h @@ -27,7 +27,6 @@ #include #include "LogBufferElement.h" -#include "LogBufferInterface.h" #include "LogStatistics.h" #include "LogTags.h" #include "LogTimes.h" @@ -75,7 +74,7 @@ static bool isMonotonic(const log_time& mono) { typedef std::list LogBufferElementCollection; -class LogBuffer : public LogBufferInterface { +class LogBuffer { LogBufferElementCollection mLogElements; pthread_rwlock_t mLogElementsLock; @@ -108,14 +107,14 @@ class LogBuffer : public LogBufferInterface { LastLogTimes& mTimes; explicit LogBuffer(LastLogTimes* times); - ~LogBuffer() override; + ~LogBuffer(); void init(); bool isMonotonic() { return monotonic; } - int log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, - const char* msg, uint16_t len) override; + int log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, const char* msg, + uint16_t len); // lastTid is an optional context to help detect if the last previous // valid message was from the same source so we can differentiate chatty // filter types (identical or expired) diff --git a/logd/LogBufferInterface.cpp b/logd/LogBufferInterface.cpp deleted file mode 100644 index 66b3ab420..000000000 --- a/logd/LogBufferInterface.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "LogBufferInterface.h" - -LogBufferInterface::LogBufferInterface() { -} -LogBufferInterface::~LogBufferInterface() {} \ No newline at end of file diff --git a/logd/LogBufferInterface.h b/logd/LogBufferInterface.h deleted file mode 100644 index 2bb08f926..000000000 --- a/logd/LogBufferInterface.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2012-2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _LOGD_LOG_BUFFER_INTERFACE_H__ -#define _LOGD_LOG_BUFFER_INTERFACE_H__ - -#include - -#include -#include -#include - -// Abstract interface that handles log when log available. -class LogBufferInterface { - public: - LogBufferInterface(); - virtual ~LogBufferInterface(); - // Handles a log entry when available in LogListener. - // Returns the size of the handled log message. - virtual int log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, - pid_t tid, const char* msg, uint16_t len) = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(LogBufferInterface); -}; - -#endif // _LOGD_LOG_BUFFER_INTERFACE_H__ diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp index 7f78e1991..443570fd3 100644 --- a/logd/LogListener.cpp +++ b/logd/LogListener.cpp @@ -30,9 +30,8 @@ #include "LogListener.h" #include "LogUtils.h" -LogListener::LogListener(LogBufferInterface* buf, LogReader* reader) - : SocketListener(getLogSocket(), false), logbuf(buf), reader(reader) { -} +LogListener::LogListener(LogBuffer* buf, LogReader* reader) + : SocketListener(getLogSocket(), false), logbuf(buf), reader(reader) {} bool LogListener::onDataAvailable(SocketClient* cli) { static bool name_set; @@ -107,13 +106,10 @@ bool LogListener::onDataAvailable(SocketClient* cli) { // NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a // truncated message to the logs. - if (logbuf != nullptr) { - int res = logbuf->log( - logId, header->realtime, cred->uid, cred->pid, header->tid, msg, - ((size_t)n <= UINT16_MAX) ? (uint16_t)n : UINT16_MAX); - if (res > 0 && reader != nullptr) { - reader->notifyNewLog(static_cast(1 << logId)); - } + int res = logbuf->log(logId, header->realtime, cred->uid, cred->pid, header->tid, msg, + ((size_t)n <= UINT16_MAX) ? (uint16_t)n : UINT16_MAX); + if (res > 0) { + reader->notifyNewLog(static_cast(1 << logId)); } return true; diff --git a/logd/LogListener.h b/logd/LogListener.h index e16c5fb62..8fe3da46d 100644 --- a/logd/LogListener.h +++ b/logd/LogListener.h @@ -21,11 +21,11 @@ #include "LogReader.h" class LogListener : public SocketListener { - LogBufferInterface* logbuf; + LogBuffer* logbuf; LogReader* reader; public: - LogListener(LogBufferInterface* buf, LogReader* reader /* nullable */); + LogListener(LogBuffer* buf, LogReader* reader); protected: virtual bool onDataAvailable(SocketClient* cli);