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>
50 lines
872 B
C++
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 */
|