1 #pragma once
2 #include <sdbusplus/bus.hpp>
3 #include <xyz/openbmc_project/State/Watchdog/server.hpp>
4 
5 #include "utils.hpp"
6 
7 /** @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  */
12 class WatchdogService {
13     public:
14         WatchdogService();
15 
16         using Action = sdbusplus::xyz::openbmc_project::State::server::Watchdog::Action;
17 
18         /** @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 
26         /** @brief Contains a copy of the properties enumerated by the
27          *         watchdog service.
28          */
29         struct Properties {
30             bool initialized;
31             bool enabled;
32             Action expireAction;
33             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 
44         /** @brief Get the value of the initialized property on the host
45          *         watchdog
46          *
47          *  @return The value of the property
48          */
49         bool getInitialized();
50 
51         /** @brief Sets the value of the initialized property on the host
52          *         watchdog
53          *
54          *  @param[in] initialized - The new initializedvalue
55          */
56         void setInitialized(bool initialized);
57 
58         /** @brief Sets the value of the enabled property on the host watchdog
59          *
60          *  @param[in] enabled - The new enabled value
61          */
62         void setEnabled(bool enabled);
63 
64         /** @brief Sets the value of the expireAction property on the host watchdog
65          *
66          *  @param[in] expireAction - The new expireAction value
67          */
68         void setExpireAction(Action expireAction);
69 
70         /** @brief Sets the value of the interval property on the host watchdog
71          *
72          *  @param[in] interval - The new interval value
73          */
74         void setInterval(uint64_t interval);
75 
76         /** @brief Sets the value of the timeRemaining property on the host
77          *         watchdog
78          *
79          *  @param[in] timeRemaining - The new timeRemaining value
80          */
81         void setTimeRemaining(uint64_t timeRemaining);
82 
83     private:
84         /** @brief sdbusplus handle */
85         sdbusplus::bus::bus bus;
86         /** @brief The name of the mapped host watchdog service */
87         static ipmi::ServiceCache wd_service;
88 
89         /** @brief Gets the value of the property on the host watchdog
90          *
91          *  @param[in] key - The name of the property
92          *  @return The value of the property
93          */
94         template <typename T>
95         T getProperty(const std::string& key);
96 
97         /** @brief Sets the value of the property on the host watchdog
98          *
99          *  @param[in] key - The name of the property
100          *  @param[in] val - The new value
101          */
102         template <typename T>
103         void setProperty(const std::string& key, const T& val);
104 };
105