Files
external_libcamera/include/libcamera/base/shared_fd.h
Laurent Pinchart 5c85e70240 libcamera: base: Rename FileDescriptor to SharedFD
Now that we have a UniqueFD class, the name FileDescriptor is ambiguous.
Rename it to SharedFD.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-04 23:05:05 +02:00

50 lines
872 B
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* shared_fd.h - File descriptor wrapper with shared ownership
*/
#pragma once
#include <memory>
namespace libcamera {
class UniqueFD;
class SharedFD final
{
public:
explicit SharedFD(const int &fd = -1);
explicit SharedFD(int &&fd);
explicit SharedFD(UniqueFD fd);
SharedFD(const SharedFD &other);
SharedFD(SharedFD &&other);
~SharedFD();
SharedFD &operator=(const SharedFD &other);
SharedFD &operator=(SharedFD &&other);
bool isValid() const { return fd_ != nullptr; }
int fd() const { return fd_ ? fd_->fd() : -1; }
UniqueFD 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 */