Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 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 SECTIONS_H |
| 18 | #define SECTIONS_H |
| 19 | |
| 20 | #include "FdBuffer.h" |
| 21 | |
| 22 | #include <utils/String8.h> |
| 23 | #include <utils/String16.h> |
| 24 | #include <utils/Vector.h> |
| 25 | |
| 26 | using namespace android; |
| 27 | |
| 28 | /** |
| 29 | * Base class for sections |
| 30 | */ |
| 31 | class Section |
| 32 | { |
| 33 | public: |
| 34 | int id; |
| 35 | String8 name; |
| 36 | |
| 37 | Section(int id); |
| 38 | virtual ~Section(); |
| 39 | |
| 40 | virtual status_t Execute(ReportRequestSet* requests) const = 0; |
| 41 | |
| 42 | status_t WriteHeader(ReportRequestSet* requests, size_t size) const; |
| 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * Section that reads in a file. |
| 47 | */ |
| 48 | class FileSection : public Section |
| 49 | { |
| 50 | public: |
| 51 | FileSection(int id, const char* filename); |
| 52 | virtual ~FileSection(); |
| 53 | |
| 54 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 55 | |
| 56 | private: |
| 57 | const char* mFilename; |
| 58 | }; |
| 59 | |
| 60 | /** |
| 61 | * Base class for sections that call a command that might need a timeout. |
| 62 | */ |
| 63 | class WorkerThreadSection : public Section |
| 64 | { |
| 65 | public: |
| 66 | WorkerThreadSection(int id); |
| 67 | virtual ~WorkerThreadSection(); |
| 68 | |
| 69 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 70 | |
| 71 | virtual status_t BlockingCall(int pipeWriteFd) const = 0; |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * Section that forks and execs a command, and puts stdout as the section. |
| 76 | */ |
| 77 | class CommandSection : public Section |
| 78 | { |
| 79 | public: |
| 80 | CommandSection(int id, const char* first, ...); |
| 81 | virtual ~CommandSection(); |
| 82 | |
| 83 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 84 | |
| 85 | private: |
| 86 | const char** mCommand; |
| 87 | }; |
| 88 | |
| 89 | /** |
| 90 | * Section that calls dumpsys on a system service. |
| 91 | */ |
| 92 | class DumpsysSection : public WorkerThreadSection |
| 93 | { |
| 94 | public: |
| 95 | DumpsysSection(int id, const char* service, ...); |
| 96 | virtual ~DumpsysSection(); |
| 97 | |
| 98 | virtual status_t BlockingCall(int pipeWriteFd) const; |
| 99 | |
| 100 | private: |
| 101 | String16 mService; |
| 102 | Vector<String16> mArgs; |
| 103 | }; |
| 104 | |
| 105 | #endif // SECTIONS_H |
| 106 | |