Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012-2014 The Android Open Source Project |
| 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 | |
| 17 | #ifndef _LOGD_LOG_BUFFER_H__ |
| 18 | #define _LOGD_LOG_BUFFER_H__ |
| 19 | |
| 20 | #include <sys/types.h> |
| 21 | |
| 22 | #include <log/log.h> |
| 23 | #include <sysutils/SocketClient.h> |
| 24 | #include <utils/List.h> |
| 25 | |
| 26 | #include "LogBufferElement.h" |
| 27 | #include "LogTimes.h" |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame^] | 28 | #include "LogStatistics.h" |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 29 | |
| 30 | typedef android::List<LogBufferElement *> LogBufferElementCollection; |
| 31 | |
| 32 | class LogBuffer { |
| 33 | LogBufferElementCollection mLogElements; |
| 34 | pthread_mutex_t mLogElementsLock; |
| 35 | |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame^] | 36 | LogStatistics stats; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 37 | |
| 38 | public: |
| 39 | LastLogTimes &mTimes; |
| 40 | |
| 41 | LogBuffer(LastLogTimes *times); |
| 42 | |
Mark Salyzyn | 7139117 | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 43 | void log(log_id_t log_id, log_time realtime, |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 44 | uid_t uid, pid_t pid, const char *msg, unsigned short len); |
Mark Salyzyn | 7139117 | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 45 | log_time flushTo(SocketClient *writer, const log_time start, |
| 46 | bool privileged, |
| 47 | bool (*filter)(const LogBufferElement *element, void *arg) = NULL, |
| 48 | void *arg = NULL); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 49 | |
| 50 | void clear(log_id_t id); |
| 51 | unsigned long getSize(log_id_t id); |
| 52 | unsigned long getSizeUsed(log_id_t id); |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame^] | 53 | // *strp uses malloc, use free to release. |
| 54 | size_t formatStatistics(char **strp, uid_t uid, unsigned int logMask); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 55 | |
| 56 | private: |
| 57 | void maybePrune(log_id_t id); |
| 58 | void prune(log_id_t id, unsigned long pruneRows); |
| 59 | |
| 60 | }; |
| 61 | |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame^] | 62 | #endif // _LOGD_LOG_BUFFER_H__ |