Save properties to persistent storage when host is on
1. When host is on, set properties as requested properties instead
of notify listeners;
2. When host becomes off, and requested properties are not empty, notify
the listners and reset the requested properties.
Add unit tests.
Change-Id: I9359c801c698df0c6e5eab43e12427bb5a6da611
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/host_epoch.cpp b/host_epoch.cpp
index f45581d..3b4c00e 100644
--- a/host_epoch.cpp
+++ b/host_epoch.cpp
@@ -1,9 +1,8 @@
#include "host_epoch.hpp"
+#include "utils.hpp"
#include <phosphor-logging/log.hpp>
-#include <fstream>
-
namespace phosphor
{
namespace time
@@ -14,7 +13,7 @@
HostEpoch::HostEpoch(sdbusplus::bus::bus& bus,
const char* objPath)
: EpochBase(bus, objPath),
- offset(readData<decltype(offset)::rep>(offsetFile))
+ offset(utils::readData<decltype(offset)::rep>(offsetFile))
{
// Empty
}
@@ -41,34 +40,12 @@
offset = time - getTime();
// Store the offset to file
- writeData(offsetFile, offset.count());
+ utils::writeData(offsetFile, offset.count());
server::EpochTime::elapsed(value);
return value;
}
-template <typename T>
-T HostEpoch::readData(const char* fileName)
-{
- T data{};
- std::ifstream fs(fileName);
- if (fs.is_open())
- {
- fs >> data;
- }
- return data;
-}
-
-template <typename T>
-void HostEpoch::writeData(const char* fileName, T&& data)
-{
- std::ofstream fs(fileName, std::ios::out);
- if (fs.is_open())
- {
- fs << std::forward<T>(data);
- }
-}
-
} // namespace time
} // namespace phosphor