diff options
-rw-r--r-- | include/libcamera/camera_manager.h | 8 | ||||
-rw-r--r-- | src/libcamera/camera_manager.cpp | 15 | ||||
-rw-r--r-- | test/list.cpp | 7 |
3 files changed, 22 insertions, 8 deletions
diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h index 2768a5bd..e14da0f8 100644 --- a/include/libcamera/camera_manager.h +++ b/include/libcamera/camera_manager.h @@ -19,15 +19,19 @@ class PipelineHandler; class CameraManager { public: - CameraManager(); - int start(); void stop(); std::vector<std::string> list() const; Camera *get(const std::string &name); + static CameraManager *instance(); + private: + CameraManager(); + CameraManager(const CameraManager &) = delete; + void operator=(const CameraManager &) = delete; + DeviceEnumerator *enumerator_; std::vector<PipelineHandler *> pipes_; }; diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 50a805fc..1a9d2f38 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -161,4 +161,19 @@ Camera *CameraManager::get(const std::string &name) return nullptr; } +/** + * \brief Retrieve the camera manager instance + * + * The CameraManager is a singleton and can't be constructed manually. This + * function shall instead be used to retrieve the single global instance of the + * manager. + * + * \return The camera manager instance + */ +CameraManager *CameraManager::instance() +{ + static CameraManager manager; + return &manager; +} + } /* namespace libcamera */ diff --git a/test/list.cpp b/test/list.cpp index 39b8a41d..e2026c99 100644 --- a/test/list.cpp +++ b/test/list.cpp @@ -19,10 +19,7 @@ class ListTest : public Test protected: int init() { - cm = new CameraManager(); - if (!cm) - return -ENOMEM; - + cm = CameraManager::instance(); cm->start(); return 0; @@ -43,8 +40,6 @@ protected: void cleanup() { cm->stop(); - - delete cm; } private: |