| 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 |  | 
|  | 6 | #include <memory> | 
| Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 7 | #include <sdbusplus/bus.hpp> | 
| Ramesh Iyyar | 2279386 | 2020-12-04 04:03:03 -0600 | [diff] [blame] | 8 | #include <xyz/openbmc_project/State/Boot/Progress/server.hpp> | 
| Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame] | 9 |  | 
| Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 10 | namespace phosphor | 
|  | 11 | { | 
|  | 12 | namespace dump | 
|  | 13 | { | 
|  | 14 |  | 
| Ramesh Iyyar | 2279386 | 2020-12-04 04:03:03 -0600 | [diff] [blame] | 15 | using BootProgress = sdbusplus::xyz::openbmc_project::State::Boot::server:: | 
|  | 16 | Progress::ProgressStages; | 
|  | 17 |  | 
| Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame] | 18 | /* Need a custom deleter for freeing up sd_event */ | 
|  | 19 | struct EventDeleter | 
|  | 20 | { | 
|  | 21 | void operator()(sd_event* event) const | 
|  | 22 | { | 
|  | 23 | event = sd_event_unref(event); | 
|  | 24 | } | 
|  | 25 | }; | 
|  | 26 | using EventPtr = std::unique_ptr<sd_event, EventDeleter>; | 
|  | 27 |  | 
| Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 28 | /** @struct CustomFd | 
|  | 29 | * | 
|  | 30 | *  RAII wrapper for file descriptor. | 
|  | 31 | */ | 
|  | 32 | struct CustomFd | 
|  | 33 | { | 
| Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 34 | private: | 
|  | 35 | /** @brief File descriptor */ | 
|  | 36 | int fd = -1; | 
| Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 37 |  | 
| Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 38 | 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 Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 44 |  | 
| Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 45 | /** @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 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 | **/ | 
|  | 75 | std::string getService(sdbusplus::bus::bus& bus, const std::string& path, | 
|  | 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 |  | 
| Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 87 | } // namespace dump | 
|  | 88 | } // namespace phosphor |