| Colin Cross | 6310a82 | 2010-04-20 14:29:05 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2010 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 _INIT_INIT_PARSER_H_ | 
|  | 18 | #define _INIT_INIT_PARSER_H_ | 
|  | 19 |  | 
| Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 20 | #include <map> | 
| Yabin Cui | 00ede7d | 2015-07-24 13:26:04 -0700 | [diff] [blame] | 21 | #include <string> | 
| Tom Cherry | bac3299 | 2015-07-31 12:45:25 -0700 | [diff] [blame] | 22 | #include <vector> | 
| Yabin Cui | 00ede7d | 2015-07-24 13:26:04 -0700 | [diff] [blame] | 23 |  | 
| Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 24 | class SectionParser { | 
|  | 25 | public: | 
|  | 26 | virtual ~SectionParser() { | 
|  | 27 | } | 
|  | 28 | virtual bool ParseSection(const std::vector<std::string>& args, | 
|  | 29 | std::string* err) = 0; | 
|  | 30 | virtual bool ParseLineSection(const std::vector<std::string>& args, | 
|  | 31 | const std::string& filename, int line, | 
|  | 32 | std::string* err) const = 0; | 
|  | 33 | virtual void EndSection() = 0; | 
|  | 34 | virtual void EndFile(const std::string& filename) = 0; | 
|  | 35 | }; | 
| Colin Cross | 6310a82 | 2010-04-20 14:29:05 -0700 | [diff] [blame] | 36 |  | 
| Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 37 | class Parser { | 
|  | 38 | public: | 
|  | 39 | static Parser& GetInstance(); | 
|  | 40 | void DumpState() const; | 
|  | 41 | bool ParseConfig(const std::string& path); | 
|  | 42 | void AddSectionParser(const std::string& name, | 
|  | 43 | std::unique_ptr<SectionParser> parser); | 
| Jaekyun Seok | 4ec72cc | 2017-02-22 20:37:57 +0900 | [diff] [blame] | 44 | void set_is_system_etc_init_loaded(bool loaded) { | 
|  | 45 | is_system_etc_init_loaded_ = loaded; | 
|  | 46 | } | 
|  | 47 | void set_is_vendor_etc_init_loaded(bool loaded) { | 
|  | 48 | is_vendor_etc_init_loaded_ = loaded; | 
|  | 49 | } | 
|  | 50 | void set_is_odm_etc_init_loaded(bool loaded) { | 
|  | 51 | is_odm_etc_init_loaded_ = loaded; | 
|  | 52 | } | 
|  | 53 | bool is_system_etc_init_loaded() { return is_system_etc_init_loaded_; } | 
|  | 54 | bool is_vendor_etc_init_loaded() { return is_vendor_etc_init_loaded_; } | 
|  | 55 | bool is_odm_etc_init_loaded() { return is_odm_etc_init_loaded_; } | 
| Colin Cross | 6310a82 | 2010-04-20 14:29:05 -0700 | [diff] [blame] | 56 |  | 
| Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 57 | private: | 
|  | 58 | Parser(); | 
|  | 59 |  | 
|  | 60 | void ParseData(const std::string& filename, const std::string& data); | 
|  | 61 | bool ParseConfigFile(const std::string& path); | 
|  | 62 | bool ParseConfigDir(const std::string& path); | 
|  | 63 |  | 
|  | 64 | std::map<std::string, std::unique_ptr<SectionParser>> section_parsers_; | 
| Jaekyun Seok | 4ec72cc | 2017-02-22 20:37:57 +0900 | [diff] [blame] | 65 | bool is_system_etc_init_loaded_ = false; | 
|  | 66 | bool is_vendor_etc_init_loaded_ = false; | 
|  | 67 | bool is_odm_etc_init_loaded_ = false; | 
| Tom Cherry | b734990 | 2015-08-26 11:43:36 -0700 | [diff] [blame] | 68 | }; | 
| Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 69 |  | 
| Colin Cross | 6310a82 | 2010-04-20 14:29:05 -0700 | [diff] [blame] | 70 | #endif |