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