| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 1 | /* |
| Andreas Gampe | 9590c64 | 2017-12-27 10:57:34 -0800 | [diff] [blame] | 2 | * |
| 3 | * Copyright 2015, The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 17 | |
| 18 | #ifndef SYSTEM_EXTRAS_PERFPROFD_CONFIGREADER_H_ |
| 19 | #define SYSTEM_EXTRAS_PERFPROFD_CONFIGREADER_H_ |
| 20 | |
| 21 | #include <string> |
| 22 | #include <map> |
| 23 | |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 24 | #include "config.h" |
| 25 | |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 26 | // |
| 27 | // This table describes the perfprofd config file syntax in terms of |
| 28 | // key/value pairs. Values come in two flavors: strings, or unsigned |
| 29 | // integers. In the latter case the reader sets allowable |
| 30 | // minimum/maximum for the setting. |
| 31 | // |
| 32 | class ConfigReader { |
| 33 | |
| 34 | public: |
| 35 | ConfigReader(); |
| 36 | ~ConfigReader(); |
| 37 | |
| 38 | // Ask for the current setting of a config item |
| 39 | unsigned getUnsignedValue(const char *key) const; |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 40 | bool getBoolValue(const char *key) const; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 41 | std::string getStringValue(const char *key) const; |
| 42 | |
| 43 | // read the specified config file, applying any settings it contains |
| 44 | // returns true for successful read, false if conf file cannot be opened. |
| 45 | bool readFile(); |
| 46 | |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 47 | bool Read(const std::string& data, bool fail_on_error); |
| 48 | |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 49 | // set/get path to config file |
| 50 | static void setConfigFilePath(const char *path); |
| 51 | static const char *getConfigFilePath(); |
| 52 | |
| 53 | // override a config item (for unit testing purposes) |
| 54 | void overrideUnsignedEntry(const char *key, unsigned new_value); |
| 55 | |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 56 | void FillConfig(Config* config); |
| 57 | |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 58 | private: |
| 59 | void addUnsignedEntry(const char *key, |
| 60 | unsigned default_value, |
| 61 | unsigned min_value, |
| 62 | unsigned max_value); |
| 63 | void addStringEntry(const char *key, const char *default_value); |
| 64 | void addDefaultEntries(); |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 65 | bool parseLine(const char *key, const char *value, unsigned linecount); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 66 | |
| 67 | typedef struct { unsigned minv, maxv; } values; |
| 68 | std::map<std::string, values> u_info; |
| 69 | std::map<std::string, unsigned> u_entries; |
| 70 | std::map<std::string, std::string> s_entries; |
| 71 | bool trace_config_read; |
| 72 | }; |
| 73 | |
| 74 | #endif |