| Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 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 LOGREADER_H |
| 18 | #define LOGREADER_H |
| 19 | |
| 20 | #include <log/log_read.h> |
| 21 | |
| 22 | #include <utils/RefBase.h> |
| 23 | |
| 24 | #include <vector> |
| 25 | |
| 26 | /** |
| 27 | * Callback for LogReader |
| 28 | */ |
| 29 | class LogListener : public virtual android::RefBase |
| 30 | { |
| 31 | public: |
| 32 | LogListener(); |
| 33 | virtual ~LogListener(); |
| 34 | |
| 35 | // TODO: Rather than using log_msg, which doesn't have any real internal structure |
| 36 | // here, we should pull this out into our own LogEntry class. |
| 37 | virtual void OnLogEvent(const log_msg& msg) = 0; |
| 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * Class to read logs from logd. |
| 42 | */ |
| 43 | class LogReader : public virtual android::RefBase |
| 44 | { |
| 45 | public: |
| 46 | /** |
| 47 | * Construct the LogReader with a pointer back to the StatsService |
| 48 | */ |
| 49 | LogReader(); |
| 50 | |
| 51 | /** |
| 52 | * Destructor. |
| 53 | */ |
| 54 | virtual ~LogReader(); |
| 55 | |
| 56 | /** |
| 57 | * Add a LogListener class. |
| 58 | */ |
| 59 | void AddListener(const android::sp<LogListener>& listener); |
| 60 | |
| 61 | /** |
| 62 | * Run the main LogReader loop |
| 63 | */ |
| 64 | void Run(); |
| 65 | |
| 66 | private: |
| 67 | /** |
| 68 | * List of listeners to call back on when we do get an event. |
| 69 | */ |
| 70 | std::vector<android::sp<LogListener> > m_listeners; |
| 71 | |
| 72 | /** |
| 73 | * Connect to a single instance of logd, and read until there's a read error. |
| 74 | * Logd can crash, exit, be killed etc. |
| 75 | * |
| 76 | * Returns the number of lines that were read. |
| 77 | */ |
| 78 | int connect_and_read(); |
| 79 | }; |
| 80 | |
| 81 | #endif // LOGREADER_H |