Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
Brandon Wyman | fef0295 | 2017-03-31 18:13:21 -0500 | [diff] [blame] | 4 | #include <unistd.h> |
Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace fan |
| 9 | { |
Matt Spinler | 5cfdf94 | 2017-04-10 14:25:47 -0500 | [diff] [blame] | 10 | namespace util |
Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 11 | { |
| 12 | |
Brandon Wyman | fef0295 | 2017-03-31 18:13:21 -0500 | [diff] [blame] | 13 | class 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 Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 44 | /** |
| 45 | * @brief Get the inventory service name from the mapper object |
| 46 | * |
| 47 | * @return The inventory manager service name |
| 48 | */ |
| 49 | std::string getInvService(sdbusplus::bus::bus& bus); |
| 50 | |
Matt Spinler | 5cfdf94 | 2017-04-10 14:25:47 -0500 | [diff] [blame] | 51 | |
| 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 | */ |
| 62 | std::string getService(const std::string& path, |
| 63 | const std::string& interface, |
| 64 | sdbusplus::bus::bus& bus); |
| 65 | |
Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | } |