mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-24 00:55:07 +03:00
libcamera: camera: Handle camera objects through shared pointers
The Camera class is explicitly reference-counted to manage the lifetime of camera objects. Replace this open-coded implementation with usage of the std::shared_ptr<> class. This API change prevents pipeline handlers from subclassing the Camera class. This isn't deemed to be an issue. Mark the class final to make this explicit. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
f3695e9b09
commit
21ff749a79
6 changed files with 54 additions and 45 deletions
|
@ -7,22 +7,25 @@
|
|||
#ifndef __LIBCAMERA_CAMERA_H__
|
||||
#define __LIBCAMERA_CAMERA_H__
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Camera
|
||||
class Camera final
|
||||
{
|
||||
public:
|
||||
Camera(const std::string &name);
|
||||
static std::shared_ptr<Camera> create(const std::string &name);
|
||||
|
||||
Camera(const Camera &) = delete;
|
||||
void operator=(const Camera &) = delete;
|
||||
|
||||
const std::string &name() const;
|
||||
void get();
|
||||
void put();
|
||||
|
||||
private:
|
||||
virtual ~Camera() { };
|
||||
int ref_;
|
||||
explicit Camera(const std::string &name);
|
||||
~Camera();
|
||||
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
|
|
|
@ -24,10 +24,10 @@ public:
|
|||
int start();
|
||||
void stop();
|
||||
|
||||
const std::vector<Camera *> &cameras() const { return cameras_; }
|
||||
Camera *get(const std::string &name);
|
||||
const std::vector<std::shared_ptr<Camera>> &cameras() const { return cameras_; }
|
||||
std::shared_ptr<Camera> get(const std::string &name);
|
||||
|
||||
void addCamera(Camera *camera);
|
||||
void addCamera(std::shared_ptr<Camera> camera);
|
||||
|
||||
static CameraManager *instance();
|
||||
|
||||
|
@ -42,7 +42,7 @@ private:
|
|||
|
||||
std::unique_ptr<DeviceEnumerator> enumerator_;
|
||||
std::vector<PipelineHandler *> pipes_;
|
||||
std::vector<Camera *> cameras_;
|
||||
std::vector<std::shared_ptr<Camera>> cameras_;
|
||||
|
||||
std::unique_ptr<EventDispatcher> dispatcher_;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue