blob: 4d0a83c4e4cce6016b8e1fb0efc18433cf042120 [file] [log] [blame]
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +05301#pragma once
2
3#include <unistd.h>
4namespace open_power
5{
6namespace occ
7{
8namespace pass_through
9{
10/** @class FileDescriptor
11 * @brief Responsible for handling file descriptor
12 */
13class FileDescriptor
14{
15 private:
16 /** @brief File descriptor for the gpio input device */
17 int fd = -1;
18
19 public:
20 FileDescriptor() = delete;
21 FileDescriptor(const FileDescriptor&) = delete;
22 FileDescriptor& operator=(const FileDescriptor&) = delete;
23 FileDescriptor(FileDescriptor&&) = delete;
24 FileDescriptor& operator=(FileDescriptor&&) = delete;
25
26 /** @brief Saves File descriptor and uses it to do file operation
27 *
28 * @param[in] fd - File descriptor
29 */
30 FileDescriptor(int fd) : fd(fd)
31 {
32 // Nothing
33 }
34
35 ~FileDescriptor()
36 {
37 if (fd >=0)
38 {
39 close(fd);
40 }
41 }
42
43 int operator()()
44 {
45 return fd;
46 }
47};
48
49} // namespace pass_through
50} // namespace occ
51} // namespace open-power