From b3cdccbff9fb8e4da6eab06f2fe3e1f02aa29939 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 9 Sep 2019 13:26:37 +0300 Subject: libcamera: device_enumerator: Move lookupDeviceNode() to child classes The lookupDeviceNode() method is declared as pure virtual in the base DeviceEnumerator class, but is only called by derived classes. Move it to the DeviceEnumeratorSysfs and DeviceEnumeratorUdev. This allows changing the udev version to take a dev_t instead of separate major/minor, as that's what both the caller and the callee end up using. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/libcamera/device_enumerator_udev.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/libcamera/device_enumerator_udev.cpp') diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp index 40853e77..e0c646c9 100644 --- a/src/libcamera/device_enumerator_udev.cpp +++ b/src/libcamera/device_enumerator_udev.cpp @@ -178,10 +178,9 @@ int DeviceEnumeratorUdev::populateMediaDevice(const std::shared_ptr if (entity->deviceMajor() == 0 && entity->deviceMinor() == 0) continue; - std::string deviceNode = lookupDeviceNode(entity->deviceMajor(), - entity->deviceMinor()); dev_t devnum = makedev(entity->deviceMajor(), entity->deviceMinor()); + std::string deviceNode = lookupDeviceNode(devnum); /* Take device from orphan list first, if it is in the list. */ if (std::find(orphans_.begin(), orphans_.end(), devnum) != orphans_.end()) { @@ -205,14 +204,21 @@ int DeviceEnumeratorUdev::populateMediaDevice(const std::shared_ptr return pendingNodes; } -std::string DeviceEnumeratorUdev::lookupDeviceNode(int major, int minor) +/** + * \brief Lookup device node path from device number + * \param[in] devnum The device number + * + * Translate a device number given as \a devnum to a device node path. + * + * \return The device node path on success, or an empty string if the lookup + * fails + */ +std::string DeviceEnumeratorUdev::lookupDeviceNode(dev_t devnum) { struct udev_device *device; const char *name; - dev_t devnum; std::string deviceNode = std::string(); - devnum = makedev(major, minor); device = udev_device_new_from_devnum(udev_, 'c', devnum); if (!device) return std::string(); @@ -246,8 +252,7 @@ int DeviceEnumeratorUdev::addV4L2Device(dev_t devnum) return 0; } - std::string deviceNode = lookupDeviceNode(entity->deviceMajor(), - entity->deviceMinor()); + std::string deviceNode = lookupDeviceNode(devnum); if (deviceNode.empty()) return -EINVAL; -- cgit v1.2.1