blob: 1a188440d4b7a0719dee2f5a7b5a863b16adf717 [file] [log] [blame]
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05001#pragma once
2
Jayanth Othayothd02153c2017-07-02 22:29:42 -05003#include <systemd/sd-event.h>
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05004#include <unistd.h>
5
Jayanth Othayothd31be2c2020-02-04 02:56:45 -06006#include <sdbusplus/bus.hpp>
Ramesh Iyyar22793862020-12-04 04:03:03 -06007#include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -05008
Jayanth Othayoth0af74a52021-04-08 03:55:21 -05009#include <memory>
10
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050011namespace phosphor
12{
13namespace dump
14{
15
Ramesh Iyyar22793862020-12-04 04:03:03 -060016using BootProgress = sdbusplus::xyz::openbmc_project::State::Boot::server::
17 Progress::ProgressStages;
18
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -050019/* Need a custom deleter for freeing up sd_event */
20struct EventDeleter
21{
22 void operator()(sd_event* event) const
23 {
24 event = sd_event_unref(event);
25 }
26};
27using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
28
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050029/** @struct CustomFd
30 *
31 * RAII wrapper for file descriptor.
32 */
33struct CustomFd
34{
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050035 private:
36 /** @brief File descriptor */
37 int fd = -1;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050038
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050039 public:
40 CustomFd() = delete;
41 CustomFd(const CustomFd&) = delete;
42 CustomFd& operator=(const CustomFd&) = delete;
43 CustomFd(CustomFd&&) = delete;
44 CustomFd& operator=(CustomFd&&) = delete;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050045
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050046 /** @brief Saves File descriptor and uses it to do file operation
47 *
48 * @param[in] fd - File descriptor
49 */
50 CustomFd(int fd) : fd(fd)
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050051 {}
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050052
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050053 ~CustomFd()
54 {
55 if (fd >= 0)
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050056 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050057 close(fd);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050058 }
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050059 }
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050060
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050061 int operator()() const
62 {
63 return fd;
64 }
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050065};
66
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060067/**
68 * @brief Get the bus service
69 *
70 * @param[in] bus - Bus to attach to.
71 * @param[in] path - D-Bus path name.
72 * @param[in] interface - D-Bus interface name.
73 * @return the bus service as a string
74 **/
Patrick Williams9b18bf22022-07-22 19:26:55 -050075std::string getService(sdbusplus::bus_t& bus, const std::string& path,
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060076 const std::string& interface);
77
Ramesh Iyyar22793862020-12-04 04:03:03 -060078/**
79 * @brief Get the host boot progress stage
80 *
81 * @return BootProgress on success
82 * Throw exception on failure
83 *
84 */
85BootProgress getBootProgress();
86
Dhruvaraj Subhashchandran6a54d9a2020-12-17 22:24:37 -060087/**
88 * @brief Check whether host is running
89 *
90 * @return true if the host running else false.
91 * Throw exception on failure.
92 */
93bool isHostRunning();
94
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050095} // namespace dump
96} // namespace phosphor