{"id":80,"url":"https://patchwork.libcamera.org/api/patches/80/?format=json","web_url":"https://patchwork.libcamera.org/patch/80/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20181222230041.29999-5-niklas.soderlund@ragnatech.se>","date":"2018-12-22T23:00:33","name":"[libcamera-devel,04/12] libcamera: deviceenumerator: add DeviceMatch class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c0d4e518500484644d5350d36efc3145119ad613","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/80/mbox/","series":[{"id":38,"url":"https://patchwork.libcamera.org/api/series/38/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=38","date":"2018-12-22T23:00:29","name":"Add basic camera enumeration","version":1,"mbox":"https://patchwork.libcamera.org/series/38/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/80/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/80/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 D693960B31\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 23 Dec 2018 00:02:22 +0100 (CET)","from wyvern.dyn.berto.se (unknown [217.31.177.236])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 936ed3d0-063d-11e9-9adf-005056917a89;\n\tSun, 23 Dec 2018 00:01:56 +0100 (CET)"],"X-Halon-ID":"936ed3d0-063d-11e9-9adf-005056917a89","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":"Sun, 23 Dec 2018 00:00:33 +0100","Message-Id":"<20181222230041.29999-5-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20181222230041.29999-1-niklas.soderlund@ragnatech.se>","References":"<20181222230041.29999-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 04/12] libcamera: deviceenumerator: add\n\tDeviceMatch class","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, 22 Dec 2018 23:02:23 -0000"},"content":"Provide a DeviceMatch class which represents all properties of a media\ndevice a pipeline hander can specify when searching for a device to use\nin its pipeline.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/deviceenumerator.cpp       | 54 ++++++++++++++++++++++++\n src/libcamera/include/deviceenumerator.h | 17 ++++++++\n 2 files changed, 71 insertions(+)","diff":"diff --git a/src/libcamera/deviceenumerator.cpp b/src/libcamera/deviceenumerator.cpp\nindex 7c44a65b45472ef3..17b6874d229c791c 100644\n--- a/src/libcamera/deviceenumerator.cpp\n+++ b/src/libcamera/deviceenumerator.cpp\n@@ -75,4 +75,58 @@ bool DeviceInfo::lookup(const std::string &name, std::string &devnode) const\n \treturn true;\n }\n \n+/* -----------------------------------------------------------------------------\n+ * DeviceMatch\n+ */\n+\n+DeviceMatch::DeviceMatch(const std::string &driver)\n+\t: driver_(driver)\n+{\n+}\n+\n+void DeviceMatch::add(const std::string &entity)\n+{\n+\tentities_.push_back(std::string(entity));\n+}\n+\n+bool DeviceMatch::match(const DeviceInfo *info) const\n+{\n+\tstd::vector<std::string> entities;\n+\n+\tif (!matchInfo(info->info()))\n+\t\treturn false;\n+\n+\tif (!matchEntities(info->entities()))\n+\t\treturn false;\n+\n+\treturn true;\n+}\n+\n+bool DeviceMatch::matchInfo(const struct media_device_info &info) const\n+{\n+\t/* TODO: Add more optinal matching pairs from struct media_device_info */\n+\t/* TODO: Allow for empty driver in DeviceMatch */\n+\treturn driver_ == info.driver;\n+}\n+\n+bool DeviceMatch::matchEntities(const std::vector<std::string> &entities) const\n+{\n+\tfor (const std::string &name : entities_) {\n+\t\tbool found = false;\n+\n+\t\tfor (const std::string &entity : entities) {\n+\n+\t\t\tif (name == entity) {\n+\t\t\t\tfound = true;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (!found)\n+\t\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/deviceenumerator.h b/src/libcamera/include/deviceenumerator.h\nindex 0136ed6ea23bf65e..fb412b8840cb2ffe 100644\n--- a/src/libcamera/include/deviceenumerator.h\n+++ b/src/libcamera/include/deviceenumerator.h\n@@ -39,6 +39,23 @@ private:\n \tstd::map<std::string, std::string> entities_;\n };\n \n+class DeviceMatch\n+{\n+public:\n+\tDeviceMatch(const std::string &driver);\n+\n+\tvoid add(const std::string &entity);\n+\n+\tbool match(const DeviceInfo *info) const;\n+\n+private:\n+\tstd::string driver_;\n+\tstd::vector<std::string> entities_;\n+\n+\tbool matchInfo(const struct media_device_info &info) const;\n+\tbool matchEntities(const std::vector<std::string> &entities) const;\n+};\n+\n } /* namespace libcamera */\n \n #endif\t/* __LIBCAMERA_DEVICEENUMERATE_H__ */\n","prefixes":["libcamera-devel","04/12"]}