summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-21 19:54:20 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-23 16:30:40 +0200
commite75ef59e028e5b686d686789439ede443c9c4cde (patch)
tree55c44804134ca3938bc91588230d1091c3e06651
parent74c99b41e7387dcd3ce7e1b2ea8affd719f64e92 (diff)
libcamera: device_enumerator_udev: Update pending list in addUdevDevice
Media devices that have unmet dependencies are added to the pending list in populateMediaDevice(). Move the code to the caller, addUdevDevice(), as it logically belongs there. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r--src/libcamera/device_enumerator_udev.cpp28
-rw-r--r--src/libcamera/include/device_enumerator_udev.h2
2 files changed, 13 insertions, 17 deletions
diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp
index e5535054..ea3f6b7c 100644
--- a/src/libcamera/device_enumerator_udev.cpp
+++ b/src/libcamera/device_enumerator_udev.cpp
@@ -81,7 +81,8 @@ int DeviceEnumeratorUdev::addUdevDevice(struct udev_device *dev)
if (!media)
return -ENODEV;
- int ret = populateMediaDevice(media);
+ DependencyMap deps;
+ int ret = populateMediaDevice(media.get(), &deps);
if (ret < 0) {
LOG(DeviceEnumerator, Warning)
<< "Failed to populate media device "
@@ -90,10 +91,16 @@ int DeviceEnumeratorUdev::addUdevDevice(struct udev_device *dev)
return ret;
}
- if (ret) {
+ if (!deps.empty()) {
LOG(DeviceEnumerator, Debug)
<< "Defer media device " << media->deviceNode()
<< " due to " << ret << " missing dependencies";
+
+ pending_.emplace_back(media, deps);
+ MediaDeviceDeps *mediaDeps = &pending_.back();
+ for (const auto &dep : mediaDeps->deps_)
+ devMap_[dep.first] = mediaDeps;
+
return 0;
}
@@ -185,10 +192,9 @@ done:
return 0;
}
-int DeviceEnumeratorUdev::populateMediaDevice(const std::shared_ptr<MediaDevice> &media)
+int DeviceEnumeratorUdev::populateMediaDevice(MediaDevice *media, DependencyMap *deps)
{
std::set<dev_t> children;
- DependencyMap deps;
/* Associate entities to device node paths. */
for (MediaEntity *entity : media->entities()) {
@@ -203,7 +209,7 @@ int DeviceEnumeratorUdev::populateMediaDevice(const std::shared_ptr<MediaDevice>
* dependencies.
*/
if (orphans_.find(devnum) == orphans_.end()) {
- deps[devnum].push_back(entity);
+ (*deps)[devnum].push_back(entity);
continue;
}
@@ -231,17 +237,7 @@ int DeviceEnumeratorUdev::populateMediaDevice(const std::shared_ptr<MediaDevice>
++it;
}
- /*
- * If the media device has unmet dependencies, add it to the pending
- * list and update the devnum map accordingly.
- */
- if (!deps.empty()) {
- pending_.emplace_back(media, deps);
- for (const auto &dep : deps)
- devMap_[dep.first] = &pending_.back();
- }
-
- return deps.size();
+ return 0;
}
/**
diff --git a/src/libcamera/include/device_enumerator_udev.h b/src/libcamera/include/device_enumerator_udev.h
index 6d826862..efaefe5d 100644
--- a/src/libcamera/include/device_enumerator_udev.h
+++ b/src/libcamera/include/device_enumerator_udev.h
@@ -63,7 +63,7 @@ private:
std::map<dev_t, MediaDeviceDeps *> devMap_;
int addUdevDevice(struct udev_device *dev);
- int populateMediaDevice(const std::shared_ptr<MediaDevice> &media);
+ int populateMediaDevice(MediaDevice *media, DependencyMap *deps);
std::string lookupDeviceNode(dev_t devnum);
int addV4L2Device(dev_t devnum);