libcamera: base: file_descriptor: Add constructor from UniqueFD
Add a FileDescriptor constructor that takes a UniqueFD, transfering ownership of the file descriptor to the FileDescriptor. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
779f70c747
commit
1d0dbc0da8
2 changed files with 16 additions and 0 deletions
|
@ -11,11 +11,14 @@
|
||||||
|
|
||||||
namespace libcamera {
|
namespace libcamera {
|
||||||
|
|
||||||
|
class UniqueFD;
|
||||||
|
|
||||||
class FileDescriptor final
|
class FileDescriptor final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit FileDescriptor(const int &fd = -1);
|
explicit FileDescriptor(const int &fd = -1);
|
||||||
explicit FileDescriptor(int &&fd);
|
explicit FileDescriptor(int &&fd);
|
||||||
|
explicit FileDescriptor(UniqueFD fd);
|
||||||
FileDescriptor(const FileDescriptor &other);
|
FileDescriptor(const FileDescriptor &other);
|
||||||
FileDescriptor(FileDescriptor &&other);
|
FileDescriptor(FileDescriptor &&other);
|
||||||
~FileDescriptor();
|
~FileDescriptor();
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <libcamera/base/log.h>
|
#include <libcamera/base/log.h>
|
||||||
|
#include <libcamera/base/unique_fd.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file base/file_descriptor.h
|
* \file base/file_descriptor.h
|
||||||
|
@ -109,6 +110,18 @@ FileDescriptor::FileDescriptor(int &&fd)
|
||||||
fd = -1;
|
fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Create a FileDescriptor taking ownership of a given UniqueFD \a fd
|
||||||
|
* \param[in] fd UniqueFD
|
||||||
|
*
|
||||||
|
* Construct a FileDescriptor from UniqueFD by taking ownership of the \a fd.
|
||||||
|
* The original \a fd becomes invalid.
|
||||||
|
*/
|
||||||
|
FileDescriptor::FileDescriptor(UniqueFD fd)
|
||||||
|
: FileDescriptor(fd.release())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Copy constructor, create a FileDescriptor from a copy of \a other
|
* \brief Copy constructor, create a FileDescriptor from a copy of \a other
|
||||||
* \param[in] other The other FileDescriptor
|
* \param[in] other The other FileDescriptor
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue