diff options
author | Daniel Lezcano <daniel.lezcano@linaro.org> | 2023-07-05 18:41:07 +0200 |
---|---|---|
committer | Daniel Lezcano <daniel.lezcano@linaro.org> | 2023-07-05 18:44:34 +0200 |
commit | d9d5e360c6c7436531116ac531576f3181f5d155 (patch) | |
tree | 82b9d038f418a967d4bc8ca6a4a088d3652ff2a1 | |
parent | 6cae8a9754196d85d9ab66d3ec4cb29da3cbf7ec (diff) |
When starting the service, at starting it will show up an error saying
it failed to parse the file Line 9.
Change the code to directly parse the file instead of passing through
an intermediate buffer.
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-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: |