From 38b08d791b159424c9c9f9a21876f73f6020062b Mon Sep 17 00:00:00 2001 From: Vishwanatha Subbanna Date: Fri, 14 Apr 2017 18:12:14 +0530 Subject: Open device and populate file descriptor Change-Id: I8159f71ff3dd087f10cdf3b013e1acb60d4758fb Signed-off-by: Vishwanatha Subbanna --- file.hpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 file.hpp (limited to 'file.hpp') diff --git a/file.hpp b/file.hpp new file mode 100644 index 0000000..4d0a83c --- /dev/null +++ b/file.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include +namespace open_power +{ +namespace occ +{ +namespace pass_through +{ +/** @class FileDescriptor + * @brief Responsible for handling file descriptor + */ +class FileDescriptor +{ + private: + /** @brief File descriptor for the gpio input device */ + int fd = -1; + + public: + FileDescriptor() = delete; + FileDescriptor(const FileDescriptor&) = delete; + FileDescriptor& operator=(const FileDescriptor&) = delete; + FileDescriptor(FileDescriptor&&) = delete; + FileDescriptor& operator=(FileDescriptor&&) = delete; + + /** @brief Saves File descriptor and uses it to do file operation + * + * @param[in] fd - File descriptor + */ + FileDescriptor(int fd) : fd(fd) + { + // Nothing + } + + ~FileDescriptor() + { + if (fd >=0) + { + close(fd); + } + } + + int operator()() + { + return fd; + } +}; + +} // namespace pass_through +} // namespace occ +} // namespace open-power -- cgit v1.2.1