blob: 5121babd63df76347a60b195b702841f6cc11631 [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
6#include <memory>
Jayanth Othayothd31be2c2020-02-04 02:56:45 -06007#include <sdbusplus/bus.hpp>
Ramesh Iyyar22793862020-12-04 04:03:03 -06008#include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -05009
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050010namespace phosphor
11{
12namespace dump
13{
14
Ramesh Iyyar22793862020-12-04 04:03:03 -060015using BootProgress = sdbusplus::xyz::openbmc_project::State::Boot::server::
16 Progress::ProgressStages;
17
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -050018/* Need a custom deleter for freeing up sd_event */
19struct EventDeleter
20{
21 void operator()(sd_event* event) const
22 {
23 event = sd_event_unref(event);
24 }
25};
26using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
27
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050028/** @struct CustomFd
29 *
30 * RAII wrapper for file descriptor.
31 */
32struct CustomFd
33{
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050034 private:
35 /** @brief File descriptor */
36 int fd = -1;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050037
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050038 public:
39 CustomFd() = delete;
40 CustomFd(const CustomFd&) = delete;
41 CustomFd& operator=(const CustomFd&) = delete;
42 CustomFd(CustomFd&&) = delete;
43 CustomFd& operator=(CustomFd&&) = delete;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050044
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050045 /** @brief Saves File descriptor and uses it to do file operation
46 *
47 * @param[in] fd - File descriptor
48 */
49 CustomFd(int fd) : fd(fd)
50 {
51 }
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 **/
75std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
76 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
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050087} // namespace dump
88} // namespace phosphor