blob: e93b7f33b66e88df4c4c0560232889da35b177b1 [file] [log] [blame]
William A. Kennington III52575252018-02-09 15:54:56 -08001#pragma once
2#include <sdbusplus/bus.hpp>
William A. Kennington IIIb638de22018-02-09 16:12:53 -08003#include <xyz/openbmc_project/State/Watchdog/server.hpp>
William A. Kennington III52575252018-02-09 15:54:56 -08004
William A. Kennington III25bc7ac2018-03-15 11:48:41 -07005#include "utils.hpp"
6
William A. Kennington III52575252018-02-09 15:54:56 -08007/** @class WatchdogService
8 * @brief Access to the running OpenBMC watchdog implementation.
9 * @details Easy accessor for servers that implement the
10 * xyz.openbmc_project.State.Watchdog DBus API.
11 */
12class WatchdogService {
13 public:
14 WatchdogService();
15
William A. Kennington IIIb638de22018-02-09 16:12:53 -080016 using Action = sdbusplus::xyz::openbmc_project::State::server::Watchdog::Action;
17
William A. Kennington III52575252018-02-09 15:54:56 -080018 /** @brief Contains a copy of the properties enumerated by the
19 * watchdog service.
20 */
21 struct Properties {
William A. Kennington IIIde14a022018-02-09 16:11:18 -080022 bool initialized;
William A. Kennington III52575252018-02-09 15:54:56 -080023 bool enabled;
William A. Kennington IIIb638de22018-02-09 16:12:53 -080024 Action expireAction;
William A. Kennington III52575252018-02-09 15:54:56 -080025 uint64_t interval;
26 uint64_t timeRemaining;
27 };
28
29 /** @brief Retrieves a copy of the currently set properties on the
30 * host watchdog
31 *
32 * @return A populated WatchdogProperties struct
33 */
34 Properties getProperties();
35
William A. Kennington IIIde14a022018-02-09 16:11:18 -080036 /** @brief Sets the value of the initialized property on the host
37 * watchdog
38 *
39 * @param[in] initialized - The new initializedvalue
40 */
41 void setInitialized(bool initialized);
42
William A. Kennington III52575252018-02-09 15:54:56 -080043 /** @brief Sets the value of the enabled property on the host watchdog
44 *
45 * @param[in] enabled - The new enabled value
46 */
47 void setEnabled(bool enabled);
48
William A. Kennington IIIb638de22018-02-09 16:12:53 -080049 /** @brief Sets the value of the expireAction property on the host watchdog
50 *
51 * @param[in] expireAction - The new expireAction value
52 */
53 void setExpireAction(Action expireAction);
54
William A. Kennington III52575252018-02-09 15:54:56 -080055 /** @brief Sets the value of the interval property on the host watchdog
56 *
57 * @param[in] interval - The new interval value
58 */
59 void setInterval(uint64_t interval);
60
61 /** @brief Sets the value of the timeRemaining property on the host
62 * watchdog
63 *
64 * @param[in] timeRemaining - The new timeRemaining value
65 */
66 void setTimeRemaining(uint64_t timeRemaining);
67
68 private:
69 /** @brief sdbusplus handle */
70 sdbusplus::bus::bus bus;
71 /** @brief The name of the mapped host watchdog service */
William A. Kennington III25bc7ac2018-03-15 11:48:41 -070072 static ipmi::ServiceCache wd_service;
William A. Kennington III52575252018-02-09 15:54:56 -080073
74 /** @brief Sets the value of the property on the host watchdog
75 *
76 * @param[in] key - The name of the property
77 * @param[in] val - The new value
78 */
79 template <typename T>
80 void setProperty(const std::string& key, const T& val);
81};