blob: ad92213f95cd86da81274c14c576cd571362419e [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 III4b017a92018-04-27 14:31:08 -070018 /** @brief Resets the time remaining on the watchdog.
19 * Equivalent to setTimeRemaining(getInterval()).
20 * Optionally enables the watchdog.
21 *
22 * @param[in] enableWatchdog - Should the call also enable the watchdog
23 */
24 void resetTimeRemaining(bool enableWatchdog);
25
William A. Kennington III52575252018-02-09 15:54:56 -080026 /** @brief Contains a copy of the properties enumerated by the
27 * watchdog service.
28 */
29 struct Properties {
William A. Kennington IIIde14a022018-02-09 16:11:18 -080030 bool initialized;
William A. Kennington III52575252018-02-09 15:54:56 -080031 bool enabled;
William A. Kennington IIIb638de22018-02-09 16:12:53 -080032 Action expireAction;
William A. Kennington III52575252018-02-09 15:54:56 -080033 uint64_t interval;
34 uint64_t timeRemaining;
35 };
36
37 /** @brief Retrieves a copy of the currently set properties on the
38 * host watchdog
39 *
40 * @return A populated WatchdogProperties struct
41 */
42 Properties getProperties();
43
William A. Kennington IIIde14a022018-02-09 16:11:18 -080044 /** @brief Sets the value of the initialized property on the host
45 * watchdog
46 *
47 * @param[in] initialized - The new initializedvalue
48 */
49 void setInitialized(bool initialized);
50
William A. Kennington III52575252018-02-09 15:54:56 -080051 /** @brief Sets the value of the enabled property on the host watchdog
52 *
53 * @param[in] enabled - The new enabled value
54 */
55 void setEnabled(bool enabled);
56
William A. Kennington IIIb638de22018-02-09 16:12:53 -080057 /** @brief Sets the value of the expireAction property on the host watchdog
58 *
59 * @param[in] expireAction - The new expireAction value
60 */
61 void setExpireAction(Action expireAction);
62
William A. Kennington III52575252018-02-09 15:54:56 -080063 /** @brief Sets the value of the interval property on the host watchdog
64 *
65 * @param[in] interval - The new interval value
66 */
67 void setInterval(uint64_t interval);
68
69 /** @brief Sets the value of the timeRemaining property on the host
70 * watchdog
71 *
72 * @param[in] timeRemaining - The new timeRemaining value
73 */
74 void setTimeRemaining(uint64_t timeRemaining);
75
76 private:
77 /** @brief sdbusplus handle */
78 sdbusplus::bus::bus bus;
79 /** @brief The name of the mapped host watchdog service */
William A. Kennington III25bc7ac2018-03-15 11:48:41 -070080 static ipmi::ServiceCache wd_service;
William A. Kennington III52575252018-02-09 15:54:56 -080081
82 /** @brief Sets the value of the property on the host watchdog
83 *
84 * @param[in] key - The name of the property
85 * @param[in] val - The new value
86 */
87 template <typename T>
88 void setProperty(const std::string& key, const T& val);
89};