From 5c85e7024027c90b1b054782e510691b8b9c7419 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 28 Nov 2021 05:45:34 +0200 Subject: 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 Reviewed-by: Hirokazu Honda Reviewed-by: Jacopo Mondi --- include/libcamera/base/file_descriptor.h | 49 ------------------------ include/libcamera/base/meson.build | 2 +- include/libcamera/base/shared_fd.h | 49 ++++++++++++++++++++++++ include/libcamera/framebuffer.h | 4 +- include/libcamera/internal/ipa_data_serializer.h | 40 +++++++++---------- include/libcamera/internal/ipc_pipe.h | 8 ++-- include/libcamera/internal/v4l2_videodevice.h | 2 +- include/libcamera/ipa/core.mojom | 6 +-- include/libcamera/ipa/raspberrypi.mojom | 2 +- 9 files changed, 81 insertions(+), 81 deletions(-) delete mode 100644 include/libcamera/base/file_descriptor.h create mode 100644 include/libcamera/base/shared_fd.h (limited to 'include') diff --git a/include/libcamera/base/file_descriptor.h b/include/libcamera/base/file_descriptor.h deleted file mode 100644 index 12a43f95..00000000 --- a/include/libcamera/base/file_descriptor.h +++ /dev/null @@ -1,49 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * file_descriptor.h - File descriptor wrapper - */ - -#pragma once - -#include - -namespace libcamera { - -class UniqueFD; - -class FileDescriptor final -{ -public: - explicit FileDescriptor(const int &fd = -1); - explicit FileDescriptor(int &&fd); - explicit FileDescriptor(UniqueFD 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; } - UniqueFD dup() const; - -private: - class Descriptor - { - public: - Descriptor(int fd, bool duplicate); - ~Descriptor(); - - int fd() const { return fd_; } - - private: - int fd_; - }; - - std::shared_ptr fd_; -}; - -} /* namespace libcamera */ diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build index fce6eaa4..4410aba8 100644 --- a/include/libcamera/base/meson.build +++ b/include/libcamera/base/meson.build @@ -11,7 +11,6 @@ libcamera_base_headers = files([ 'event_dispatcher_poll.h', 'event_notifier.h', 'file.h', - 'file_descriptor.h', 'flags.h', 'log.h', 'message.h', @@ -19,6 +18,7 @@ libcamera_base_headers = files([ 'object.h', 'private.h', 'semaphore.h', + 'shared_fd.h', 'signal.h', 'span.h', 'thread.h', diff --git a/include/libcamera/base/shared_fd.h b/include/libcamera/base/shared_fd.h new file mode 100644 index 00000000..a786885c --- /dev/null +++ b/include/libcamera/base/shared_fd.h @@ -0,0 +1,49 @@ +/* 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 + +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 fd_; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h index 2fbea9c5..357bbe18 100644 --- a/include/libcamera/framebuffer.h +++ b/include/libcamera/framebuffer.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include namespace libcamera { @@ -51,7 +51,7 @@ class FrameBuffer final : public Extensible public: struct Plane { static constexpr unsigned int kInvalidOffset = std::numeric_limits::max(); - FileDescriptor fd; + SharedFD fd; unsigned int offset = kInvalidOffset; unsigned int length; }; diff --git a/include/libcamera/internal/ipa_data_serializer.h b/include/libcamera/internal/ipa_data_serializer.h index c2f602d5..a87449c9 100644 --- a/include/libcamera/internal/ipa_data_serializer.h +++ b/include/libcamera/internal/ipa_data_serializer.h @@ -66,7 +66,7 @@ template class IPADataSerializer { public: - static std::tuple, std::vector> + static std::tuple, std::vector> serialize(const T &data, ControlSerializer *cs = nullptr); static T deserialize(const std::vector &data, @@ -76,12 +76,12 @@ public: ControlSerializer *cs = nullptr); static T deserialize(const std::vector &data, - const std::vector &fds, + const std::vector &fds, ControlSerializer *cs = nullptr); static T deserialize(std::vector::const_iterator dataBegin, std::vector::const_iterator dataEnd, - std::vector::const_iterator fdsBegin, - std::vector::const_iterator fdsEnd, + std::vector::const_iterator fdsBegin, + std::vector::const_iterator fdsEnd, ControlSerializer *cs = nullptr); }; @@ -104,11 +104,11 @@ template class IPADataSerializer> { public: - static std::tuple, std::vector> + static std::tuple, std::vector> serialize(const std::vector &data, ControlSerializer *cs = nullptr) { std::vector dataVec; - std::vector fdsVec; + std::vector fdsVec; /* Serialize the length. */ uint32_t vecLen = data.size(); @@ -117,7 +117,7 @@ public: /* Serialize the members. */ for (auto const &it : data) { std::vector dvec; - std::vector fvec; + std::vector fvec; std::tie(dvec, fvec) = IPADataSerializer::serialize(it, cs); @@ -141,11 +141,11 @@ public: std::vector::const_iterator dataEnd, ControlSerializer *cs = nullptr) { - std::vector fds; + std::vector fds; return deserialize(dataBegin, dataEnd, fds.cbegin(), fds.end(), cs); } - static std::vector deserialize(std::vector &data, std::vector &fds, + static std::vector deserialize(std::vector &data, std::vector &fds, ControlSerializer *cs = nullptr) { return deserialize(data.cbegin(), data.end(), fds.cbegin(), fds.end(), cs); @@ -153,15 +153,15 @@ public: static std::vector deserialize(std::vector::const_iterator dataBegin, std::vector::const_iterator dataEnd, - std::vector::const_iterator fdsBegin, - [[maybe_unused]] std::vector::const_iterator fdsEnd, + std::vector::const_iterator fdsBegin, + [[maybe_unused]] std::vector::const_iterator fdsEnd, ControlSerializer *cs = nullptr) { uint32_t vecLen = readPOD(dataBegin, 0, dataEnd); std::vector ret(vecLen); std::vector::const_iterator dataIter = dataBegin + 4; - std::vector::const_iterator fdIter = fdsBegin; + std::vector::const_iterator fdIter = fdsBegin; for (uint32_t i = 0; i < vecLen; i++) { uint32_t sizeofData = readPOD(dataIter, 0, dataEnd); uint32_t sizeofFds = readPOD(dataIter, 4, dataEnd); @@ -201,11 +201,11 @@ template class IPADataSerializer> { public: - static std::tuple, std::vector> + static std::tuple, std::vector> serialize(const std::map &data, ControlSerializer *cs = nullptr) { std::vector dataVec; - std::vector fdsVec; + std::vector fdsVec; /* Serialize the length. */ uint32_t mapLen = data.size(); @@ -214,7 +214,7 @@ public: /* Serialize the members. */ for (auto const &it : data) { std::vector dvec; - std::vector fvec; + std::vector fvec; std::tie(dvec, fvec) = IPADataSerializer::serialize(it.first, cs); @@ -247,11 +247,11 @@ public: std::vector::const_iterator dataEnd, ControlSerializer *cs = nullptr) { - std::vector fds; + std::vector fds; return deserialize(dataBegin, dataEnd, fds.cbegin(), fds.end(), cs); } - static std::map deserialize(std::vector &data, std::vector &fds, + static std::map deserialize(std::vector &data, std::vector &fds, ControlSerializer *cs = nullptr) { return deserialize(data.cbegin(), data.end(), fds.cbegin(), fds.end(), cs); @@ -259,8 +259,8 @@ public: static std::map deserialize(std::vector::const_iterator dataBegin, std::vector::const_iterator dataEnd, - std::vector::const_iterator fdsBegin, - [[maybe_unused]] std::vector::const_iterator fdsEnd, + std::vector::const_iterator fdsBegin, + [[maybe_unused]] std::vector::const_iterator fdsEnd, ControlSerializer *cs = nullptr) { std::map ret; @@ -268,7 +268,7 @@ public: uint32_t mapLen = readPOD(dataBegin, 0, dataEnd); std::vector::const_iterator dataIter = dataBegin + 4; - std::vector::const_iterator fdIter = fdsBegin; + std::vector::const_iterator fdIter = fdsBegin; for (uint32_t i = 0; i < mapLen; i++) { uint32_t sizeofData = readPOD(dataIter, 0, dataEnd); uint32_t sizeofFds = readPOD(dataIter, 4, dataEnd); diff --git a/include/libcamera/internal/ipc_pipe.h b/include/libcamera/internal/ipc_pipe.h index 986f8d88..ab5dd67c 100644 --- a/include/libcamera/internal/ipc_pipe.h +++ b/include/libcamera/internal/ipc_pipe.h @@ -9,7 +9,7 @@ #include -#include +#include #include #include "libcamera/internal/ipc_unixsocket.h" @@ -33,17 +33,17 @@ public: Header &header() { return header_; } std::vector &data() { return data_; } - std::vector &fds() { return fds_; } + std::vector &fds() { return fds_; } const Header &header() const { return header_; } const std::vector &data() const { return data_; } - const std::vector &fds() const { return fds_; } + const std::vector &fds() const { return fds_; } private: Header header_; std::vector data_; - std::vector fds_; + std::vector fds_; }; class IPCPipe diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 9f556f99..5ba2b546 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -184,7 +184,7 @@ public: ~V4L2VideoDevice(); int open(); - int open(FileDescriptor handle, enum v4l2_buf_type type); + int open(SharedFD handle, enum v4l2_buf_type type); void close(); const char *driverName() const { return caps_.driver(); } diff --git a/include/libcamera/ipa/core.mojom b/include/libcamera/ipa/core.mojom index f7eff0c7..74f3339e 100644 --- a/include/libcamera/ipa/core.mojom +++ b/include/libcamera/ipa/core.mojom @@ -32,7 +32,7 @@ module libcamera; * - This attribute instructs the build system that a (de)serializer is * available for the type and there's no need to generate one * - hasFd - struct fields or empty structs only - * - Designate that this field or empty struct contains a FileDescriptor + * - Designate that this field or empty struct contains a SharedFD * * Rules: * - If the type is defined in a libcamera C++ header *and* a (de)serializer is @@ -60,7 +60,7 @@ module libcamera; * - In mojom, reference the type as FrameBuffer.Plane and only as map/array * member * - [skipHeader] and [skipSerdes] only work here in core.mojom - * - If a field in a struct has a FileDescriptor, but is not explicitly + * - If a field in a struct has a SharedFD, but is not explicitly * defined so in mojom, then the field must be marked with the [hasFd] * attribute * @@ -71,7 +71,7 @@ module libcamera; */ [skipSerdes, skipHeader] struct ControlInfoMap {}; [skipSerdes, skipHeader] struct ControlList {}; -[skipSerdes, skipHeader] struct FileDescriptor {}; +[skipSerdes, skipHeader] struct SharedFD {}; [skipHeader] struct Point { int32 x; diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index e453d46c..acd3cafe 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -35,7 +35,7 @@ struct ISPConfig { struct IPAConfig { uint32 transform; - libcamera.FileDescriptor lsTableHandle; + libcamera.SharedFD lsTableHandle; }; struct StartConfig { -- cgit v1.2.1