blob: 6935fdf758467a73ae0a7acbd43ed4e0120a1f6d [file] [log] [blame]
Colin Cross6310a822010-04-20 14:29:05 -07001/*
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 Cherryb7349902015-08-26 11:43:36 -070020#include <map>
Tom Cherry3f5eaae52017-04-06 16:30:22 -070021#include <memory>
Yabin Cui00ede7d2015-07-24 13:26:04 -070022#include <string>
Tom Cherrybac32992015-07-31 12:45:25 -070023#include <vector>
Yabin Cui00ede7d2015-07-24 13:26:04 -070024
Tom Cherryb7349902015-08-26 11:43:36 -070025class SectionParser {
26public:
27 virtual ~SectionParser() {
28 }
29 virtual bool ParseSection(const std::vector<std::string>& args,
30 std::string* err) = 0;
31 virtual bool ParseLineSection(const std::vector<std::string>& args,
32 const std::string& filename, int line,
33 std::string* err) const = 0;
34 virtual void EndSection() = 0;
35 virtual void EndFile(const std::string& filename) = 0;
36};
Colin Cross6310a822010-04-20 14:29:05 -070037
Tom Cherryb7349902015-08-26 11:43:36 -070038class Parser {
39public:
40 static Parser& GetInstance();
41 void DumpState() const;
42 bool ParseConfig(const std::string& path);
43 void AddSectionParser(const std::string& name,
44 std::unique_ptr<SectionParser> parser);
Jaekyun Seok4ec72cc2017-02-22 20:37:57 +090045 void set_is_system_etc_init_loaded(bool loaded) {
46 is_system_etc_init_loaded_ = loaded;
47 }
48 void set_is_vendor_etc_init_loaded(bool loaded) {
49 is_vendor_etc_init_loaded_ = loaded;
50 }
51 void set_is_odm_etc_init_loaded(bool loaded) {
52 is_odm_etc_init_loaded_ = loaded;
53 }
54 bool is_system_etc_init_loaded() { return is_system_etc_init_loaded_; }
55 bool is_vendor_etc_init_loaded() { return is_vendor_etc_init_loaded_; }
56 bool is_odm_etc_init_loaded() { return is_odm_etc_init_loaded_; }
Colin Cross6310a822010-04-20 14:29:05 -070057
Tom Cherryb7349902015-08-26 11:43:36 -070058private:
59 Parser();
60
61 void ParseData(const std::string& filename, const std::string& data);
62 bool ParseConfigFile(const std::string& path);
63 bool ParseConfigDir(const std::string& path);
64
65 std::map<std::string, std::unique_ptr<SectionParser>> section_parsers_;
Jaekyun Seok4ec72cc2017-02-22 20:37:57 +090066 bool is_system_etc_init_loaded_ = false;
67 bool is_vendor_etc_init_loaded_ = false;
68 bool is_odm_etc_init_loaded_ = false;
Tom Cherryb7349902015-08-26 11:43:36 -070069};
Elliott Hughes8d82ea02015-02-06 20:15:18 -080070
Colin Cross6310a822010-04-20 14:29:05 -070071#endif