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