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>
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 @@
// 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 @@
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);
+}
+
}
}
}
diff --git a/control/zone.hpp b/control/zone.hpp
index feaa8c8..3774d76 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -622,6 +622,12 @@
void saveCurrentMode();
/**
+ * @brief Restore persisted thermal control current mode property
+ * value, setting the mode to "Default" otherwise
+ */
+ void restoreCurrentMode();
+
+ /**
* @brief Get the request speed base if defined, otherwise the
* the current target speed is returned
*