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