Yi Jin | 0a3406f | 2017-06-22 19:23:11 -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 INCIDENT_HELPER_H |
| 18 | #define INCIDENT_HELPER_H |
| 19 | |
| 20 | #include <utils/Errors.h> |
| 21 | #include <utils/String8.h> |
| 22 | |
| 23 | using namespace android; |
| 24 | |
| 25 | /** |
| 26 | * Base class for text parser |
| 27 | */ |
| 28 | class TextParserBase { |
| 29 | public: |
| 30 | String8 name; |
| 31 | |
| 32 | TextParserBase(String8 name) : name(name) {}; |
| 33 | virtual ~TextParserBase() {}; |
| 34 | |
| 35 | virtual status_t Parse(const int in, const int out) const = 0; |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * This parser is used for testing only, results in timeout. |
| 40 | */ |
| 41 | class TimeoutParser : public TextParserBase { |
| 42 | public: |
| 43 | TimeoutParser() : TextParserBase(String8("TimeoutParser")) {}; |
| 44 | ~TimeoutParser() {}; |
| 45 | |
| 46 | virtual status_t Parse(const int /** in */, const int /** out */) const { while (true); }; |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * This parser is used for testing only, results in reversed input text. |
| 51 | */ |
| 52 | class ReverseParser : public TextParserBase { |
| 53 | public: |
| 54 | ReverseParser() : TextParserBase(String8("ReverseParser")) {}; |
| 55 | ~ReverseParser() {}; |
| 56 | |
| 57 | virtual status_t Parse(const int in, const int out) const; |
| 58 | }; |
| 59 | |
| 60 | /** |
| 61 | * Kernel wakeup sources parser, parses text to protobuf in /d/wakeup_sources |
| 62 | */ |
Yi Jin | 0a3406f | 2017-06-22 19:23:11 -0700 | [diff] [blame] | 63 | class KernelWakesParser : public TextParserBase { |
| 64 | public: |
| 65 | KernelWakesParser() : TextParserBase(String8("KernelWakeSources")) {}; |
| 66 | ~KernelWakesParser() {}; |
| 67 | |
| 68 | virtual status_t Parse(const int in, const int out) const; |
| 69 | }; |
| 70 | |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 71 | /** |
| 72 | * Procrank parser, parses text produced by command procrank |
| 73 | */ |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 74 | class ProcrankParser : public TextParserBase { |
| 75 | public: |
| 76 | ProcrankParser() : TextParserBase(String8("ProcrankParser")) {}; |
| 77 | ~ProcrankParser() {}; |
| 78 | |
| 79 | virtual status_t Parse(const int in, const int out) const; |
| 80 | }; |
| 81 | |
Yi Jin | 0a3406f | 2017-06-22 19:23:11 -0700 | [diff] [blame] | 82 | #endif // INCIDENT_HELPER_H |