file_descriptor.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* file_descriptor.h - File descriptor wrapper
*/
#ifndef __LIBCAMERA_FILE_DESCRIPTOR_H__
#define __LIBCAMERA_FILE_DESCRIPTOR_H__
#include <memory>
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;
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 */
#endif /* __LIBCAMERA_FILE_DESCRIPTOR_H__ */
libcamera::FileDescriptor
RAII-style wrapper for file descriptors.
Definition: file_descriptor.h:15
libcamera::FileDescriptor::fd
int fd() const
Retrieve the numerical file descriptor.
Definition: file_descriptor.h:27
libcamera::FileDescriptor::dup
FileDescriptor dup() const
Duplicate a FileDescriptor.
Definition: file_descriptor.cpp:219
libcamera::FileDescriptor::~FileDescriptor
~FileDescriptor()
Destroy the FileDescriptor instance.
Definition: file_descriptor.cpp:148
libcamera::FileDescriptor::isValid
bool isValid() const
Check if the FileDescriptor instance is valid.
Definition: file_descriptor.h:26
libcamera::FileDescriptor::operator=
FileDescriptor & operator=(const FileDescriptor &other)
Copy assignment operator, replace the wrapped file descriptor with a copy of other.
Definition: file_descriptor.cpp:166
libcamera::FileDescriptor::FileDescriptor
FileDescriptor(const int &fd=-1)
Create a FileDescriptor copying a given fd.
Definition: file_descriptor.cpp:73