forked from ibm-openbmc/phosphor-debug-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump_utils.hpp
96 lines (81 loc) · 1.88 KB
/
dump_utils.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#pragma once
#include <systemd/sd-event.h>
#include <unistd.h>
#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
#include <memory>
namespace phosphor
{
namespace dump
{
using BootProgress = sdbusplus::xyz::openbmc_project::State::Boot::server::
Progress::ProgressStages;
/* Need a custom deleter for freeing up sd_event */
struct EventDeleter
{
void operator()(sd_event* event) const
{
event = sd_event_unref(event);
}
};
using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
/** @struct CustomFd
*
* RAII wrapper for file descriptor.
*/
struct CustomFd
{
private:
/** @brief File descriptor */
int fd = -1;
public:
CustomFd() = delete;
CustomFd(const CustomFd&) = delete;
CustomFd& operator=(const CustomFd&) = delete;
CustomFd(CustomFd&&) = delete;
CustomFd& operator=(CustomFd&&) = delete;
/** @brief Saves File descriptor and uses it to do file operation
*
* @param[in] fd - File descriptor
*/
CustomFd(int fd) : fd(fd)
{}
~CustomFd()
{
if (fd >= 0)
{
close(fd);
}
}
int operator()() const
{
return fd;
}
};
/**
* @brief Get the bus service
*
* @param[in] bus - Bus to attach to.
* @param[in] path - D-Bus path name.
* @param[in] interface - D-Bus interface name.
* @return the bus service as a string
**/
std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
const std::string& interface);
/**
* @brief Get the host boot progress stage
*
* @return BootProgress on success
* Throw exception on failure
*
*/
BootProgress getBootProgress();
/**
* @brief Check whether host is running
*
* @return true if the host running else false.
* Throw exception on failure.
*/
bool isHostRunning();
} // namespace dump
} // namespace phosphor