summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLei YU <mine260309@gmail.com>2017-08-01 17:10:17 +0800
committerLei YU <mine260309@gmail.com>2017-10-16 20:41:01 +0800
commit710d49be2fc33f22e8f4a7ed43774fd9293d083f (patch)
tree7f12eab17509e59546fb5825adb4d36cc6cfd866
parentad14354fc17811ae585f13b1d52a275cf3daff35 (diff)
downloadphosphor-time-manager-710d49be2fc33f22e8f4a7ed43774fd9293d083f.tar.gz
phosphor-time-manager-710d49be2fc33f22e8f4a7ed43774fd9293d083f.zip
Use new settings API
The new time manager code was using the old settings daemon. Now it uses the new settings API. Change-Id: Id551d97c28a6cfbb81c87118b26292b1b5574e93 Signed-off-by: Lei YU <mine260309@gmail.com>
-rw-r--r--Makefile.am1
-rw-r--r--README.md4
-rw-r--r--manager.cpp61
-rw-r--r--manager.hpp34
-rw-r--r--test/TestManager.cpp22
5 files changed, 104 insertions, 18 deletions
diff --git a/Makefile.am b/Makefile.am
index bf7a559..09e8807 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,6 +17,7 @@ libtimemanager_la_SOURCES = \
host_epoch.cpp \
manager.cpp \
utils.cpp \
+ settings.cpp \
${generated_source}
phosphor_timemanager_SOURCES = \
diff --git a/README.md b/README.md
index d86559d..5365349 100644
--- a/README.md
+++ b/README.md
@@ -39,10 +39,10 @@ the time. For example on an authenticated session:
Getting BMC or HOST time is always allowed, but setting the time may not be
allowed depending on below two settings in settings manager.
-* time_mode
+* TimeSyncMethod
* NTP: Time is set via NTP server.
* MANUAL: Time is set manually.
-* time_owner
+* TimeOwner
* BMC: BMC owns the time and can set the time.
* HOST: Host owns the time and can set the time.
* SPLIT: BMC and Host owns separate time.
diff --git a/manager.cpp b/manager.cpp
index 0fedd09..fc2ca65 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -55,14 +55,33 @@ Manager::Manager(sdbusplus::bus::bus& bus)
propertyChangeMatch(bus, MATCH_PROPERTY_CHANGE, onPropertyChanged, this),
pgoodChangeMatch(bus, MATCH_PGOOD_CHANGE, onPgoodChanged, this)
{
+ using namespace sdbusplus::bus::match::rules;
+ settingsMatches.emplace_back(
+ bus,
+ propertiesChanged(settings.timeOwner, settings::timeOwnerIntf),
+ std::bind(std::mem_fn(&Manager::onSettingsChanged),
+ this, std::placeholders::_1));
+ settingsMatches.emplace_back(
+ bus,
+ propertiesChanged(settings.timeSyncMethod, settings::timeSyncIntf),
+ std::bind(std::mem_fn(&Manager::onSettingsChanged),
+ this, std::placeholders::_1));
+
checkHostOn();
// Restore settings from persistent storage
restoreSettings();
// Check the settings daemon to process the new settings
- onPropertyChanged(PROPERTY_TIME_MODE, getSettings(PROPERTY_TIME_MODE));
- onPropertyChanged(PROPERTY_TIME_OWNER, getSettings(PROPERTY_TIME_OWNER));
+ auto mode = getSetting(settings.timeSyncMethod.c_str(),
+ settings::timeSyncIntf,
+ PROPERTY_TIME_MODE);
+ auto owner = getSetting(settings.timeOwner.c_str(),
+ settings::timeOwnerIntf,
+ PROPERTY_TIME_OWNER);
+
+ onPropertyChanged(PROPERTY_TIME_MODE, mode);
+ onPropertyChanged(PROPERTY_TIME_OWNER, owner);
checkDhcpNtp();
}
@@ -164,6 +183,26 @@ int Manager::onPropertyChanged(sd_bus_message* msg,
return 0;
}
+int Manager::onSettingsChanged(sdbusplus::message::message& msg)
+{
+ using Interface = std::string;
+ using Property = std::string;
+ using Value = std::string;
+ using Properties = std::map<Property, sdbusplus::message::variant<Value>>;
+
+ Interface interface;
+ Properties properties;
+
+ msg.read(interface, properties);
+
+ for(const auto& p : properties)
+ {
+ onPropertyChanged(p.first, p.second.get<std::string>());
+ }
+
+ return 0;
+}
+
void Manager::setPropertyAsRequested(const std::string& key,
const std::string& value)
{
@@ -199,7 +238,8 @@ void Manager::setRequestedOwner(const std::string& owner)
void Manager::updateNtpSetting(const std::string& value)
{
- bool isNtp = (value == "NTP");
+ bool isNtp =
+ (value == "xyz.openbmc_project.Time.Synchronization.Method.NTP");
auto method = bus.new_method_call(SYSTEMD_TIME_SERVICE,
SYSTEMD_TIME_PATH,
SYSTEMD_TIME_INTERFACE,
@@ -340,6 +380,9 @@ void Manager::onTimeOwnerChanged()
}
}
+// TODO: This function is here only for use_dhcp_ntp.
+// When use_dhcp_ntp is transferred to new settings daemon,
+// this function can be removed.
std::string Manager::getSettings(const char* setting) const
{
std::string settingsService = utils::getService(bus,
@@ -353,5 +396,17 @@ std::string Manager::getSettings(const char* setting) const
setting);
}
+std::string Manager::getSetting(const char* path,
+ const char* interface,
+ const char* setting) const
+{
+ std::string settingManager = utils::getService(bus, path, interface);
+ return utils::getProperty<std::string>(bus,
+ settingManager.c_str(),
+ path,
+ interface,
+ setting);
+}
+
}
}
diff --git a/manager.hpp b/manager.hpp
index 9b135d9..dc0885e 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -2,6 +2,7 @@
#include "types.hpp"
#include "property_change_listener.hpp"
+#include "settings.hpp"
#include <sdbusplus/bus.hpp>
#include <sdbusplus/bus/match.hpp>
@@ -30,6 +31,7 @@ class Manager
Manager& operator=(const Manager&) = delete;
Manager(Manager&&) = delete;
Manager& operator=(Manager&&) = delete;
+ ~Manager() = default;
/** @brief Add a listener that will be called
* when property is changed
@@ -41,14 +43,22 @@ class Manager
sdbusplus::bus::bus& bus;
/** @brief The match of settings property change */
+ // TODO: This is to be removed when all properties are handled in
+ // new settings daemon
sdbusplus::bus::match::match propertyChangeMatch;
+ /** @brief The match of settings property change */
+ std::vector<sdbusplus::bus::match::match> settingsMatches;
+
/** @brief The match of pgood change */
sdbusplus::bus::match::match pgoodChangeMatch;
/** @brief The container to hold all the listeners */
std::set<PropertyChangeListner*> listeners;
+ /** @brief Settings objects of intereset */
+ settings::Objects settings;
+
/** @brief The value to indicate if host is on */
bool hostOn = false;
@@ -81,6 +91,18 @@ class Manager
*/
std::string getSettings(const char* setting) const;
+ /** @brief Get setting from settingsd service
+ *
+ * @param[in] path - The dbus object path
+ * @param[in] interface - The dbus interface
+ * @param[in] setting - The string of the setting
+ *
+ * @return The setting value in string
+ */
+ std::string getSetting(const char* path,
+ const char* interface,
+ const char* setting) const;
+
/** @brief Set current time mode from the time mode string
*
* @param[in] mode - The string of time mode
@@ -113,6 +135,14 @@ class Manager
*/
void onTimeOwnerChanged();
+ /** @brief Callback to handle change in a setting
+ *
+ * @param[in] msg - sdbusplus dbusmessage
+ *
+ * @return 0 on success, < 0 on failure.
+ */
+ int onSettingsChanged(sdbusplus::message::message& msg);
+
/** @brief Notified on settings property changed
*
* @param[in] key - The name of property that is changed
@@ -182,10 +212,10 @@ class Manager
sd_bus_error* retError);
/** @brief The string of time mode property */
- static constexpr auto PROPERTY_TIME_MODE = "time_mode";
+ static constexpr auto PROPERTY_TIME_MODE = "TimeSyncMethod";
/** @brief The string of time owner property */
- static constexpr auto PROPERTY_TIME_OWNER = "time_owner";
+ static constexpr auto PROPERTY_TIME_OWNER = "TimeOwner";
/** @brief The string of use dhcp ntp property */
static constexpr auto PROPERTY_DHCP_NTP = "use_dhcp_ntp";
diff --git a/test/TestManager.cpp b/test/TestManager.cpp
index d87ca39..d8c51ca 100644
--- a/test/TestManager.cpp
+++ b/test/TestManager.cpp
@@ -31,7 +31,7 @@ class TestManager : public testing::Test
}
// Proxies for Manager's private members and functions
- Mode getTimeMode()
+ Mode getTimeMode()
{
return manager.timeMode;
}
@@ -94,10 +94,10 @@ TEST_F(TestManager, DISABLED_propertyChanged)
EXPECT_CALL(listener2, onOwnerChanged(Owner::Host)).Times(1);
notifyPropertyChanged(
- "time_mode",
+ "TimeSyncMethod",
"xyz.openbmc_project.Time.Synchronization.Method.Manual");
notifyPropertyChanged(
- "time_owner",
+ "TimeOwner",
"xyz.openbmc_project.Time.Owner.Owners.Host");
EXPECT_EQ("", getRequestedMode());
@@ -113,10 +113,10 @@ TEST_F(TestManager, DISABLED_propertyChanged)
EXPECT_CALL(listener2, onOwnerChanged(Owner::Host)).Times(0);
notifyPropertyChanged(
- "time_mode",
+ "TimeSyncMethod",
"xyz.openbmc_project.Time.Synchronization.Method.NTP");
notifyPropertyChanged(
- "time_owner",
+ "TimeOwner",
"xyz.openbmc_project.Time.Owner.Owners.Split");
EXPECT_EQ("xyz.openbmc_project.Time.Synchronization.Method.NTP",
@@ -147,10 +147,10 @@ TEST_F(TestManager, DISABLED_propertyChangedAndChangedbackWhenHostOn)
{
// Property is now MANUAL/HOST
notifyPropertyChanged(
- "time_mode",
+ "TimeSyncMethod",
"xyz.openbmc_project.Time.Synchronization.Method.Manual");
notifyPropertyChanged(
- "time_owner",
+ "TimeOwner",
"xyz.openbmc_project.Time.Owner.Owners.Host");
// Set host on
@@ -163,10 +163,10 @@ TEST_F(TestManager, DISABLED_propertyChangedAndChangedbackWhenHostOn)
EXPECT_CALL(listener2, onOwnerChanged(_)).Times(0);
notifyPropertyChanged(
- "time_mode",
+ "TimeSyncMethod",
"xyz.openbmc_project.Time.Synchronization.Method.NTP");
notifyPropertyChanged(
- "time_owner",
+ "TimeOwner",
"xyz.openbmc_project.Time.Owner.Owners.Split");
// Saved as requested mode/owner
@@ -177,10 +177,10 @@ TEST_F(TestManager, DISABLED_propertyChangedAndChangedbackWhenHostOn)
// Property changed back to MANUAL/HOST
notifyPropertyChanged(
- "time_mode",
+ "TimeSyncMethod",
"xyz.openbmc_project.Time.Synchronization.Method.Manual");
notifyPropertyChanged(
- "time_owner",
+ "TimeOwner",
"xyz.openbmc_project.Time.Owner.Owners.Host");
// Requested mode/owner shall be updated
OpenPOWER on IntegriCloud