blob: 47484af8901f1636ebc0c1c535291097ee2332e2 [file] [log] [blame]
Vishwanatha Subbannad7a3f132017-05-29 19:39:08 +05301#pragma once
2
3#include <systemd/sd-event.h>
4#include <sdbusplus/bus.hpp>
5#include <sdbusplus/server/object.hpp>
6#include <xyz/openbmc_project/State/Watchdog/server.hpp>
7#include "timer.hpp"
8
9namespace phosphor
10{
11namespace watchdog
12{
13using WatchdogInherits = sdbusplus::server::object::object<
14 sdbusplus::xyz::openbmc_project::State::server::Watchdog>;
15
16/** @class Watchdog
17 * @brief OpenBMC watchdog implementation.
18 * @details A concrete implementation for the
19 * xyz.openbmc_project.State.Watchdog DBus API.
20 */
21class Watchdog : public WatchdogInherits
22{
23 public:
24 Watchdog() = delete;
25 ~Watchdog() = default;
26 Watchdog(const Watchdog&) = delete;
27 Watchdog& operator=(const Watchdog&) = delete;
28 Watchdog(Watchdog&&) = delete;
29 Watchdog& operator=(Watchdog &&) = delete;
30
31 /** @brief Constructs the Watchdog object
32 *
33 * @param[in] bus - DBus bus to attach to
34 * @param[in] objPath - Object path to attach to
35 * @param[in] event - reference to sd_event unique pointer
36 */
37 Watchdog(sdbusplus::bus::bus& bus,
38 const char* objPath,
39 EventPtr& event) :
40 WatchdogInherits(bus, objPath),
41 bus(bus),
42 timer(event)
43 {
44 // Nothing
45 }
46
47 /** @brief Enable or disable watchdog
48 * If a watchdog state is changed from disable to enable,
49 * the watchdog timer is set with the default expiration
50 * interval and it starts counting down.
51 * If a watchdog is already enabled, setting @value to true
52 * has no effect.
53 *
54 * @param[in] value - 'true' to enable. 'false' to disable
55 *
56 * @return : applied value if success, previous value otherwise
57 */
58 bool enabled(bool value) override;
59
60 /** @brief Gets the remaining time before watchdog expires.
61 *
62 * @return 0 if watchdog is disabled or expired.
63 * Remaining time in milliseconds otherwise.
64 */
65 uint64_t timeRemaining() const override;
66
67 /** @brief Reset timer to expire after new timeout in milliseconds.
68 *
69 * @param[in] value - the time in miliseconds after which
70 * the watchdog will expire
71 *
72 * @return: updated timeout value if watchdog is enabled.
73 * 0 otherwise.
74 */
75 uint64_t timeRemaining(uint64_t value) override;
76
77 /** @brief Tells if the referenced timer is expired or not */
78 inline auto timerExpired() const
79 {
80 return timer.expired();
81 }
82
83 private:
84 /** @brief sdbusplus handle */
85 sdbusplus::bus::bus& bus;
86
87 /** @brief Contained timer object */
88 Timer timer;
89};
90
91} // namespace watchdog
92} // namespace phosphor