blob: 05fe60cc54f4123b8de9f99ee423df9ccf143f9b [file] [log] [blame]
Brandon Wyman5914f652017-03-16 18:17:07 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
Brandon Wymanfef02952017-03-31 18:13:21 -05004#include <unistd.h>
Brandon Wyman5914f652017-03-16 18:17:07 -05005
6namespace phosphor
7{
8namespace fan
9{
Matt Spinler5cfdf942017-04-10 14:25:47 -050010namespace util
Brandon Wyman5914f652017-03-16 18:17:07 -050011{
12
Brandon Wymanfef02952017-03-31 18:13:21 -050013class FileDescriptor
14{
15 public:
16 FileDescriptor() = delete;
17 FileDescriptor(const FileDescriptor&) = delete;
18 FileDescriptor(FileDescriptor&&) = default;
19 FileDescriptor& operator=(const FileDescriptor&) = delete;
20 FileDescriptor& operator=(FileDescriptor&&) = default;
21
22 FileDescriptor(int fd) : fd(fd)
23 {
24 }
25
26 ~FileDescriptor()
27 {
28 if (fd != -1)
29 {
30 close(fd);
31 }
32 }
33
34 bool is_open()
35 {
36 return fd != -1;
37 }
38
39 private:
40 int fd = -1;
41
42};
43
Brandon Wyman5914f652017-03-16 18:17:07 -050044/**
45 * @brief Get the inventory service name from the mapper object
46 *
47 * @return The inventory manager service name
48 */
49std::string getInvService(sdbusplus::bus::bus& bus);
50
Matt Spinler5cfdf942017-04-10 14:25:47 -050051
52/**
53 * @brief Get the service name from the mapper for the
54 * interface and path passed in.
55 *
56 * @param[in] path - the dbus path name
57 * @param[in] interface - the dbus interface name
58 * @param[in] bus - the dbus object
59 *
60 * @return The service name
61 */
62std::string getService(const std::string& path,
63 const std::string& interface,
64 sdbusplus::bus::bus& bus);
65
Brandon Wyman5914f652017-03-16 18:17:07 -050066}
67}
68}