{"id":82,"url":"https://patchwork.libcamera.org/api/1.1/patches/82/?format=json","web_url":"https://patchwork.libcamera.org/patch/82/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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-7-niklas.soderlund@ragnatech.se>","date":"2018-12-22T23:00:35","name":"[libcamera-devel,06/12] libcamera: deviceenumerator: add DeviceEnumeratorUdev class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"39e992510cb3d606337d3f021dd4917bbba76dfc","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/82/mbox/","series":[{"id":38,"url":"https://patchwork.libcamera.org/api/1.1/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/82/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/82/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 12ABD60B2C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 23 Dec 2018 00:02:26 +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 95a1b78c-063d-11e9-9adf-005056917a89;\n\tSun, 23 Dec 2018 00:01:59 +0100 (CET)"],"X-Halon-ID":"95a1b78c-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:35 +0100","Message-Id":"<20181222230041.29999-7-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 06/12] libcamera: deviceenumerator: add\n\tDeviceEnumeratorUdev 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:26 -0000"},"content":"Provide a DeviceEnumeratorUdev class which is a specialization\nof DeviceEnumerator which uses udev to enumerate information in the\nsystem.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/deviceenumerator.cpp       | 100 +++++++++++++++++++++++\n src/libcamera/include/deviceenumerator.h |  15 ++++\n 2 files changed, 115 insertions(+)","diff":"diff --git a/src/libcamera/deviceenumerator.cpp b/src/libcamera/deviceenumerator.cpp\nindex b2f59017e94d14aa..f4c40bf0376ab453 100644\n--- a/src/libcamera/deviceenumerator.cpp\n+++ b/src/libcamera/deviceenumerator.cpp\n@@ -6,6 +6,7 @@\n  */\n \n #include <fcntl.h>\n+#include <libudev.h>\n #include <sys/ioctl.h>\n #include <unistd.h>\n \n@@ -273,4 +274,103 @@ DeviceInfo *DeviceEnumerator::search(DeviceMatch &dm) const\n \treturn info;\n }\n \n+/* -----------------------------------------------------------------------------\n+ * Enumerator Udev\n+ */\n+\n+DeviceEnumeratorUdev::DeviceEnumeratorUdev()\n+\t: udev_(NULL)\n+{\n+}\n+\n+DeviceEnumeratorUdev::~DeviceEnumeratorUdev()\n+{\n+\tif (udev_)\n+\t\tudev_unref(udev_);\n+}\n+\n+int DeviceEnumeratorUdev::init()\n+{\n+\tif (udev_)\n+\t\treturn -EBUSY;\n+\n+\tudev_ = udev_new();\n+\tif (!udev_)\n+\t\treturn -ENODEV;\n+\n+\treturn 0;\n+}\n+\n+int DeviceEnumeratorUdev::enumerate()\n+{\n+\tstruct udev_enumerate *udev_enum = NULL;\n+\tstruct udev_list_entry *ents, *ent;\n+\tint ret;\n+\n+\tudev_enum = udev_enumerate_new(udev_);\n+\tif (udev_enum == NULL)\n+\t\treturn -ENOMEM;\n+\n+\tret = udev_enumerate_add_match_subsystem(udev_enum, \"media\");\n+\tif (ret < 0)\n+\t\tgoto done;\n+\n+\tret = udev_enumerate_scan_devices(udev_enum);\n+\tif (ret < 0)\n+\t\tgoto done;\n+\n+\tents = udev_enumerate_get_list_entry(udev_enum);\n+\tif (ents == NULL)\n+\t\tgoto done;\n+\n+\tudev_list_entry_foreach(ent, ents) {\n+\t\tstruct udev_device *dev;\n+\t\tconst char *devnode;\n+\t\tconst char *syspath = udev_list_entry_get_name(ent);\n+\n+\t\tdev = udev_device_new_from_syspath(udev_, syspath);\n+\t\tif (dev == NULL) {\n+\t\t\tLOG(Error) << \"Failed to device for '\" << syspath << \"', skipping\";\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tdevnode = udev_device_get_devnode(dev);\n+\t\tif (devnode == NULL) {\n+\t\t\tudev_device_unref(dev);\n+\t\t\tret = -ENODEV;\n+\t\t\tgoto done;\n+\t\t}\n+\n+\t\taddDevice(devnode);\n+\n+\t\tudev_device_unref(dev);\n+\t}\n+done:\n+\tudev_enumerate_unref(udev_enum);\n+\treturn ret >= 0 ? 0 : ret;\n+}\n+\n+int DeviceEnumeratorUdev::lookupDevnode(std::string &devnode, int major, int minor)\n+{\n+\tstruct udev_device *device;\n+\tconst char *name;\n+\tdev_t devnum;\n+\tint ret = 0;\n+\n+\tdevnum = makedev(major, minor);\n+\tdevice = udev_device_new_from_devnum(udev_, 'c', devnum);\n+\tif (!device)\n+\t\treturn -ENODEV;\n+\n+\tname = udev_device_get_devnode(device);\n+\tif (name)\n+\t\tdevnode = name;\n+\telse\n+\t\tret = -ENODEV;\n+\n+\tudev_device_unref(device);\n+\n+\treturn ret;\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/deviceenumerator.h b/src/libcamera/include/deviceenumerator.h\nindex cbe17774edb7fcc5..2c7ff3f336ba127d 100644\n--- a/src/libcamera/include/deviceenumerator.h\n+++ b/src/libcamera/include/deviceenumerator.h\n@@ -78,6 +78,21 @@ private:\n \tvirtual int lookupDevnode(std::string &devnode, int major, int minor) = 0;\n };\n \n+class DeviceEnumeratorUdev: public DeviceEnumerator\n+{\n+public:\n+\tDeviceEnumeratorUdev();\n+\t~DeviceEnumeratorUdev();\n+\n+\tint init() final;\n+\tint enumerate() final;\n+\n+private:\n+\tstruct udev *udev_;\n+\n+\tint lookupDevnode(std::string &devnode, int major, int minor) final;\n+};\n+\n } /* namespace libcamera */\n \n #endif\t/* __LIBCAMERA_DEVICEENUMERATE_H__ */\n","prefixes":["libcamera-devel","06/12"]}