Show a patch.

GET /api/1.1/patches/269/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 269,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/269/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/269/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20190117235916.1906-4-laurent.pinchart@ideasonboard.com>",
    "date": "2019-01-17T23:59:15",
    "name": "[libcamera-devel,3/4] libcamera: camera_manager: Register cameras with the camera manager",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "c47c3ca9ba04e96b9400b8790d26888f07515cc3",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/269/mbox/",
    "series": [
        {
            "id": 90,
            "url": "https://patchwork.libcamera.org/api/1.1/series/90/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=90",
            "date": "2019-01-17T23:59:12",
            "name": "Object lifetime management",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/90/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/269/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/269/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1475360C98\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Jan 2019 00:59:21 +0100 (CET)",
            "from pendragon.bb.dnainternet.fi\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AA5F8558\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Jan 2019 00:59:20 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1547769560;\n\tbh=BCmQvI98I0BXOsQ8vk/ummh4rX9zomnw65nmhCAHLOs=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=OOVxhQoiPWGnx6+y5kgs/g9kyPP6VBZYM2MNwo4zSusTTaoqF0FxNghohXclUTfeI\n\tvE/fWGxSOso7uIpw2cwSgEj+sq7zI9je163bNrikKlc4/smdjSg/4ueIxgf4x6x0x7\n\tQeh33hp81l5DqyU0eZk/F86NPgW6KxdqT8x4IEFU=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 18 Jan 2019 01:59:15 +0200",
        "Message-Id": "<20190117235916.1906-4-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.19.2",
        "In-Reply-To": "<20190117235916.1906-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20190117235916.1906-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 3/4] libcamera: camera_manager: Register\n\tcameras with the camera manager",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.23",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "X-List-Received-Date": "Thu, 17 Jan 2019 23:59:21 -0000"
    },
    "content": "Cameras are listed through a double indirection, first iterating over\nall available pipeline handlers, and then listing the cameras they each\nsupport. To simplify the API make the pipeline handlers register the\ncameras with the camera manager directly, which lets the camera manager\neasily expose the list of all available cameras.\n\nThe PipelineHandler API gets simplified as the handlers don't need to\nexpose the list of cameras they have created.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/camera_manager.h       |  5 ++-\n src/libcamera/camera_manager.cpp         | 44 +++++++++++-------------\n src/libcamera/include/pipeline_handler.h |  6 ++--\n src/libcamera/pipeline/vimc.cpp          | 30 ++++------------\n src/libcamera/pipeline_handler.cpp       | 21 +++--------\n test/list-cameras.cpp                    |  5 +--\n 6 files changed, 40 insertions(+), 71 deletions(-)",
    "diff": "diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h\nindex b82a8ce95b9f..4b941fd9183b 100644\n--- a/include/libcamera/camera_manager.h\n+++ b/include/libcamera/camera_manager.h\n@@ -24,9 +24,11 @@ public:\n \tint start();\n \tvoid stop();\n \n-\tstd::vector<std::string> list() const;\n+\tconst std::vector<Camera *> &cameras() const { return cameras_; }\n \tCamera *get(const std::string &name);\n \n+\tvoid addCamera(Camera *camera);\n+\n \tstatic CameraManager *instance();\n \n \tvoid setEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher);\n@@ -40,6 +42,7 @@ private:\n \n \tstd::unique_ptr<DeviceEnumerator> enumerator_;\n \tstd::vector<PipelineHandler *> pipes_;\n+\tstd::vector<Camera *> cameras_;\n \n \tstd::unique_ptr<EventDispatcher> dispatcher_;\n };\ndiff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\nindex 9806e399f92b..852e5ed70fe3 100644\n--- a/src/libcamera/camera_manager.cpp\n+++ b/src/libcamera/camera_manager.cpp\n@@ -93,7 +93,7 @@ int CameraManager::start()\n \t\t */\n \t\twhile (1) {\n \t\t\tPipelineHandler *pipe = factory->create();\n-\t\t\tif (!pipe->match(enumerator_.get())) {\n+\t\t\tif (!pipe->match(this, enumerator_.get())) {\n \t\t\t\tdelete pipe;\n \t\t\t\tbreak;\n \t\t\t}\n@@ -132,26 +132,14 @@ void CameraManager::stop()\n }\n \n /**\n- * \\brief List all detected cameras\n+ * \\fn CameraManager::cameras()\n+ * \\brief Retrieve all available cameras\n  *\n  * Before calling this function the caller is responsible for ensuring that\n  * the camera manger is running.\n  *\n- * \\return List of names for all detected cameras\n+ * \\return List of all available cameras\n  */\n-std::vector<std::string> CameraManager::list() const\n-{\n-\tstd::vector<std::string> list;\n-\n-\tfor (PipelineHandler *pipe : pipes_) {\n-\t\tfor (unsigned int i = 0; i < pipe->count(); i++) {\n-\t\t\tCamera *cam = pipe->camera(i);\n-\t\t\tlist.push_back(cam->name());\n-\t\t}\n-\t}\n-\n-\treturn list;\n-}\n \n /**\n  * \\brief Get a camera based on name\n@@ -167,19 +155,27 @@ std::vector<std::string> CameraManager::list() const\n  */\n Camera *CameraManager::get(const std::string &name)\n {\n-\tfor (PipelineHandler *pipe : pipes_) {\n-\t\tfor (unsigned int i = 0; i < pipe->count(); i++) {\n-\t\t\tCamera *cam = pipe->camera(i);\n-\t\t\tif (cam->name() == name) {\n-\t\t\t\tcam->get();\n-\t\t\t\treturn cam;\n-\t\t\t}\n-\t\t}\n+\tfor (Camera *camera : cameras_) {\n+\t\tif (camera->name() == name)\n+\t\t\treturn camera;\n \t}\n \n \treturn nullptr;\n }\n \n+/**\n+ * \\brief Add a camera to the camera manager\n+ * \\param[in] camera The camera to be added\n+ *\n+ * This function is called by pipeline handlers to register the cameras they\n+ * handle with the camera manager. Registered cameras are immediately made\n+ * available to the system.\n+ */\n+void CameraManager::addCamera(Camera *camera)\n+{\n+\tcameras_.push_back(camera);\n+}\n+\n /**\n  * \\brief Retrieve the camera manager instance\n  *\ndiff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h\nindex e976aaa13546..f05f201f7ca8 100644\n--- a/src/libcamera/include/pipeline_handler.h\n+++ b/src/libcamera/include/pipeline_handler.h\n@@ -15,6 +15,7 @@\n \n namespace libcamera {\n \n+class CameraManager;\n class DeviceEnumerator;\n \n class PipelineHandler\n@@ -22,10 +23,7 @@ class PipelineHandler\n public:\n \tvirtual ~PipelineHandler() { };\n \n-\tvirtual bool match(DeviceEnumerator *enumerator) = 0;\n-\n-\tvirtual unsigned int count() = 0;\n-\tvirtual Camera *camera(unsigned int id) = 0;\n+\tvirtual bool match(CameraManager *manager, DeviceEnumerator *enumerator) = 0;\n };\n \n class PipelineHandlerFactory\ndiff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\nindex 720d9c2031c9..8742e0bae9a8 100644\n--- a/src/libcamera/pipeline/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc.cpp\n@@ -6,6 +6,7 @@\n  */\n \n #include <libcamera/camera.h>\n+#include <libcamera/camera_manager.h>\n \n #include \"device_enumerator.h\"\n #include \"media_device.h\"\n@@ -19,44 +20,24 @@ public:\n \tPipeHandlerVimc();\n \t~PipeHandlerVimc();\n \n-\tbool match(DeviceEnumerator *enumerator);\n-\n-\tunsigned int count();\n-\tCamera *camera(unsigned int id) final;\n+\tbool match(CameraManager *manager, DeviceEnumerator *enumerator);\n \n private:\n \tMediaDevice *dev_;\n-\tCamera *camera_;\n };\n \n PipeHandlerVimc::PipeHandlerVimc()\n-\t: dev_(nullptr), camera_(nullptr)\n+\t: dev_(nullptr)\n {\n }\n \n PipeHandlerVimc::~PipeHandlerVimc()\n {\n-\tif (camera_)\n-\t\tcamera_->put();\n-\n \tif (dev_)\n \t\tdev_->release();\n }\n \n-unsigned int PipeHandlerVimc::count()\n-{\n-\treturn 1;\n-}\n-\n-Camera *PipeHandlerVimc::camera(unsigned int id)\n-{\n-\tif (id != 0)\n-\t\treturn nullptr;\n-\n-\treturn camera_;\n-}\n-\n-bool PipeHandlerVimc::match(DeviceEnumerator *enumerator)\n+bool PipeHandlerVimc::match(CameraManager *manager, DeviceEnumerator *enumerator)\n {\n \tDeviceMatch dm(\"vimc\");\n \n@@ -83,7 +64,8 @@ bool PipeHandlerVimc::match(DeviceEnumerator *enumerator)\n \t * will be chosen depends on how the Camera\n \t * object is modeled.\n \t */\n-\tcamera_ = new Camera(\"Dummy VIMC Camera\");\n+\tCamera *camera = new Camera(\"Dummy VIMC Camera\");\n+\tmanager->addCamera(camera);\n \n \treturn true;\n }\ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex c19ab94f1774..f2e08a6a7315 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -35,13 +35,15 @@ namespace libcamera {\n /**\n  * \\fn PipelineHandler::match(DeviceEnumerator *enumerator)\n  * \\brief Match media devices and create camera instances\n+ * \\param manager The camera manager\n  * \\param enumerator The enumerator providing all media devices found in the\n  * system\n  *\n  * This function is the main entry point of the pipeline handler. It is called\n- * by the camera manager with the \\a enumerator passed as an argument. It\n- * shall acquire from the \\a enumerator all the media devices it needs for a\n- * single pipeline and create one or multiple Camera instances.\n+ * by the camera manager with the \\a manager and \\a enumerator passed as\n+ * arguments. It shall acquire from the \\a enumerator all the media devices it\n+ * needs for a single pipeline, create one or multiple Camera instances and\n+ * register them with the \\a manager.\n  *\n  * If all media devices needed by the pipeline handler are found, they must all\n  * be acquired by a call to MediaDevice::acquire(). This function shall then\n@@ -62,19 +64,6 @@ namespace libcamera {\n  * created, or false otherwise\n  */\n \n-/**\n- * \\fn PipelineHandler::count()\n- * \\brief Retrieve the number of cameras handled by this pipeline handler\n- * \\return the number of cameras that were created by the match() function\n- */\n-\n-/**\n- * \\fn PipelineHandler::camera(unsigned int id)\n- * \\brief Retrieve one of the cameras handled by this pipeline handler\n- * \\param[in] id the camera index\n- * \\return a pointer to the Camera identified by \\a id\n- */\n-\n /**\n  * \\class PipelineHandlerFactory\n  * \\brief Registration of PipelineHandler classes and creation of instances\ndiff --git a/test/list-cameras.cpp b/test/list-cameras.cpp\nindex e2026c99c5b8..fdbbda0957b2 100644\n--- a/test/list-cameras.cpp\n+++ b/test/list-cameras.cpp\n@@ -7,6 +7,7 @@\n \n #include <iostream>\n \n+#include <libcamera/camera.h>\n #include <libcamera/camera_manager.h>\n \n #include \"test.h\"\n@@ -29,8 +30,8 @@ protected:\n \t{\n \t\tunsigned int count = 0;\n \n-\t\tfor (auto name : cm->list()) {\n-\t\t\tcout << \"- \" << name << endl;\n+\t\tfor (Camera *camera : cm->cameras()) {\n+\t\t\tcout << \"- \" << camera->name() << endl;\n \t\t\tcount++;\n \t\t}\n \n",
    "prefixes": [
        "libcamera-devel",
        "3/4"
    ]
}