Add time Manager to handle property changes callback
1. Implement time::Manager who registers property change signal for time
mode and owner;
2. Add PropertyChangeListner interface to handle the callback;
3. Make EpochBase to implement the interface.
Change-Id: I185580ae37353e1ed82a47e4905fb22e269ac09d
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/epoch_base.cpp b/epoch_base.cpp
index 06232bb..07b3113 100644
--- a/epoch_base.cpp
+++ b/epoch_base.cpp
@@ -5,15 +5,6 @@
#include <iomanip>
#include <sstream>
-namespace // anonymous
-{
-constexpr auto SETTINGS_SERVICE = "org.openbmc.settings.Host";
-constexpr auto SETTINGS_PATH = "/org/openbmc/settings/host0";
-constexpr auto SETTINGS_INTERFACE = "org.openbmc.settings.Host";
-constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties";
-constexpr auto METHOD_GET = "Get";
-}
-
namespace phosphor
{
namespace time
@@ -21,90 +12,21 @@
using namespace phosphor::logging;
-const std::map<std::string, EpochBase::Owner>
-EpochBase::ownerMap = {
- { "BMC", EpochBase::Owner::BMC },
- { "HOST", EpochBase::Owner::HOST },
- { "SPLIT", EpochBase::Owner::SPLIT },
- { "BOTH", EpochBase::Owner::BOTH },
-};
-
EpochBase::EpochBase(sdbusplus::bus::bus& bus,
const char* objPath)
- : sdbusplus::server::object::object<EpochTime>(bus, objPath, true),
+ : sdbusplus::server::object::object<EpochTime>(bus, objPath),
bus(bus)
{
- initialize();
- // Deferred this until we could get our property correct
- emit_object_added();
}
-void EpochBase::setCurrentTimeMode(const std::string& mode)
+void EpochBase::onModeChanged(Mode mode)
{
- log<level::INFO>("Time mode is changed",
- entry("MODE=%s", mode.c_str()));
- timeMode = convertToMode(mode);
+ timeMode = mode;
}
-void EpochBase::setCurrentTimeOwner(const std::string& owner)
+void EpochBase::onOwnerChanged(Owner owner)
{
- log<level::INFO>("Time owner is changed",
- entry("OWNER=%s", owner.c_str()));
- timeOwner = convertToOwner(owner);
-}
-
-void EpochBase::initialize()
-{
- setCurrentTimeMode(getSettings("time_mode"));
- setCurrentTimeOwner(getSettings("time_owner"));
- // TODO: subscribe settingsd's property changes callback
-}
-
-std::string EpochBase::getSettings(const char* value) const
-{
- sdbusplus::message::variant<std::string> mode;
- auto method = bus.new_method_call(SETTINGS_SERVICE,
- SETTINGS_PATH,
- PROPERTY_INTERFACE,
- METHOD_GET);
- method.append(SETTINGS_INTERFACE, value);
- auto reply = bus.call(method);
- if (reply)
- {
- reply.read(mode);
- }
-
- return mode.get<std::string>();
-}
-
-EpochBase::Mode EpochBase::convertToMode(const std::string& mode)
-{
- if (mode == "NTP")
- {
- return Mode::NTP;
- }
- else if (mode == "MANUAL")
- {
- return Mode::MANUAL;
- }
- else
- {
- log<level::ERR>("Unrecognized mode",
- entry("%s", mode.c_str()));
- return Mode::NTP;
- }
-}
-
-EpochBase::Owner EpochBase::convertToOwner(const std::string& owner)
-{
- auto it = ownerMap.find(owner);
- if (it == ownerMap.end())
- {
- log<level::ERR>("Unrecognized owner",
- entry("%s", owner.c_str()));
- return Owner::BMC;
- }
- return it->second;
+ timeOwner = owner;
}
using namespace std::chrono;