Show a patch.

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

{
    "id": 3792,
    "url": "https://patchwork.libcamera.org/api/patches/3792/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/3792/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20200513172950.72685-5-email@uajain.com>",
    "date": "2020-05-13T17:30:00",
    "name": "[libcamera-devel,v2,4/5] qcam: main_window: Introduce hotplug support",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "88fe321bdea40c6041dcc196c5aeb2f473307d22",
    "submitter": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/people/1/?format=api",
        "name": "Umang Jain",
        "email": "email@uajain.com"
    },
    "delegate": {
        "id": 12,
        "url": "https://patchwork.libcamera.org/api/users/12/?format=api",
        "username": "uajain",
        "first_name": "Umang",
        "last_name": "Jain",
        "email": "umang.jain@ideasonboard.com"
    },
    "mbox": "https://patchwork.libcamera.org/patch/3792/mbox/",
    "series": [
        {
            "id": 903,
            "url": "https://patchwork.libcamera.org/api/series/903/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=903",
            "date": "2020-05-13T17:29:57",
            "name": "Introduce UVC hotplug support",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/903/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/3792/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/3792/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<bounces+15657259-5c31-libcamera-devel=lists.libcamera.org@em7280.uajain.com>",
        "Received": [
            "from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8ED6660DFF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 May 2020 19:30:02 +0200 (CEST)",
            "by filter0072p3las1.sendgrid.net with SMTP id\n\tfilter0072p3las1-6642-5EBC2E98-17B\n\t2020-05-13 17:30:00.930007584 +0000 UTC m=+2402884.819728798",
            "from mail.uajain.com (unknown)\n\tby ismtpd0001p1maa1.sendgrid.net (SG) with ESMTP\n\tid 3v7NZwMDTz2Lz20o5j-dDw Wed, 13 May 2020 17:30:00.181 +0000 (UTC)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=uajain.com\n\theader.i=@uajain.com header.b=\"jTXSiAMJ\"; \n\tdkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com;\n\th=from:subject:in-reply-to:references:mime-version:to:cc:\n\tcontent-transfer-encoding:content-type;\n\ts=s1; bh=vQG8D4Rs2e+3VRzx4T+kw1iaoiDSgpaV3ULjJUAPrsI=;\n\tb=jTXSiAMJl4n/amseeBFMogLG+3AnaNoyM9jqq55o3j4msCf5XAk8IoMj5UikBL4/BybI\n\tw3G9U0qRuWGvwk5dkf6T/6wtUXgumd/MH17vJ4znK3IVMegOEiSMVk2XrAVmwPLkYpK+o/\n\tjr82yQycDMFHiQMjuEJdMXPqNTri46ScI=",
        "From": "Umang Jain <email@uajain.com>",
        "Date": "Wed, 13 May 2020 17:30:00 +0000 (UTC)",
        "Message-Id": "<20200513172950.72685-5-email@uajain.com>",
        "In-Reply-To": "<20200513172950.72685-1-email@uajain.com>",
        "References": "<20200513172950.72685-1-email@uajain.com>",
        "Mime-Version": "1.0",
        "X-SG-EID": "1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcROc560Os82e1tQwAlD2FoFmN5OulnnhnFwgFz4a1BpblVayaQjtPgzBnzvPCHP5XF8rSK9ay1hcdUKpmjYejxIF4TLI7ULNS7cSUuzXvBcoi6PaATAHiIHsntyR2+mlCOMVhtqruEhw7HTnKfAE9R7e0FSmjTx0aqURAAWvRtcXQxEplTgK1x63U11jfVaHv",
        "To": "libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Content-Transfer-Encoding": "7bit",
        "Content-Type": "text/plain; charset=us-ascii",
        "Subject": "[libcamera-devel] [PATCH v2 4/5] qcam: main_window: Introduce\n\thotplug support",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "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": "Wed, 13 May 2020 17:30:04 -0000"
    },
    "content": "Signed-off-by: Umang Jain <email@uajain.com>\n---\n src/qcam/main_window.cpp | 83 ++++++++++++++++++++++++++++++++++++++++\n src/qcam/main_window.h   |  6 +++\n 2 files changed, 89 insertions(+)",
    "diff": "diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 7de0895..d595112 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -49,6 +49,43 @@ public:\n \t}\n };\n \n+/**\n+ * \\brief Custom QEvent to signal hotplug or unplug\n+ */\n+class HotplugEvent : public QEvent\n+{\n+public:\n+\tenum PLUGEVENT {\n+\t\tHOTPLUG,\n+\t\tUNPLUG\n+\t};\n+\n+\tHotplugEvent(std::shared_ptr<Camera> camera, PLUGEVENT event)\n+\t\t: QEvent(type())\n+\t{\n+\t\tcamera_ = camera;\n+\t\tplugEvent_ = event;\n+\t}\n+\n+\t~HotplugEvent()\n+\t{\n+\t\tcamera_.reset();\n+\t}\n+\n+\tstatic Type type()\n+\t{\n+\t\tstatic int type = QEvent::registerEventType();\n+\t\treturn static_cast<Type>(type);\n+\t}\n+\n+\tPLUGEVENT getHotplugEvent() { return plugEvent_; }\n+\tCamera *getCamera() { return camera_.get(); }\n+\n+private:\n+\tstd::shared_ptr<Camera> camera_;\n+\tPLUGEVENT plugEvent_;\n+};\n+\n MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)\n \t: saveRaw_(nullptr), options_(options), cm_(cm), allocator_(nullptr),\n \t  isCapturing_(false), captureRaw_(false)\n@@ -71,6 +108,10 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)\n \tsetCentralWidget(viewfinder_);\n \tadjustSize();\n \n+\t/* Hotplug/unplug support */\n+\tcm_->cameraAdded.connect(this, &MainWindow::addNewCamera);\n+\tcm_->cameraRemoved.connect(this, &MainWindow::removeCamera);\n+\n \t/* Open the camera and start capture. */\n \tret = openCamera();\n \tif (ret < 0) {\n@@ -95,6 +136,9 @@ bool MainWindow::event(QEvent *e)\n \tif (e->type() == CaptureEvent::type()) {\n \t\tprocessCapture();\n \t\treturn true;\n+\t} else if (e->type() == HotplugEvent::type()) {\n+\t\tprocessHotplug(static_cast<HotplugEvent *>(e));\n+\t\treturn true;\n \t}\n \n \treturn QMainWindow::event(e);\n@@ -525,6 +569,45 @@ void MainWindow::stopCapture()\n \tsetWindowTitle(title_);\n }\n \n+/* -----------------------------------------------------------------------------\n+ * Camera hotplugging support\n+ */\n+\n+void MainWindow::processHotplug(HotplugEvent *e)\n+{\n+\tCamera *camera = e->getCamera();\n+\tHotplugEvent::PLUGEVENT event = e->getHotplugEvent();\n+\n+\tif (event == HotplugEvent::PLUGEVENT::HOTPLUG) {\n+\t\tcameraCombo_->addItem(QString::fromStdString(camera->name()));\n+\t} else if (event == HotplugEvent::PLUGEVENT::UNPLUG) {\n+\t\tint camIndex = cameraCombo_->findText(QString::fromStdString(camera->name()));\n+\n+\t\t/* Check if the currently-streaming camera is removed. */\n+\t\tif (camera == camera_.get()) {\n+\t\t\ttoggleCapture(false);\n+\t\t\tcameraCombo_->setCurrentIndex(0);\n+\t\t}\n+\t\tcameraCombo_->removeItem(camIndex);\n+\t}\n+}\n+\n+void MainWindow::addNewCamera(std::shared_ptr<Camera> camera)\n+{\n+\tqInfo() << \"Adding new camera:\" << camera->name().c_str();\n+\tQCoreApplication::postEvent(this,\n+\t\t\t\t    new HotplugEvent(std::move(camera),\n+\t\t\t\t\t\t     HotplugEvent::PLUGEVENT::HOTPLUG));\n+}\n+\n+void MainWindow::removeCamera(std::shared_ptr<Camera> camera)\n+{\n+\tqInfo() << \"Removing camera:\" << camera->name().c_str();\n+\tQCoreApplication::postEvent(this,\n+\t\t\t\t    new HotplugEvent(std::move(camera),\n+\t\t\t\t\t\t     HotplugEvent::PLUGEVENT::UNPLUG));\n+}\n+\n /* -----------------------------------------------------------------------------\n  * Image Save\n  */\ndiff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\nindex 59fa2d9..9108780 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -32,6 +32,8 @@ using namespace libcamera;\n class QAction;\n class QComboBox;\n \n+class HotplugEvent;\n+\n enum {\n \tOptCamera = 'c',\n \tOptHelp = 'h',\n@@ -87,8 +89,12 @@ private:\n \tint startCapture();\n \tvoid stopCapture();\n \n+\tvoid addNewCamera(std::shared_ptr<Camera> camera);\n+\tvoid removeCamera(std::shared_ptr<Camera> camera);\n+\n \tvoid requestComplete(Request *request);\n \tvoid processCapture();\n+\tvoid processHotplug(HotplugEvent *e);\n \tvoid processViewfinder(FrameBuffer *buffer);\n \n \t/* UI elements */\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "4/5"
    ]
}