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 "logd/LogListener.h" 21 22 #include <utils/RefBase.h> 23 24 #include <vector> 25 26 namespace android { 27 namespace os { 28 namespace statsd { 29 30 /** 31 * Class to read logs from logd. 32 */ 33 class LogReader : public virtual android::RefBase { 34 public: 35 /** 36 * Construct the LogReader with the event listener. (Which is StatsService) 37 */ 38 LogReader(const sp<LogListener>& listener); 39 40 /** 41 * Destructor. 42 */ 43 virtual ~LogReader(); 44 45 /** 46 * Run the main LogReader loop 47 */ 48 void Run(); 49 50 private: 51 /** 52 * Who is going to get the events when they're read. 53 */ 54 sp<LogListener> mListener; 55 56 /** 57 * Connect to a single instance of logd, and read until there's a read error. 58 * Logd can crash, exit, be killed etc. 59 * 60 * Returns the number of lines that were read. 61 */ 62 int connect_and_read(); 63 }; 64 65 } // namespace statsd 66 } // namespace os 67 } // namespace android 68 69 #endif // LOGREADER_H 70