summaryrefslogtreecommitdiffstats
path: root/filedescriptor.hpp
blob: 2a4c6d032501042dc33767e7cf0e9c5881b6c106 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#include <fcntl.h>
#include <string>

namespace openpower
{
namespace util
{

/**
 * Class to wrap a file descriptor.
 *
 * Opens the descriptor in the constructor, and
 * then closes it when destroyed.
 */
class FileDescriptor
{
    public:

        FileDescriptor() = delete;
        FileDescriptor(const FileDescriptor&) = delete;
        FileDescriptor(FileDescriptor&&) = default;
        FileDescriptor& operator=(const FileDescriptor) = delete;
        FileDescriptor& operator=(FileDescriptor&&) = default;

        /**
         * Creates a file descriptor by opening the device
         * path passed in.
         *
         * @param path[in] - the device path that will be open
         */
        FileDescriptor(const std::string& path);

        /**
         * Closes the file.
         */
        ~FileDescriptor();

        /**
         * The method to access the file descriptor value
         */
        inline auto get() const
        {
            return fd;
        }

    private:

        /**
         * The actual file descriptor
         */
        int fd;
};

}
}
OpenPOWER on IntegriCloud