diff options
author | Daniel Lezcano <daniel.lezcano@linaro.org> | 2023-07-05 18:45:02 +0200 |
---|---|---|
committer | Daniel Lezcano <daniel.lezcano@linaro.org> | 2023-07-05 18:45:02 +0200 |
commit | c2c8d2d07c34401e8c076c86ed2e1e391cbeab8c (patch) | |
tree | d6718712378e4e6779c6f2ae8e137712a9dde4a9 | |
parent | 7019c2c9a0f91e51f8129e133831f97b51e81d03 (diff) | |
parent | d9d5e360c6c7436531116ac531576f3181f5d155 (diff) |
Merge branch 'master' into dragonboarddragonboard
-rw-r--r-- | thermal/Config.cpp | 36 | ||||
-rw-r--r-- | thermal/Config.h | 3 |
2 files changed, 9 insertions, 30 deletions
diff --git a/thermal/Config.cpp b/thermal/Config.cpp index bfb2e39..c289c31 100644 --- a/thermal/Config.cpp +++ b/thermal/Config.cpp @@ -242,46 +242,28 @@ bool Config::readCoolingDevice(Json::Value &coolingDevice) return true; } -bool Config::readFile(const std::string path, std::stringstream &config) +bool Config::parseFile(std::string path, Json::Value &root) { - std::ifstream file; + Json::CharReaderBuilder builder; + std::string strerr; + std::ifstream ifs; LOG(DEBUG) << "Reading configuration file: " << path; - file.open(path); - if (!file) { + ifs.open(path); + if (!ifs) { LOG(ERROR) << "Failed to open: " << path; return false; } - - config << file.rdbuf(); - - LOG(DEBUG) << config.str(); - file.close(); - - return true; -} - -bool Config::parseFile(std::string path, Json::Value &root) -{ - std::stringstream config; - std::string strerr; - - Json::CharReaderBuilder builder; - std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); - - if (!readFile(path, config)) { - LOG(ERROR) << "Failed to read configuration file"; - return false; - } - - if (!reader->parse(&*config.str().begin(), &*config.str().end(), &root, &strerr)) { + if (!parseFromStream(builder, ifs, &root, &strerr)) { LOG(ERROR) << "Failed to parse JSON config: " << strerr; return false; } LOG(DEBUG) << "Configuration file parsed successfully"; + + ifs.close(); return true; } diff --git a/thermal/Config.h b/thermal/Config.h index 35186d8..0ea48bf 100644 --- a/thermal/Config.h +++ b/thermal/Config.h @@ -67,9 +67,6 @@ private: bool readSensor(Json::Value &sensor); - bool readFile(const std::string path, - std::stringstream &config); - bool parseFile(std::string path, Json::Value &root); public: |