summaryrefslogtreecommitdiffstats
path: root/app/watchdog_service.cpp
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-02-09 15:54:56 -0800
committerWilliam A. Kennington III <wak@google.com>2018-02-21 23:54:59 +0000
commit5257525db7dd97ffb8b5464df1b5b83df0297e7a (patch)
tree3757c1daa038c38100fee2599c0ba8df81a6cf44 /app/watchdog_service.cpp
parente66c3b042c0cd2d94059fa93298e0ba52c92b248 (diff)
downloadphosphor-host-ipmid-5257525db7dd97ffb8b5464df1b5b83df0297e7a.tar.gz
phosphor-host-ipmid-5257525db7dd97ffb8b5464df1b5b83df0297e7a.zip
watchdog: Rewrite using sdbusplus
Change-Id: I730317954819859d23fdaca7336f19f5c5b0c107 Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'app/watchdog_service.cpp')
-rw-r--r--app/watchdog_service.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/app/watchdog_service.cpp b/app/watchdog_service.cpp
new file mode 100644
index 0000000..7f5d179
--- /dev/null
+++ b/app/watchdog_service.cpp
@@ -0,0 +1,69 @@
+#include "watchdog_service.hpp"
+
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/message.hpp>
+#include <string>
+
+#include "host-ipmid/ipmid-api.h"
+#include "utils.hpp"
+
+using sdbusplus::message::variant_ns::get;
+using sdbusplus::message::variant_ns::variant;
+
+static constexpr char wd_path[] = "/xyz/openbmc_project/watchdog/host0";
+static constexpr char wd_intf[] = "xyz.openbmc_project.State.Watchdog";
+static constexpr char prop_intf[] = "org.freedesktop.DBus.Properties";
+
+WatchdogService::WatchdogService()
+ : bus(ipmid_get_sd_bus_connection()),
+ wd_service(ipmi::getService(bus, wd_intf, wd_path))
+{
+}
+
+WatchdogService::Properties WatchdogService::getProperties()
+{
+ auto request = bus.new_method_call(wd_service.c_str(), wd_path,
+ prop_intf, "GetAll");
+ request.append(wd_intf);
+ auto response = bus.call(request);
+ if (response.is_method_error())
+ {
+ throw std::runtime_error("Failed to get watchdog properties");
+ }
+
+ std::map<std::string, variant<bool, uint64_t, std::string>> properties;
+ response.read(properties);
+ Properties wd_prop;
+ wd_prop.enabled = get<bool>(properties.at("Enabled"));
+ wd_prop.interval = get<uint64_t>(properties.at("Interval"));
+ wd_prop.timeRemaining = get<uint64_t>(properties.at("TimeRemaining"));
+ return wd_prop;
+}
+
+template <typename T>
+void WatchdogService::setProperty(const std::string& key, const T& val)
+{
+ auto request = bus.new_method_call(wd_service.c_str(), wd_path,
+ prop_intf, "Set");
+ request.append(wd_intf, key, variant<T>(val));
+ auto response = bus.call(request);
+ if (response.is_method_error())
+ {
+ throw std::runtime_error(std::string("Failed to set property: ") + key);
+ }
+}
+
+void WatchdogService::setEnabled(bool enabled)
+{
+ setProperty("Enabled", enabled);
+}
+
+void WatchdogService::setInterval(uint64_t interval)
+{
+ setProperty("Interval", interval);
+}
+
+void WatchdogService::setTimeRemaining(uint64_t timeRemaining)
+{
+ setProperty("TimeRemaining", timeRemaining);
+}
OpenPOWER on IntegriCloud