Files
external_libcamera/include/libcamera/internal/device_enumerator_udev.h
Laurent Pinchart 1e4e158d98 libcamera: Replace plain pointers with std::unique<>
libcamera uses std::unique_ptr<> to simplify life time management of
objects and avoid leaks. For historical reasons there are a fair number
of plain pointers with manual memory management. Replace them with
std::unique_ptr<> when the conversion is simple.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
2026-04-24 01:17:37 +03:00

81 lines
1.6 KiB
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2018-2019, Google Inc.
*
* udev-based device enumerator
*/
#pragma once
#include <list>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <sys/types.h>
#include <unordered_set>
#include <libcamera/base/class.h>
#include "libcamera/internal/device_enumerator.h"
struct udev;
struct udev_device;
struct udev_monitor;
namespace libcamera {
class EventNotifier;
class MediaDevice;
class MediaEntity;
class DeviceEnumeratorUdev final : public DeviceEnumerator
{
public:
DeviceEnumeratorUdev();
~DeviceEnumeratorUdev();
int init();
int enumerate();
private:
using DependencyMap = std::map<dev_t, std::list<MediaEntity *>>;
struct MediaDeviceDeps {
MediaDeviceDeps(std::unique_ptr<MediaDevice> media,
DependencyMap deps)
: media_(std::move(media)), deps_(std::move(deps))
{
}
bool operator==(const MediaDeviceDeps &other) const
{
return media_ == other.media_;
}
std::unique_ptr<MediaDevice> media_;
DependencyMap deps_;
};
LIBCAMERA_DISABLE_COPY_AND_MOVE(DeviceEnumeratorUdev)
int addUdevDevice(struct udev_device *dev);
void removeUdevDevice(struct udev_device *dev);
int populateMediaDevice(MediaDevice *media, DependencyMap *deps);
std::string lookupDeviceNode(dev_t devnum);
int addV4L2Device(dev_t devnum);
void udevNotify();
struct udev *udev_;
struct udev_monitor *monitor_;
std::unique_ptr<EventNotifier> notifier_;
std::set<dev_t> orphans_;
std::unordered_set<dev_t> devices_;
std::list<MediaDeviceDeps> pending_;
std::map<dev_t, MediaDeviceDeps *> devMap_;
};
} /* namespace libcamera */