libcamera  v0.0.0+3310-4b24b0bf
Supporting cameras in Linux since 2019
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
file_descriptor.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2019, Google Inc.
4  *
5  * file_descriptor.h - File descriptor wrapper
6  */
7 
8 #pragma once
9 
10 #include <memory>
11 #include <sys/types.h>
12 
13 namespace libcamera {
14 
15 class FileDescriptor final
16 {
17 public:
18  explicit FileDescriptor(const int &fd = -1);
19  explicit FileDescriptor(int &&fd);
20  FileDescriptor(const FileDescriptor &other);
23 
26 
27  bool isValid() const { return fd_ != nullptr; }
28  int fd() const { return fd_ ? fd_->fd() : -1; }
29  FileDescriptor dup() const;
30 
31  ino_t inode() const;
32 
33 private:
34  class Descriptor
35  {
36  public:
37  Descriptor(int fd, bool duplicate);
38  ~Descriptor();
39 
40  int fd() const { return fd_; }
41 
42  private:
43  int fd_;
44  };
45 
46  std::shared_ptr<Descriptor> fd_;
47 };
48 
49 } /* namespace libcamera */
RAII-style wrapper for file descriptors.
Definition: file_descriptor.h:15
FileDescriptor dup() const
Duplicate a FileDescriptor.
Definition: file_descriptor.cpp:221
Top-level libcamera namespace.
Definition: backtrace.h:17
bool isValid() const
Check if the FileDescriptor instance is valid.
Definition: file_descriptor.h:27
ino_t inode() const
Retrieve the file descriptor inode.
Definition: file_descriptor.cpp:233
~FileDescriptor()
Destroy the FileDescriptor instance.
Definition: file_descriptor.cpp:150
int fd() const
Retrieve the numerical file descriptor.
Definition: file_descriptor.h:28
FileDescriptor(const int &fd=-1)
Create a FileDescriptor copying a given fd.
Definition: file_descriptor.cpp:75
FileDescriptor & operator=(const FileDescriptor &other)
Copy assignment operator, replace the wrapped file descriptor with a copy of other.
Definition: file_descriptor.cpp:168