libcamera: device_enumerator: add factory for DeviceEnumerators

Provide a factory for DeviceEnumerator objects. Depending on which
libraries are available there will be different ways to enumerate
information in the system. This factory hides this from the rest of the
library.

Currently udev enumeration is the only supported implementation, a sysfs
implementation is another method that surely will be added in the
future.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Niklas Söderlund 2018-12-21 02:45:14 +01:00
parent 4db38e82a3
commit 06e2ac2e2f
2 changed files with 21 additions and 0 deletions

View file

@ -121,6 +121,25 @@ bool DeviceMatch::match(const DeviceInfo *info) const
* Enumerator Base
*/
DeviceEnumerator *DeviceEnumerator::create()
{
DeviceEnumerator *enumerator;
/* TODO: add compile time checks to only try udev enumerator if libudev is available */
enumerator = new DeviceEnumeratorUdev();
if (!enumerator->init())
return enumerator;
/*
* NOTE: Either udev is not available or initialization of it
* failed, use/fallback on sysfs enumerator
*/
/* TODO: add a sysfs based enumerator */
return nullptr;
}
DeviceEnumerator::~DeviceEnumerator()
{
for (DeviceInfo *dev : devices_) {

View file

@ -56,6 +56,8 @@ private:
class DeviceEnumerator
{
public:
static DeviceEnumerator *create();
virtual ~DeviceEnumerator();
virtual int init() = 0;