1 #pragma once
2 #include <ipmid/utils.hpp>
3 #include <sdbusplus/bus.hpp>
4 #include <xyz/openbmc_project/State/Watchdog/server.hpp>
5 
6 /** @class WatchdogService
7  *  @brief Access to the running OpenBMC watchdog implementation.
8  *  @details Easy accessor for servers that implement the
9  *  xyz.openbmc_project.State.Watchdog DBus API.
10  */
11 class WatchdogService
12 {
13   public:
14     WatchdogService();
15 
16     using Action =
17         sdbusplus::xyz::openbmc_project::State::server::Watchdog::Action;
18     using TimerUse =
19         sdbusplus::xyz::openbmc_project::State::server::Watchdog::TimerUse;
20 
21     /** @brief Resets the time remaining on the watchdog.
22      *         Equivalent to setTimeRemaining(getInterval()).
23      *         Optionally enables the watchdog.
24      *
25      *  @param[in] enableWatchdog - Should the call also enable the watchdog
26      */
27     void resetTimeRemaining(bool enableWatchdog);
28 
29     /** @brief Contains a copy of the properties enumerated by the
30      *         watchdog service.
31      */
32     struct Properties
33     {
34         bool initialized;
35         bool enabled;
36         Action expireAction;
37         TimerUse timerUse;
38         TimerUse expiredTimerUse;
39         uint64_t interval;
40         uint64_t timeRemaining;
41     };
42 
43     /** @brief Retrieves a copy of the currently set properties on the
44      *         host watchdog
45      *
46      *  @return A populated WatchdogProperties struct
47      */
48     Properties getProperties();
49 
50     /** @brief Get the value of the initialized property on the host
51      *         watchdog
52      *
53      *  @return The value of the property
54      */
55     bool getInitialized();
56 
57     /** @brief Sets the value of the initialized property on the host
58      *         watchdog
59      *
60      *  @param[in] initialized - The new initializedvalue
61      */
62     void setInitialized(bool initialized);
63 
64     /** @brief Sets the value of the enabled property on the host watchdog
65      *
66      *  @param[in] enabled - The new enabled value
67      */
68     void setEnabled(bool enabled);
69 
70     /** @brief Sets the value of the expireAction property on the host watchdog
71      *
72      *  @param[in] expireAction - The new expireAction value
73      */
74     void setExpireAction(Action expireAction);
75 
76     /** @brief Sets the value of the timerUse property on the host watchdog
77      *
78      *  @param[in] timerUse - The new timerUse value
79      */
80     void setTimerUse(TimerUse timerUse);
81 
82     /** @brief Sets the value of the ExpiredTimerUse property on the host
83      * watchdog
84      *
85      *  @param[in] timerUse - The new timerUse value
86      */
87     void setExpiredTimerUse(TimerUse timerUse);
88 
89     /** @brief Sets the value of the interval property on the host watchdog
90      *
91      *  @param[in] interval - The new interval value
92      */
93     void setInterval(uint64_t interval);
94 
95   private:
96     /** @brief sdbusplus handle */
97     sdbusplus::bus_t bus;
98     /** @brief The name of the mapped host watchdog service */
99     static ipmi::ServiceCache wd_service;
100 
101     /** @brief Gets the value of the property on the host watchdog
102      *
103      *  @param[in] key - The name of the property
104      *  @return The value of the property
105      */
106     template <typename T>
107     T getProperty(const std::string& key);
108 
109     /** @brief Sets the value of the property on the host watchdog
110      *
111      *  @param[in] key - The name of the property
112      *  @param[in] val - The new value
113      */
114     template <typename T>
115     void setProperty(const std::string& key, const T& val);
116 };
117