summaryrefslogtreecommitdiff
path: root/include/libcamera/base/file_descriptor.h
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-11-28 05:07:54 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-12-03 19:20:31 +0200
commit6c6acaa7ea1893b99adbf2becc46238e4a5c78b2 (patch)
tree56c89594833ade5b8018de1e77d0e94f8be24f10 /include/libcamera/base/file_descriptor.h
parent6b1e25693402a1db6cde995ae8e1b8bf74b88e17 (diff)
libcamera: Move file_descriptor.h to base/
The FileDescriptor class is a generic helper that matches the criteria for the base library. Move it there. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'include/libcamera/base/file_descriptor.h')
-rw-r--r--include/libcamera/base/file_descriptor.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/include/libcamera/base/file_descriptor.h b/include/libcamera/base/file_descriptor.h
new file mode 100644
index 00000000..8d764f8b
--- /dev/null
+++ b/include/libcamera/base/file_descriptor.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * file_descriptor.h - File descriptor wrapper
+ */
+
+#pragma once
+
+#include <memory>
+#include <sys/types.h>
+
+namespace libcamera {
+
+class FileDescriptor final
+{
+public:
+ explicit FileDescriptor(const int &fd = -1);
+ explicit FileDescriptor(int &&fd);
+ FileDescriptor(const FileDescriptor &other);
+ FileDescriptor(FileDescriptor &&other);
+ ~FileDescriptor();
+
+ FileDescriptor &operator=(const FileDescriptor &other);
+ FileDescriptor &operator=(FileDescriptor &&other);
+
+ bool isValid() const { return fd_ != nullptr; }
+ int fd() const { return fd_ ? fd_->fd() : -1; }
+ FileDescriptor dup() const;
+
+ ino_t inode() const;
+
+private:
+ class Descriptor
+ {
+ public:
+ Descriptor(int fd, bool duplicate);
+ ~Descriptor();
+
+ int fd() const { return fd_; }
+
+ private:
+ int fd_;
+ };
+
+ std::shared_ptr<Descriptor> fd_;
+};
+
+} /* namespace libcamera */