Show a patch.

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

{
    "id": 104,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/104/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/104/",
    "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": "<20181229032855.26249-9-niklas.soderlund@ragnatech.se>",
    "date": "2018-12-29T03:28:51",
    "name": "[libcamera-devel,v2,08/12] libcamera: device_enumerator: add documentation",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "2dd62533bca496c276690bda59184bd8c9e93e56",
    "submitter": {
        "id": 5,
        "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api",
        "name": "Niklas Söderlund",
        "email": "niklas.soderlund@ragnatech.se"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/104/mbox/",
    "series": [
        {
            "id": 41,
            "url": "https://patchwork.libcamera.org/api/1.1/series/41/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=41",
            "date": "2018-12-29T03:28:43",
            "name": "Add basic camera enumeration",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/41/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/104/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/104/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<niklas.soderlund@ragnatech.se>",
        "Received": [
            "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4A3CE60B4A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 29 Dec 2018 04:29:58 +0100 (CET)",
            "from bismarck.berto.se (unknown [89.233.230.99])\n\tby bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid fc0cb492-0b19-11e9-911a-0050569116f7;\n\tSat, 29 Dec 2018 04:29:44 +0100 (CET)"
        ],
        "X-Halon-ID": "fc0cb492-0b19-11e9-911a-0050569116f7",
        "Authorized-sender": "niklas@soderlund.pp.se",
        "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat, 29 Dec 2018 04:28:51 +0100",
        "Message-Id": "<20181229032855.26249-9-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20181229032855.26249-1-niklas.soderlund@ragnatech.se>",
        "References": "<20181229032855.26249-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 08/12] libcamera: device_enumerator:\n\tadd documentation",
        "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": "Sat, 29 Dec 2018 03:29:58 -0000"
    },
    "content": "Document the intended use-case of the different elements of the device\nenumerator.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/device_enumerator.cpp | 224 +++++++++++++++++++++++++++-\n 1 file changed, 216 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\nindex 26a3e68fcf39e43a..7608087b282339f8 100644\n--- a/src/libcamera/device_enumerator.cpp\n+++ b/src/libcamera/device_enumerator.cpp\n@@ -14,12 +14,55 @@\n #include \"device_enumerator.h\"\n #include \"log.h\"\n \n+/**\n+ * \\file device_enumerator.h\n+ * \\brief Enumerating and matching of media devices\n+ *\n+ * The purpose of device enumeration and matching is to find media\n+ * devices in the system and map one or more media devices to a pipeline\n+ * handler. During enumeration information about each media device is\n+ * gathered, transformed and stored.\n+ *\n+ * The core of the enumeration is DeviceEnumerator which is responsible\n+ * for all interactions with the operating system and the entry point\n+ * for other parts of libcamera.\n+ *\n+ * The DeviceEnumerator can enumerate all or specific media devices in\n+ * the system. When a new media device is added the enumerator gathers\n+ * information about it and stores it in a DeviceInfo object.\n+ *\n+ * The last functionality provided is the ability to search among the\n+ * enumerate media devices for one matching information known to the\n+ * searcher. This is done by populating and passing a DeviceMatch object\n+ * to the DeviceEnumerator.\n+ *\n+ * \\todo Add sysfs based device enumerator\n+ * \\todo Add support for hot-plug and hot-unplug.\n+ */\n+\n namespace libcamera {\n \n-/* -----------------------------------------------------------------------------\n- * DeviceInfo\n+/**\n+ * \\class DeviceInfo\n+ * \\brief Container of information for enumerated device\n+ *\n+ * The DeviceInfo class holds information about a media device. It provides\n+ * methods to retrieve the information stored and to lookup entity names\n+ * to device node paths. Furthermore it provides a scheme where a device\n+ * can be acquired and released to indicate if the device is in use.\n+ *\n+ * \\todo Look into the possibility to replace this with a more complete MediaDevice model.\n  */\n \n+/**\n+ * \\brief Construct a container of device information\n+ *\n+ * \\param[in] devnode The path to the device node of the media device\n+ * \\param[in] info Information retrieved from MEDIA_IOC_DEVICE_INFO IOCTL\n+ * \\param[in] entities A map of media graph 'Entity name' -> 'devnode path'\n+ *\n+ * The caller is responsible to provide all information for the device.\n+ */\n DeviceInfo::DeviceInfo(const std::string &devnode, const struct media_device_info &info,\n \t\t       const std::map<std::string, std::string> &entities)\n \t: acquired_(false), devnode_(devnode), info_(info), entities_(entities)\n@@ -28,6 +71,15 @@ DeviceInfo::DeviceInfo(const std::string &devnode, const struct media_device_inf\n \t\tLOG(Info) << \"Device: \" << devnode_ << \" Entity: '\" << entity.first << \"' -> \" << entity.second;\n }\n \n+/**\n+ * \\brief Claim a device for exclusive use\n+ *\n+ * Once a device is successfully acquired the caller is responsible to\n+ * release it once it is done wit it.\n+ *\n+ * \\retval 0 Device claimed\n+ * \\retval -EBUSY Device already claimed by someone else\n+ */\n int DeviceInfo::acquire()\n {\n \tif (acquired_)\n@@ -38,26 +90,53 @@ int DeviceInfo::acquire()\n \treturn 0;\n }\n \n+/**\n+ * \\brief Release a device from exclusive use\n+ */\n void DeviceInfo::release()\n {\n \tacquired_ = false;\n }\n \n+/**\n+ * \\brief Check if a device is in use\n+ *\n+ * \\retval true Device is in use\n+ * \\retval false Device is free\n+ */\n bool DeviceInfo::busy() const\n {\n \treturn acquired_;\n }\n \n+/**\n+ * \\brief Retrieve the devnode to the media device\n+ *\n+ * \\return Path to the media device (example /dev/media0)\n+ */\n const std::string &DeviceInfo::devnode() const\n {\n \treturn devnode_;\n }\n \n+/**\n+ * \\brief Retrieve the media device v4l2 information\n+ *\n+ * \\return v4l2 specific information structure\n+ */\n const struct media_device_info &DeviceInfo::info() const\n {\n \treturn info_;\n }\n \n+/**\n+ * \\brief List all entities of the device\n+ *\n+ * List all media entities names from the media graph which are known\n+ * and to which this instance can lookup the device node path.\n+ *\n+ * \\return List of strings\n+ */\n std::vector<std::string> DeviceInfo::entities() const\n {\n \tstd::vector<std::string> entities;\n@@ -68,6 +147,17 @@ std::vector<std::string> DeviceInfo::entities() const\n \treturn entities;\n }\n \n+/**\n+ * \\brief Lookup a media entity name and retrieve its device node path\n+ *\n+ * \\param[in] name Entity name to lookup\n+ * \\param[out] devnode Path to \\a name devnode if lookup is successful\n+ *\n+ * The caller is responsible to check the return code of the function\n+ * to determine if the entity name could be looked up.\n+ *\n+ * \\return 0 on success none zero otherwise\n+ */\n int DeviceInfo::lookup(const std::string &name, std::string &devnode) const\n {\n \tauto it = entities_.find(name);\n@@ -81,20 +171,49 @@ int DeviceInfo::lookup(const std::string &name, std::string &devnode) const\n \treturn 0;\n }\n \n-/* -----------------------------------------------------------------------------\n- * DeviceMatch\n+/**\n+ * \\class DeviceMatch\n+ * \\brief Description of a media device search pattern\n+ *\n+ * The DeviceMatch class describes a media device using properties from\n+ * the v4l2 struct media_device_info, entity names in the media graph or\n+ * other properties which can be used to identify a media device.\n+ *\n+ * The description of a media device can then be passed to an enumerator\n+ * to try and find a matching media device.\n  */\n \n+/**\n+ * \\brief Construct a media device search pattern\n+ *\n+ * \\param[in] driver The Linux device driver name who created the media device\n+ */\n DeviceMatch::DeviceMatch(const std::string &driver)\n \t: driver_(driver)\n {\n }\n \n+/**\n+ * \\brief Add a media entity name to the search pattern\n+ *\n+ * \\param[in] entity The name of the entity in the media graph\n+ */\n void DeviceMatch::add(const std::string &entity)\n {\n \tentities_.push_back(entity);\n }\n \n+/**\n+ * \\brief Compare a search pattern with a media device\n+ *\n+ * \\param[in] info Information about a enumerated media device\n+ *\n+ * Matching is performed on the Linux device driver name and entity names\n+ * from the media graph.\n+ *\n+ * \\retval true The device described in \\a info matches search pattern\n+ * \\retval false The device described in \\a info do not match search pattern\n+ */\n bool DeviceMatch::match(const DeviceInfo *info) const\n {\n \tif (driver_ != info->info().driver)\n@@ -117,10 +236,30 @@ bool DeviceMatch::match(const DeviceInfo *info) const\n \treturn true;\n }\n \n-/* -----------------------------------------------------------------------------\n- * Enumerator Base\n+/**\n+ * \\class DeviceEnumerator\n+ * \\brief Enumerate, interrogate, store and search media device information\n+ *\n+ * The DeviceEnumerator class is responsible for all interactions with\n+ * the operation system when searching and interrogating media devices.\n+ *\n+ * It is possible to automatically search and add all media devices in\n+ * the system or specify which media devices should be interrogated\n+ * in order for a specialized application to open as few resources\n+ * as possible to get hold of a specific camera.\n+ *\n+ * Once one or many media devices have been enumerated it is possible\n+ * to search among them to try and find a matching device using a\n+ * DeviceMatch object.\n+ *\n  */\n \n+/**\n+ * \\brief Create a new device enumerator matching the systems capabilities\n+ *\n+ * Create a enumerator based on resource available to the system. Not all\n+ * different enumerator types are guaranteed to support all features.\n+ */\n DeviceEnumerator *DeviceEnumerator::create()\n {\n \tDeviceEnumerator *enumerator;\n@@ -150,6 +289,15 @@ DeviceEnumerator::~DeviceEnumerator()\n \t}\n }\n \n+/**\n+ * \\brief Add a media device to the enumerator\n+ *\n+ * \\param[in] devnode path to the media device to add\n+ *\n+ * Opens the media device and quires its topology and other information.\n+ *\n+ * \\return 0 on success none zero otherwise\n+ */\n int DeviceEnumerator::addDevice(const std::string &devnode)\n {\n \tint fd, ret;\n@@ -180,6 +328,16 @@ out:\n \treturn ret;\n }\n \n+/**\n+ * \\brief Fetch the MEDIA_IOC_DEVICE_INFO from media device\n+ *\n+ * \\param[in] fd File pointer to media device\n+ * \\param[out] info Information retrieved from MEDIA_IOC_DEVICE_INFO IOCTL\n+ *\n+ * Opens the media device and quires its information.\n+ *\n+ * \\return 0 on success none zero otherwise\n+ */\n int DeviceEnumerator::readInfo(int fd, struct media_device_info &info)\n {\n \tint ret;\n@@ -195,6 +353,18 @@ int DeviceEnumerator::readInfo(int fd, struct media_device_info &info)\n \treturn 0;\n }\n \n+/**\n+ * \\brief Fetch the topology from media device\n+ *\n+ * \\param[in] fd File pointer to media device\n+ * \\param[out] entities Map of entity names to device node paths\n+ *\n+ * The media graph is retrieved using MEDIA_IOC_G_TOPOLOGY and the\n+ * result is transformed to a map where the entity name is the key\n+ * and the filesystem path for that entity device node is the value.\n+ *\n+ * \\return 0 on success none zero otherwise\n+ */\n int DeviceEnumerator::readTopology(int fd, std::map<std::string, std::string> &entities)\n {\n \tstruct media_v2_topology topology;\n@@ -268,6 +438,18 @@ done:\n \treturn ret;\n }\n \n+/**\n+ * \\brief Search available media devices for a pattern match\n+ *\n+ * \\param[in] dm search pattern\n+ *\n+ * Search the enumerated media devices who are not already in use\n+ * for a match described in \\a dm. If a match is found and the caller\n+ * intends to use it the caller is responsible to mark the DeviceInfo\n+ * object as in use and to release it when it's done with it.\n+ *\n+ * \\return pointer to the matching DeviceInfo, nullptr if no match is found\n+ */\n DeviceInfo *DeviceEnumerator::search(DeviceMatch &dm) const\n {\n \tDeviceInfo *info = nullptr;\n@@ -285,8 +467,11 @@ DeviceInfo *DeviceEnumerator::search(DeviceMatch &dm) const\n \treturn info;\n }\n \n-/* -----------------------------------------------------------------------------\n- * Enumerator Udev\n+/**\n+ * \\class DeviceEnumeratorUdev\n+ * \\brief Udev implementation of device enumeration\n+ *\n+ * Implementation of system enumeration functions using libudev.\n  */\n \n DeviceEnumeratorUdev::DeviceEnumeratorUdev()\n@@ -300,6 +485,13 @@ DeviceEnumeratorUdev::~DeviceEnumeratorUdev()\n \t\tudev_unref(udev_);\n }\n \n+/**\n+ * \\brief Initialize the enumerator\n+ *\n+ * \\retval 0 Initialized\n+ * \\retval -EBUSY Busy (already initialized)\n+ * \\retval -ENODEV Failed to talk to udev\n+ */\n int DeviceEnumeratorUdev::init()\n {\n \tif (udev_)\n@@ -312,6 +504,14 @@ int DeviceEnumeratorUdev::init()\n \treturn 0;\n }\n \n+/**\n+ * \\brief Enumerate all media devices using udev\n+ *\n+ * Find, enumerate and add all media devices in the system to the\n+ * enumerator.\n+ *\n+ * \\return 0 on success none zero otherwise\n+ */\n int DeviceEnumeratorUdev::enumerate()\n {\n \tstruct udev_enumerate *udev_enum = nullptr;\n@@ -362,6 +562,14 @@ done:\n \treturn ret >= 0 ? 0 : ret;\n }\n \n+/**\n+ * \\brief Lookup device node from device number using udev\n+ *\n+ * Translate a device number (major, minor) to a device node path.\n+ *\n+ * \\return device node path or empty string if lookup fails.\n+ *\n+ */\n std::string DeviceEnumeratorUdev::lookupDevnode(int major, int minor)\n {\n \tstruct udev_device *device;\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "08/12"
    ]
}