device_enumerator.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* device_enumerator.h - API to enumerate and find media devices
*/
#ifndef __LIBCAMERA_INTERNAL_DEVICE_ENUMERATOR_H__
#define __LIBCAMERA_INTERNAL_DEVICE_ENUMERATOR_H__
#include <memory>
#include <string>
#include <vector>
#include <linux/media.h>
#include <libcamera/signal.h>
namespace libcamera {
class MediaDevice;
class DeviceMatch
{
public:
DeviceMatch(const std::string &driver);
void add(const std::string &entity);
bool match(const MediaDevice *device) const;
private:
std::string driver_;
std::vector<std::string> entities_;
};
class DeviceEnumerator
{
public:
static std::unique_ptr<DeviceEnumerator> create();
virtual ~DeviceEnumerator();
virtual int init() = 0;
virtual int enumerate() = 0;
std::shared_ptr<MediaDevice> search(const DeviceMatch &dm);
Signal<> devicesAdded;
protected:
std::unique_ptr<MediaDevice> createDevice(const std::string &deviceNode);
void addDevice(std::unique_ptr<MediaDevice> &&media);
void removeDevice(const std::string &deviceNode);
private:
std::vector<std::shared_ptr<MediaDevice>> devices_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_INTERNAL_DEVICE_ENUMERATOR_H__ */
libcamera::DeviceEnumerator
Enumerate, store and search media devices.
Definition: device_enumerator.h:37
libcamera::DeviceEnumerator::search
std::shared_ptr< MediaDevice > search(const DeviceMatch &dm)
Search available media devices for a pattern match.
Definition: device_enumerator.cpp:304
libcamera::DeviceEnumerator::create
static std::unique_ptr< DeviceEnumerator > create()
Create a new device enumerator matching the systems capabilities.
Definition: device_enumerator.cpp:140
libcamera::DeviceEnumerator::devicesAdded
Signal devicesAdded
Notify of new media devices being found.
Definition: device_enumerator.h:48
libcamera::DeviceEnumerator::enumerate
virtual int enumerate()=0
Enumerate all media devices in the system.
libcamera::DeviceEnumerator::removeDevice
void removeDevice(const std::string &deviceNode)
Remove a media device from the enumerator.
Definition: device_enumerator.cpp:268
libcamera::DeviceEnumerator::addDevice
void addDevice(std::unique_ptr< MediaDevice > &&media)
Add a media device to the enumerator.
Definition: device_enumerator.cpp:249
libcamera::DeviceEnumerator::createDevice
std::unique_ptr< MediaDevice > createDevice(const std::string &deviceNode)
Create a media device instance.
Definition: device_enumerator.cpp:211
libcamera::DeviceEnumerator::init
virtual int init()=0
Initialize the enumerator.
libcamera::DeviceMatch
Description of a media device search pattern.
Definition: device_enumerator.h:23
libcamera::DeviceMatch::DeviceMatch
DeviceMatch(const std::string &driver)
Construct a media device search pattern.
Definition: device_enumerator.cpp:69
libcamera::DeviceMatch::add
void add(const std::string &entity)
Add a media entity name to the search pattern.
Definition: device_enumerator.cpp:78
libcamera::DeviceMatch::match
bool match(const MediaDevice *device) const
Compare a search pattern with a media device.
Definition: device_enumerator.cpp:93
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition: media_device.h:25
libcamera::Signal
Generic signal and slot communication mechanism.
Definition: signal.h:39
signal.h
Signal & slot implementation.