Patch Detail
Show a patch.
GET /api/1.1/patches/9676/?format=api
{ "id": 9676, "url": "https://patchwork.libcamera.org/api/1.1/patches/9676/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9676/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200921031057.3564-2-laurent.pinchart@ideasonboard.com>", "date": "2020-09-21T03:10:54", "name": "[libcamera-devel,1/4] libcamera: Add a base class to implement the d-pointer design pattern", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "dcca2869f1a56fa4de25f6511e4c0e89f2a63872", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/9676/mbox/", "series": [ { "id": 1301, "url": "https://patchwork.libcamera.org/api/1.1/series/1301/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1301", "date": "2020-09-21T03:10:53", "name": "libcamera: Implement d-pointer design pattern", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1301/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9676/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9676/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 55E99BF01C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Sep 2020 03:11:37 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5EEBE62FD9;\n\tMon, 21 Sep 2020 05:11:36 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F2A7862FAC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Sep 2020 05:11:33 +0200 (CEST)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 869FF2D7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Sep 2020 05:11:33 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"c4+1uxWs\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1600657893;\n\tbh=fXxAeNjOVnTKLLk+0saSmrzwC+n5kR59TyTRm8Lerik=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=c4+1uxWsmMxI6aHgSAWO7IBCJcY5a2Frh7I9SVi9TP8avR0ZoMuOQZswqAiSDRrGl\n\taF19m5m3xTGGaRVixJEY3+Z1Exn2TlibDNR94Wp6CVkRGP4BPR3kPZlFsjPU9doDix\n\tihnC7xHi7FBYfMRiqnlSXkVx9OkZiUzpKgRreb5E=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 21 Sep 2020 06:10:54 +0300", "Message-Id": "<20200921031057.3564-2-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.27.0", "In-Reply-To": "<20200921031057.3564-1-laurent.pinchart@ideasonboard.com>", "References": "<20200921031057.3564-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH 1/4] libcamera: Add a base class to\n\timplement the d-pointer design pattern", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The d-pointer design patterns helps creating public classes that can be\nextended without breaking their ABI. To facilitate usage of the pattern\nin libcamera, create a base Extensible class with associated macros.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/extensible.h | 80 +++++++++++++++++++++\n include/libcamera/meson.build | 1 +\n src/libcamera/extensible.cpp | 127 +++++++++++++++++++++++++++++++++\n src/libcamera/meson.build | 1 +\n 4 files changed, 209 insertions(+)\n create mode 100644 include/libcamera/extensible.h\n create mode 100644 src/libcamera/extensible.cpp", "diff": "diff --git a/include/libcamera/extensible.h b/include/libcamera/extensible.h\nnew file mode 100644\nindex 000000000000..0fa3bcdbeac5\n--- /dev/null\n+++ b/include/libcamera/extensible.h\n@@ -0,0 +1,80 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * extensible.h - Utilities to create extensible public classes with stable ABIs\n+ */\n+#ifndef __LIBCAMERA_EXTENSIBLE_H__\n+#define __LIBCAMERA_EXTENSIBLE_H__\n+\n+#include <memory>\n+\n+namespace libcamera {\n+\n+#ifndef __DOXYGEN__\n+#define LIBCAMERA_DECLARE_PRIVATE(klass)\t\t\t\t\\\n+public:\t\t\t\t\t\t\t\t\t\\\n+\tclass Private;\t\t\t\t\t\t\t\\\n+\tfriend class Private;\n+\n+#define LIBCAMERA_DECLARE_PUBLIC(klass)\t\t\t\t\t\\\n+private:\t\t\t\t\t\t\t\t\\\n+\tfriend class klass;\t\t\t\t\t\t\\\n+\tconst klass *_o() const\t\t\t\t\t\t\\\n+\t{\t\t\t\t\t\t\t\t\\\n+\t\treturn static_cast<const klass *>(o_);\t\t\t\\\n+\t}\t\t\t\t\t\t\t\t\\\n+\tklass *_o()\t\t\t\t\t\t\t\\\n+\t{\t\t\t\t\t\t\t\t\\\n+\t\treturn static_cast<klass *>(o_);\t\t\t\\\n+\t}\n+\n+#define LIBCAMERA_D_PTR(klass)\t\t\t\t\t\t\\\n+\tauto * const d = _d<klass::Private>();\n+\n+#define LIBCAMERA_O_PTR(klass)\t\t\t\t\t\t\\\n+\tauto * const o = _o();\n+\n+#else\n+#define LIBCAMERA_DECLARE_PRIVATE(klass)\n+#define LIBCAMERA_DECLARE_PUBLIC(klass)\n+#define LIBCAMERA_D_PTR(klass)\n+#define LIBCAMERA_O_PTR(klass)\n+#endif\n+\n+class Extensible\n+{\n+public:\n+\tclass Private\n+\t{\n+\tpublic:\n+\t\tPrivate(Extensible *o);\n+\t\tvirtual ~Private();\n+\n+\t\tExtensible * const o_;\n+\t};\n+\n+\tExtensible(Private *d);\n+\n+protected:\n+#ifndef __DOXYGEN__\n+\ttemplate<typename T>\n+\tconst T *_d() const\n+\t{\n+\t\treturn static_cast<const T *>(d_.get());\n+\t}\n+\n+\ttemplate<typename T>\n+\tT *_d()\n+\t{\n+\t\treturn static_cast<T*>(d_.get());\n+\t}\n+#endif\n+\n+private:\n+\tconst std::unique_ptr<Private> d_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_EXTENSIBLE_H__ */\ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex cdb8e0372e77..0a06dab0e105 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -8,6 +8,7 @@ libcamera_public_headers = files([\n 'controls.h',\n 'event_dispatcher.h',\n 'event_notifier.h',\n+ 'extensible.h',\n 'file_descriptor.h',\n 'framebuffer_allocator.h',\n 'geometry.h',\ndiff --git a/src/libcamera/extensible.cpp b/src/libcamera/extensible.cpp\nnew file mode 100644\nindex 000000000000..b2a7fc5d5304\n--- /dev/null\n+++ b/src/libcamera/extensible.cpp\n@@ -0,0 +1,127 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * extensible.cpp - Utilities to create extensible public classes with stable ABIs\n+ */\n+\n+#include <libcamera/extensible.h>\n+\n+/**\n+ * \\file extensible.h\n+ * \\brief Utilities to create extensible public classes with stable ABIs\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\def LIBCAMERA_DECLARE_PRIVATE\n+ * \\brief Declare private data for a public class\n+ * \\param klass The public class name\n+ *\n+ * The LIBCAMERA_DECLARE_PRIVATE() macro plumbs the infrastructure necessary to\n+ * make a class manage its private data through a d-pointer. It shall be used at\n+ * the very top of the class definition, with the public class name passed as\n+ * the \\a klass parameter.\n+ */\n+\n+/**\n+ * \\def LIBCAMERA_DECLARE_PUBLIC\n+ * \\brief Declare public data for a private class\n+ * \\param klass The public class name\n+ *\n+ * The LIBCAMERA_DECLARE_PUBLIC() macro is the counterpart of\n+ * LIBCAMERA_DECLARE_PRIVATE() to be used in the private data class. It shall be\n+ * used at the very top of the private class definition, with the public class\n+ * name passed as the \\a klass parameter.\n+ */\n+\n+/**\n+ * \\def LIBCAMERA_D_PTR(klass)\n+ * \\brief Retrieve the private data pointer\n+ * \\param[in] klass The public class name\n+ *\n+ * This macro can be used in any member function of a class that inherits,\n+ * directly or indirectly, from the Extensible class, to create a local\n+ * variable named 'd' that points to the class' private data instance.\n+ */\n+\n+/**\n+ * \\def LIBCAMERA_O_PTR(klass)\n+ * \\brief Retrieve the public instance corresponding to the private data\n+ * \\param[in] klass The public class name\n+ *\n+ * This macro is the counterpart of LIBCAMERA_D_PTR() for private data classes.\n+ * It can be used in any member function of the private data class to create a\n+ * local variable named 'o' that ponits to the public class instance\n+ * corresponding to the private data.\n+ */\n+\n+/**\n+ * \\class Extensible\n+ * \\brief Base class to manage private data through a d-pointer\n+ *\n+ * The Extensible class provides a base class to implement the\n+ * <a href=\"https://wiki.qt.io/D-Pointer\">d-pointer</a> design pattern (also\n+ * known as <a href=\"https://en.wikipedia.org/wiki/Opaque_pointer\">opaque pointer</a>\n+ * or <a href=\"https://en.cppreference.com/w/cpp/language/pimpl\">pImpl idiom</a>).\n+ * It helps creating public classes that can be extended without breaking their\n+ * ABI. Such classes store their private data in a separate private data object,\n+ * referenced by a pointer in the public class (hence the name d-pointer).\n+ *\n+ * Classes that follow this design pattern are referred herein as extensible\n+ * classes. To be extensible, a class PublicClass shall\n+ *\n+ * - inherit from the Extensible class or from another extensible class\n+ * - invoke the LIBCAMERA_DECLARE_PRIVATE() macro at the very top of the class\n+ * definition\n+ * - define a private data class named PublicClass::Private that inherits from\n+ * the Private data class of the base class\n+ * - invoke the LIBCAMERA_DECLARE_PUBLIC() macro at the very top of the Private\n+ * data class definition\n+ * - pass a std::unique_ptr to a newly allocated Private data object to the\n+ * constructor of the base class\n+ *\n+ * Additionally, if the PublicClass is not final, it shall expose one or more\n+ * constructors that takes a pointer to a Private data instance, to be used by\n+ * derived classes.\n+ */\n+\n+/**\n+ * \\brief Construct an instance of an Extensible class\n+ * \\param[in] d Pointer to the private data instance\n+ */\n+Extensible::Extensible(Extensible::Private *d)\n+\t: d_(d)\n+{\n+}\n+\n+/**\n+ * \\var Extensible::d_\n+ * \\brief Pointer to the private data instance\n+ */\n+\n+/**\n+ * \\class Extensible::Private\n+ * \\brief Base class for private data managed through a d-pointer\n+ */\n+\n+/**\n+ * \\brief Construct an instance of an Extensible class private data\n+ * \\param[in] o Pointer to the public class object\n+ */\n+Extensible::Private::Private(Extensible *o)\n+\t: o_(o)\n+{\n+}\n+\n+Extensible::Private::~Private()\n+{\n+}\n+\n+/**\n+ * \\var Extensible::Private::o_\n+ * \\brief Pointer to the public class object\n+ */\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 0e6ecf5060a4..16c9c81440f5 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -16,6 +16,7 @@ libcamera_sources = files([\n 'event_dispatcher.cpp',\n 'event_dispatcher_poll.cpp',\n 'event_notifier.cpp',\n+ 'extensible.cpp',\n 'file.cpp',\n 'file_descriptor.cpp',\n 'formats.cpp',\n", "prefixes": [ "libcamera-devel", "1/4" ] }