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 ANDROID_VINTF_KERNEL_CONFIG_PARSER_H_ 18 #define ANDROID_VINTF_KERNEL_CONFIG_PARSER_H_ 19 20 #include <iostream> 21 #include <map> 22 #include <sstream> 23 #include <string> 24 25 #include <utils/Errors.h> 26 27 namespace android { 28 namespace vintf { 29 30 class KernelConfigParser { 31 public: 32 KernelConfigParser(bool processComments = false, bool relaxedFormat = false); 33 34 status_t process(const char* buf, size_t len); 35 status_t finish(); 36 status_t processAndFinish(const char* buf, size_t len); 37 status_t processAndFinish(const std::string& content); 38 std::stringbuf* error() const; 39 std::map<std::string, std::string>& configs(); 40 const std::map<std::string, std::string>& configs() const; 41 42 private: 43 status_t processRemaining(); 44 std::map<std::string, std::string> mConfigs; 45 std::stringstream mError; 46 std::string mRemaining; 47 bool mProcessComments; 48 bool mRelaxedFormat; 49 }; 50 51 } // namespace vintf 52 } // namespace android 53 54 #endif // ANDROID_VINTF_KERNEL_CONFIG_PARSER_H_ 55