summaryrefslogtreecommitdiff
path: root/src/py/libcamera/py_camera_manager.h
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ideasonboard.com>2022-08-19 14:16:11 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-08-19 15:44:18 +0300
commitf814b1b6a9f3d091982b42f117630f4dc1300404 (patch)
tree306c675142a208ad3cca9dc2d39dc886c7ea4f5e /src/py/libcamera/py_camera_manager.h
parent418cbde04b8b21a7b9392808a0144dadcd56d268 (diff)
py: Create PyCameraManager
Wrap the CameraManager with a PyCameraManager class and move the related code inside the new class. This helps understanding the life times of the used-to-be global variables, gets rid of static handleRequestCompleted function, and allows us to simplify the binding code as the more complex pieces are inside the class. There should be no user visible functional changes. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/py/libcamera/py_camera_manager.h')
-rw-r--r--src/py/libcamera/py_camera_manager.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/py/libcamera/py_camera_manager.h b/src/py/libcamera/py_camera_manager.h
new file mode 100644
index 00000000..9c15f814
--- /dev/null
+++ b/src/py/libcamera/py_camera_manager.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
+ */
+
+#pragma once
+
+#include <mutex>
+
+#include <libcamera/libcamera.h>
+
+#include <pybind11/smart_holder.h>
+
+using namespace libcamera;
+
+class PyCameraManager
+{
+public:
+ PyCameraManager();
+ ~PyCameraManager();
+
+ pybind11::list cameras();
+ std::shared_ptr<Camera> get(const std::string &name) { return cameraManager_->get(name); }
+
+ static const std::string &version() { return CameraManager::version(); }
+
+ int eventFd() const { return eventFd_; }
+
+ std::vector<pybind11::object> getReadyRequests();
+
+ void handleRequestCompleted(Request *req);
+
+private:
+ std::unique_ptr<CameraManager> cameraManager_;
+
+ int eventFd_ = -1;
+ std::mutex completedRequestsMutex_;
+ std::vector<Request *> completedRequests_;
+
+ void writeFd();
+ void readFd();
+ void pushRequest(Request *req);
+ std::vector<Request *> getCompletedRequests();
+};