diff options
author | Jason M. Bills <jason.m.bills@linux.intel.com> | 2019-06-25 21:31:22 +0300 |
---|---|---|
committer | Jason M. Bills <jason.m.bills@linux.intel.com> | 2019-06-25 21:38:05 +0300 |
commit | 25bfc30210642cad62103974fbcb25efba50bace (patch) | |
tree | e84825f99282b00f2a4af245151287ecdb133725 /settings | |
parent | 525175aea621c9d85c78c6bdea9c3c9bd2e07991 (diff) | |
download | provingground-25bfc30210642cad62103974fbcb25efba50bace.tar.xz |
Add option for settings that do not persist
This change adds a flag that allows a setting to not persist.
Tested:
Verified that a setting that is set to not persist gets created
with the default value on each boot.
Combined with the AC Boot parameter change, this makes the power
restore policy behave as expected.
Change-Id: I0a8e8237864ab7ab315c0be6df23b424f0a1ccb3
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
Diffstat (limited to 'settings')
-rw-r--r-- | settings/include/interface.hpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/settings/include/interface.hpp b/settings/include/interface.hpp index 987f8e4..b7d5525 100644 --- a/settings/include/interface.hpp +++ b/settings/include/interface.hpp @@ -115,12 +115,15 @@ struct SettingsInterface } // specialization for char * as std::string is the nlohmann type - void addProperty(const std::string &name, const char *value) + void addProperty(const std::string &name, const char *value, + const bool persist = true) { - addProperty(name, std::string(value)); + addProperty(name, std::string(value), persist); } - template <typename T> void addProperty(const std::string &name, T value) + template <typename T> + void addProperty(const std::string &name, T value, + const bool persist = true) { std::ifstream current(std::string(prefix) + *path); @@ -154,8 +157,8 @@ struct SettingsInterface interface->register_property( name, value, - [path = std::shared_ptr<std::string>(path), name](const T &req, - T &old) { + [path = std::shared_ptr<std::string>(path), name, + persist](const T &req, T &old) { nlohmann::json data; { // context is here for raii to close the file @@ -172,17 +175,20 @@ struct SettingsInterface } } - data[name] = req; - std::filesystem::create_directories( - std::filesystem::path(std::string(prefix) + *path) - .parent_path()); - std::ofstream output(std::string(prefix) + *path); - if (!output.good()) + if (persist) { - std::cerr << "Cannot write data at " << *path << "\n"; - throw std::runtime_error("Persisting Error"); + data[name] = req; + std::filesystem::create_directories( + std::filesystem::path(std::string(prefix) + *path) + .parent_path()); + std::ofstream output(std::string(prefix) + *path); + if (!output.good()) + { + std::cerr << "Cannot write data at " << *path << "\n"; + throw std::runtime_error("Persisting Error"); + } + output << data; } - output << data; old = req; |