libcamera: device_enumerator: Convey device ownership through unique_ptr
Replace usage of shared_ptr with unique_ptr to convey media device ownership internally in the enumerators when creating the media device. Once a media device has all its dependencies met, it is converted to a shared_ptr to keep the external API unchanged. 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>
This commit is contained in:
@@ -44,8 +44,8 @@ public:
|
||||
std::shared_ptr<MediaDevice> search(const DeviceMatch &dm);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<MediaDevice> createDevice(const std::string &deviceNode);
|
||||
void addDevice(const std::shared_ptr<MediaDevice> &media);
|
||||
std::unique_ptr<MediaDevice> createDevice(const std::string &deviceNode);
|
||||
void addDevice(std::unique_ptr<MediaDevice> &&media);
|
||||
void removeDevice(const std::string &deviceNode);
|
||||
|
||||
private:
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
int enumerate();
|
||||
|
||||
private:
|
||||
int populateMediaDevice(const std::shared_ptr<MediaDevice> &media);
|
||||
int populateMediaDevice(MediaDevice *media);
|
||||
std::string lookupDeviceNode(int major, int minor);
|
||||
};
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@ private:
|
||||
using DependencyMap = std::map<dev_t, std::list<MediaEntity *>>;
|
||||
|
||||
struct MediaDeviceDeps {
|
||||
MediaDeviceDeps(const std::shared_ptr<MediaDevice> &media,
|
||||
const DependencyMap &deps)
|
||||
: media_(media), deps_(deps)
|
||||
MediaDeviceDeps(std::unique_ptr<MediaDevice> &&media,
|
||||
DependencyMap &&deps)
|
||||
: media_(std::move(media)), deps_(std::move(deps))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ private:
|
||||
return media_ == other.media_;
|
||||
}
|
||||
|
||||
std::shared_ptr<MediaDevice> media_;
|
||||
std::unique_ptr<MediaDevice> media_;
|
||||
DependencyMap deps_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user