diff options
author | Deepak Kodihalli <dkodihal@in.ibm.com> | 2017-07-25 05:48:58 -0500 |
---|---|---|
committer | Deepak Kodihalli <dkodihal@in.ibm.com> | 2017-07-28 06:34:50 -0500 |
commit | 20ed79e00ea163a2f24c13baa6f60a87ac268f2c (patch) | |
tree | f6c664e0119a8851a09f5d57e099552043f75d0c | |
parent | eaee45522525b0b6d479cf9ac6afe4767648d258 (diff) | |
download | phosphor-time-manager-20ed79e00ea163a2f24c13baa6f60a87ac268f2c.tar.gz phosphor-time-manager-20ed79e00ea163a2f24c13baa6f60a87ac268f2c.zip |
Add API to retrieve settings
Add API to retrieve all settings objects of interest to the time
manager.
Change-Id: I3d121c08d0156cf481a3468e6c7ca9b71f53d666
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rw-r--r-- | Makefile.am | 10 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | settings.cpp | 92 | ||||
-rw-r--r-- | settings.hpp | 52 | ||||
-rw-r--r-- | time-config.hpp | 4 |
5 files changed, 162 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am index 090ee2c..b25fa12 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,6 +6,12 @@ sbin_PROGRAMS = \ timemanager_SOURCES = \ time-register.c \ time-config.cpp \ - time-manager.cpp + time-manager.cpp \ + settings.cpp -timemanager_LDFLAGS = $(SYSTEMD_LIBS) $(libmapper_LIBS) +timemanager_LDFLAGS = \ + $(SYSTEMD_LIBS) \ + $(libmapper_LIBS) \ + $(PHOSPHOR_DBUS_INTERFACES_LIBS) \ + $(SDBUSPLUS_LIBS) \ + $(PHOSPHOR_LOGGING_LIBS) diff --git a/configure.ac b/configure.ac index 2769644..fc0da82 100644 --- a/configure.ac +++ b/configure.ac @@ -16,6 +16,12 @@ AC_PROG_MAKE_SET # Checks for libraries. AC_CHECK_LIB([mapper], [mapper_get_service], ,[AC_MSG_ERROR([Could not find libmapper...openbmc/phosphor-objmgr package required])]) PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 221]) +PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces],,\ + AC_MSG_ERROR(["Requires phosphor-dbus-interfaces package."])) +PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus],, + AC_MSG_ERROR(["Requires sdbusplus package."])) +PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging],,\ + AC_MSG_ERROR(["Requires phosphor-logging package."])) # Checks for header files. AC_CHECK_HEADER(systemd/sd-bus.h, ,[AC_MSG_ERROR([Could not find systemd/sd-bus.h...systemd developement package required])]) diff --git a/settings.cpp b/settings.cpp new file mode 100644 index 0000000..650d03d --- /dev/null +++ b/settings.cpp @@ -0,0 +1,92 @@ +#include <phosphor-logging/elog-errors.hpp> +#include <phosphor-logging/log.hpp> +#include "xyz/openbmc_project/Common/error.hpp" +#include "settings.hpp" + +namespace settings +{ + +using namespace phosphor::logging; +using namespace sdbusplus::xyz::openbmc_project::Common::Error; + +constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper"; +constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper"; +constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper"; + +Objects::Objects() +{ + auto bus = sdbusplus::bus::new_default(); + std::vector<std::string> settingsIntfs = + {timeOwnerIntf, timeSyncIntf}; + auto depth = 0; + + auto mapperCall = bus.new_method_call(mapperService, + mapperPath, + mapperIntf, + "GetSubTree"); + mapperCall.append(root); + mapperCall.append(depth); + mapperCall.append(settingsIntfs); + auto response = bus.call(mapperCall); + if (response.is_method_error()) + { + log<level::ERR>("Error in mapper GetSubTree"); + elog<InternalFailure>(); + } + + using Interfaces = std::vector<Interface>; + using MapperResponse = std::map<Path, std::map<Service, Interfaces>>; + MapperResponse result; + response.read(result); + if (result.empty()) + { + log<level::ERR>("Invalid response from mapper"); + elog<InternalFailure>(); + } + + for (const auto& iter : result) + { + const Path& path = iter.first; + const Interface& interface = iter.second.begin()->second.front(); + + if (timeOwnerIntf == interface) + { + timeOwner = path; + } + else if (timeSyncIntf == interface) + { + timeSyncMethod = path; + } + } +} + +Service Objects::service(const Path& path, const Interface& interface) const +{ + auto bus = sdbusplus::bus::new_default(); + using Interfaces = std::vector<Interface>; + auto mapperCall = bus.new_method_call(mapperService, + mapperPath, + mapperIntf, + "GetObject"); + mapperCall.append(path); + mapperCall.append(Interfaces({interface})); + + auto response = bus.call(mapperCall); + if (response.is_method_error()) + { + log<level::ERR>("Error in mapper GetObject"); + elog<InternalFailure>(); + } + + std::map<Service, Interfaces> result; + response.read(result); + if (result.empty()) + { + log<level::ERR>("Invalid response from mapper"); + elog<InternalFailure>(); + } + + return result.begin()->first; +} + +} // namespace settings diff --git a/settings.hpp b/settings.hpp new file mode 100644 index 0000000..db1e5e4 --- /dev/null +++ b/settings.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include <string> +#include <sdbusplus/bus.hpp> + +namespace settings +{ + +using Path = std::string; +using Service = std::string; +using Interface = std::string; + +constexpr auto root = "/"; +constexpr auto timeOwnerIntf = "xyz.openbmc_project.Time.Owner"; +constexpr auto timeSyncIntf = "xyz.openbmc_project.Time.Synchronization"; + +/** @class Objects + * @brief Fetch paths of settings D-bus objects of interest upon construction + */ +struct Objects +{ + public: + /** @brief Constructor - fetch settings objects + * + * @param[in] bus - The D-bus bus object + */ + Objects(); + Objects(const Objects&) = default; + Objects& operator=(const Objects&) = default; + Objects(Objects&&) = default; + Objects& operator=(Objects&&) = default; + ~Objects() = default; + + /** @brief Fetch D-bus service, given a path and an interface. The + * service can't be cached because mapper returns unique + * service names. + * + * @param[in] path - The D-bus object + * @param[in] interface - The D-bus interface + * + * @return std::string - the D-bus service + */ + Service service(const Path& path, const Interface& interface) const; + + /** @brief time owner settings object */ + Path timeOwner; + + /** @brief time sync method settings object */ + Path timeSyncMethod; +}; + +} // namespace settings diff --git a/time-config.hpp b/time-config.hpp index 367380c..2d55b4b 100644 --- a/time-config.hpp +++ b/time-config.hpp @@ -1,5 +1,6 @@ #include <map> #include <systemd/sd-bus.h> +#include "settings.hpp" /** @class TimeConfig * @brief Maintains various time modes and time owners. @@ -224,6 +225,9 @@ private: // Needed to nudge Time Manager to reset offset bool iv_SplitModeChanged; + /** @brief Settings objects of intereset */ + settings::Objects settings; + static constexpr auto cv_TimeModeFile = "/var/lib/obmc/saved_timeMode"; static constexpr auto cv_TimeOwnerFile = "/var/lib/obmc/saved_timeOwner"; static constexpr auto cv_DhcpNtpFile = "/var/lib/obmc/saved_dhcpNtp"; |