libcamera: base: extensible: Pass private pointer as unique_ptr<>
The Extensible constructor takes a pointer to a Private instance, whose lifetime it then manages. Make this explicit in the API by passing the pointer as a std::unique_ptr<Private>. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
5420e359f2
commit
e77c8951e9
7 changed files with 16 additions and 8 deletions
|
@ -87,7 +87,7 @@ public:
|
||||||
Extensible *const o_;
|
Extensible *const o_;
|
||||||
};
|
};
|
||||||
|
|
||||||
Extensible(Private *d);
|
Extensible(std::unique_ptr<Private> d);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
|
|
||||||
#define PUBLIC_CAMERA_BUFFER_IMPLEMENTATION \
|
#define PUBLIC_CAMERA_BUFFER_IMPLEMENTATION \
|
||||||
CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) \
|
CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) \
|
||||||
: Extensible(new Private(this, camera3Buffer, flags)) \
|
: Extensible(std::make_unique<Private>(this, camera3Buffer, flags)) \
|
||||||
{ \
|
{ \
|
||||||
} \
|
} \
|
||||||
CameraBuffer::~CameraBuffer() \
|
CameraBuffer::~CameraBuffer() \
|
||||||
|
|
|
@ -341,7 +341,7 @@ int CameraHalConfig::Private::parseConfigFile(FILE *fh,
|
||||||
}
|
}
|
||||||
|
|
||||||
CameraHalConfig::CameraHalConfig()
|
CameraHalConfig::CameraHalConfig()
|
||||||
: Extensible(new Private()), exists_(false), valid_(false)
|
: Extensible(std::make_unique<Private>()), exists_(false), valid_(false)
|
||||||
{
|
{
|
||||||
parseConfigurationFile();
|
parseConfigurationFile();
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,9 +147,12 @@ namespace libcamera {
|
||||||
/**
|
/**
|
||||||
* \brief Construct an instance of an Extensible class
|
* \brief Construct an instance of an Extensible class
|
||||||
* \param[in] d Pointer to the private data instance
|
* \param[in] d Pointer to the private data instance
|
||||||
|
*
|
||||||
|
* The private data lifetime is managed by the Extensible class, which destroys
|
||||||
|
* it when the Extensible instance is destroyed.
|
||||||
*/
|
*/
|
||||||
Extensible::Extensible(Extensible::Private *d)
|
Extensible::Extensible(std::unique_ptr<Extensible::Private> d)
|
||||||
: d_(d)
|
: d_(std::move(d))
|
||||||
{
|
{
|
||||||
*const_cast<Extensible **>(&d_->o_) = this;
|
*const_cast<Extensible **>(&d_->o_) = this;
|
||||||
}
|
}
|
||||||
|
@ -163,6 +166,10 @@ Extensible::Extensible(Extensible::Private *d)
|
||||||
* overriden _d() functions that return the correct pointer type to the
|
* overriden _d() functions that return the correct pointer type to the
|
||||||
* corresponding derived Private class.
|
* corresponding derived Private class.
|
||||||
*
|
*
|
||||||
|
* The lifetime of the private data is tied to the Extensible class. The caller
|
||||||
|
* shall not retain any reference to the returned pointer for longer than it
|
||||||
|
* holds a reference to the Extensible instance.
|
||||||
|
*
|
||||||
* \return A pointer to the private data instance
|
* \return A pointer to the private data instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -596,7 +596,7 @@ const std::string &Camera::id() const
|
||||||
|
|
||||||
Camera::Camera(PipelineHandler *pipe, const std::string &id,
|
Camera::Camera(PipelineHandler *pipe, const std::string &id,
|
||||||
const std::set<Stream *> &streams)
|
const std::set<Stream *> &streams)
|
||||||
: Extensible(new Private(pipe, id, streams))
|
: Extensible(std::make_unique<Private>(pipe, id, streams))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -258,7 +258,7 @@ void CameraManager::Private::removeCamera(Camera *camera)
|
||||||
CameraManager *CameraManager::self_ = nullptr;
|
CameraManager *CameraManager::self_ = nullptr;
|
||||||
|
|
||||||
CameraManager::CameraManager()
|
CameraManager::CameraManager()
|
||||||
: Extensible(new CameraManager::Private())
|
: Extensible(std::make_unique<CameraManager::Private>())
|
||||||
{
|
{
|
||||||
if (self_)
|
if (self_)
|
||||||
LOG(Camera, Fatal)
|
LOG(Camera, Fatal)
|
||||||
|
|
|
@ -181,7 +181,8 @@ FrameBuffer::Private::Private()
|
||||||
* \param[in] cookie Cookie
|
* \param[in] cookie Cookie
|
||||||
*/
|
*/
|
||||||
FrameBuffer::FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie)
|
FrameBuffer::FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie)
|
||||||
: Extensible(new Private()), planes_(planes), cookie_(cookie)
|
: Extensible(std::make_unique<Private>()), planes_(planes),
|
||||||
|
cookie_(cookie)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue