From 33dd4fab9d39726be4fcbd300a27f2640be1cd6f Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 23 Jul 2021 02:41:16 +0300 Subject: libcamera: base: class: Don't pass Extensible pointer to Private constructor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Extensible and Extensible::Private classes contain pointers to each other. These pointers are initialized in the respective class's constructor, by passing a pointer to the other class to each constructor. This particular construct reduces the flexibility of the Extensible pattern, as the Private class instance has to be allocated and constructed in the members initializer list of the Extensible class's constructor. It is thus impossible to perform any operation on the Private class between its construction and the construction of the Extensible class, or to subclass the Private class without subclassing the Extensible class. To make the design pattern more flexible, don't pass the pointer to the Extensible class to the Private class's constructor, but initialize the pointer manually in the Extensible class's constructor. This requires a const_cast as the o_ member of the Private class is const. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/libcamera/camera.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libcamera/camera.cpp') diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index c8858e71..c126b492 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -344,7 +344,7 @@ public: CameraRunning, }; - Private(Camera *camera, PipelineHandler *pipe, const std::string &id, + Private(PipelineHandler *pipe, const std::string &id, const std::set &streams); ~Private(); @@ -368,11 +368,11 @@ private: std::atomic state_; }; -Camera::Private::Private(Camera *camera, PipelineHandler *pipe, +Camera::Private::Private(PipelineHandler *pipe, const std::string &id, const std::set &streams) - : Extensible::Private(camera), pipe_(pipe->shared_from_this()), id_(id), - streams_(streams), disconnected_(false), state_(CameraAvailable) + : pipe_(pipe->shared_from_this()), id_(id), streams_(streams), + disconnected_(false), state_(CameraAvailable) { } @@ -632,7 +632,7 @@ const std::string &Camera::id() const Camera::Camera(PipelineHandler *pipe, const std::string &id, const std::set &streams) - : Extensible(new Private(this, pipe, id, streams)) + : Extensible(new Private(pipe, id, streams)) { } -- cgit v1.2.1