Remove the inheritance between epoch base and bmc epoch
The epoch_base exists because it was managing bmc_time and host_time
before, and now the host_time has been removed, so the dependency on
epoch_base and bmc_epoch should be removed.
Tested: Built phosphor-time-manager successfully and CI passed.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Iff87f18d450095f8a673b2d73c50092c65adca20
diff --git a/bmc_epoch.cpp b/bmc_epoch.cpp
index 9fc3097..db4051a 100644
--- a/bmc_epoch.cpp
+++ b/bmc_epoch.cpp
@@ -9,6 +9,7 @@
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/Time/error.hpp>
// Need to do this since its not exported outside of the kernel.
// Refer : https://gist.github.com/lethean/446cea944b7441228298
@@ -23,15 +24,17 @@
{
namespace time
{
+namespace // anonymous
+{
+constexpr auto SYSTEMD_TIME_SERVICE = "org.freedesktop.timedate1";
+constexpr auto SYSTEMD_TIME_PATH = "/org/freedesktop/timedate1";
+constexpr auto SYSTEMD_TIME_INTERFACE = "org.freedesktop.timedate1";
+constexpr auto METHOD_SET_TIME = "SetTime";
+} // namespace
+
namespace server = sdbusplus::xyz::openbmc_project::Time::server;
using namespace phosphor::logging;
-
-BmcEpoch::BmcEpoch(sdbusplus::bus_t& bus, const char* objPath,
- Manager& manager) :
- EpochBase(bus, objPath, manager)
-{
- initialize();
-}
+using FailedError = sdbusplus::xyz::openbmc_project::Time::Error::Failed;
void BmcEpoch::initialize()
{
@@ -109,5 +112,37 @@
return 0;
}
+void BmcEpoch::onModeChanged(Mode mode)
+{
+ manager.setTimeMode(mode);
+}
+
+bool BmcEpoch::setTime(const microseconds& usec)
+{
+ auto method = bus.new_method_call(SYSTEMD_TIME_SERVICE, SYSTEMD_TIME_PATH,
+ SYSTEMD_TIME_INTERFACE, METHOD_SET_TIME);
+ method.append(static_cast<int64_t>(usec.count()),
+ false, // relative
+ false); // user_interaction
+
+ try
+ {
+ bus.call_noreply(method);
+ }
+ catch (const sdbusplus::exception_t& ex)
+ {
+ lg2::error("Error in setting system time: {ERROR}", "ERROR", ex);
+ using namespace xyz::openbmc_project::Time;
+ elog<FailedError>(Failed::REASON(ex.what()));
+ }
+ return true;
+}
+
+microseconds BmcEpoch::getTime() const
+{
+ auto now = system_clock::now();
+ return duration_cast<microseconds>(now.time_since_epoch());
+}
+
} // namespace time
} // namespace phosphor