Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 3 | #include <systemd/sd-event.h> |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 4 | #include <unistd.h> |
| 5 | |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
Ramesh Iyyar | 2279386 | 2020-12-04 04:03:03 -0600 | [diff] [blame] | 7 | #include <xyz/openbmc_project/State/Boot/Progress/server.hpp> |
Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame] | 8 | |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 9 | #include <memory> |
| 10 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 11 | namespace phosphor |
| 12 | { |
| 13 | namespace dump |
| 14 | { |
| 15 | |
Ramesh Iyyar | 2279386 | 2020-12-04 04:03:03 -0600 | [diff] [blame] | 16 | using BootProgress = sdbusplus::xyz::openbmc_project::State::Boot::server:: |
| 17 | Progress::ProgressStages; |
| 18 | |
Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame] | 19 | /* Need a custom deleter for freeing up sd_event */ |
| 20 | struct EventDeleter |
| 21 | { |
| 22 | void operator()(sd_event* event) const |
| 23 | { |
| 24 | event = sd_event_unref(event); |
| 25 | } |
| 26 | }; |
| 27 | using EventPtr = std::unique_ptr<sd_event, EventDeleter>; |
| 28 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 29 | /** @struct CustomFd |
| 30 | * |
| 31 | * RAII wrapper for file descriptor. |
| 32 | */ |
| 33 | struct CustomFd |
| 34 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 35 | private: |
| 36 | /** @brief File descriptor */ |
| 37 | int fd = -1; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 38 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 39 | 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 Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 45 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 46 | /** @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 Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 51 | {} |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 52 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 53 | ~CustomFd() |
| 54 | { |
| 55 | if (fd >= 0) |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 56 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 57 | close(fd); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 58 | } |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 59 | } |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 60 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 61 | int operator()() const |
| 62 | { |
| 63 | return fd; |
| 64 | } |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 65 | }; |
| 66 | |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 67 | /** |
| 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 Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 75 | std::string getService(sdbusplus::bus_t& bus, const std::string& path, |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 76 | const std::string& interface); |
| 77 | |
Ramesh Iyyar | 2279386 | 2020-12-04 04:03:03 -0600 | [diff] [blame] | 78 | /** |
| 79 | * @brief Get the host boot progress stage |
| 80 | * |
| 81 | * @return BootProgress on success |
| 82 | * Throw exception on failure |
| 83 | * |
| 84 | */ |
| 85 | BootProgress getBootProgress(); |
| 86 | |
Dhruvaraj Subhashchandran | 6a54d9a | 2020-12-17 22:24:37 -0600 | [diff] [blame] | 87 | /** |
| 88 | * @brief Check whether host is running |
| 89 | * |
| 90 | * @return true if the host running else false. |
| 91 | * Throw exception on failure. |
| 92 | */ |
| 93 | bool isHostRunning(); |
| 94 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 95 | } // namespace dump |
| 96 | } // namespace phosphor |