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>
This commit is contained in:
Laurent Pinchart
2021-12-03 19:20:31 +02:00
parent 6b1e256934
commit 6c6acaa7ea
14 changed files with 13 additions and 16 deletions
+49
View File
@@ -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 */
+1
View File
@@ -11,6 +11,7 @@ libcamera_base_headers = files([
'event_dispatcher_poll.h',
'event_notifier.h',
'file.h',
'file_descriptor.h',
'flags.h',
'log.h',
'message.h',