diff options
author | Matthew Barth <msbarth@us.ibm.com> | 2019-01-21 13:08:02 -0600 |
---|---|---|
committer | Matthew Barth <msbarth@us.ibm.com> | 2019-02-13 14:31:44 -0600 |
commit | 9e4db25cdf7d02878aab1d485b20235c147fbe4a (patch) | |
tree | 550a86e2993dbb063e48a014443487035ac3fef7 /control/zone.cpp | |
parent | cc8912e93eb55e938b5cdb189a70d1f342fb49ea (diff) | |
download | phosphor-fan-presence-9e4db25cdf7d02878aab1d485b20235c147fbe4a.tar.gz phosphor-fan-presence-9e4db25cdf7d02878aab1d485b20235c147fbe4a.zip |
Restore current mode property
When the fan control zone is created, the current mode property is
restored from persistent storage. If the persistent storage file does
not exist or fails to be read, the current mode property is set to
default.
Change-Id: I5ba699f9b6683aea4f39444eace8c7d19a22c92d
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'control/zone.cpp')
-rw-r--r-- | control/zone.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/control/zone.cpp b/control/zone.cpp index 7d836ba..8408e8d 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -71,7 +71,8 @@ Zone::Zone(Mode mode, // Do not enable set speed events when in init mode if (mode == Mode::control) { - // TODO Determine thermal control mode states + // Restore thermal control current mode state + restoreCurrentMode(); // Emit objects added in control mode only this->emit_object_added(); @@ -614,6 +615,33 @@ void Zone::saveCurrentMode() oArch(ThermalObject::current()); } +void Zone::restoreCurrentMode() +{ + std::string current = "Default"; + fs::path path{CONTROL_PERSIST_ROOT_PATH}; + path /= std::to_string(_zoneNum); + path /= "CurrentMode"; + fs::create_directories(path.parent_path()); + + try + { + if (fs::exists(path)) + { + std::ifstream ifs(path.c_str(), std::ios::in | std::ios::binary); + cereal::JSONInputArchive iArch(ifs); + iArch(current); + } + } + catch (std::exception& e) + { + log<level::ERR>(e.what()); + fs::remove(path); + current = "Default"; + } + + this->current(current); +} + } } } |