-rw-r--r--
: driver_(driver)
{
}
/**
* \brief Add a media entity name to the search pattern
* \param[in] entity The name of the entity in the media graph
*/
void DeviceMatch::add(const std::string &entity)
{
entities_.push_back(entity);
}
/**
* \brief Compare a search pattern with a media device
* \param[in] device The media device
*
* Matching is performed on the Linux device driver name and entity names from
* the media graph. A match is found if both the driver name matches and the
* media device contains all the entities listed in the search pattern.
*
* \return true if the media device matches the search pattern, false otherwise
*/
bool DeviceMatch::match(const MediaDevice *device) const
{
if (driver_ != device->driver())
return false;
for (const std::string &name : entities_) {
bool found = false;
for (const MediaEntity *entity : device->entities()) {
if (name == entity->name()) {
found = true;
break;
}
}
if (!found)
return false;
}
return true;
}
/**
* \class DeviceEnumerator
* \brief Enumerate, store and search media devices
*
* The DeviceEnumerator class is responsible for all interactions with the
* operating system related to media devices. It enumerates all media devices
* in the system, and for each device found creates an instance of the
* MediaDevice class and stores it internally. The list of media devices can
* then be searched using DeviceMatch search patterns.
*
* The enumerator also associates media device entities with device node paths.
*/
/**
* \brief Create a new device enumerator matching the systems capabilities
*
* Depending on how the operating system handles device detection, hot-plug
* notification and device node lookup, different device enumerator
* implementations may be needed. This function creates the best enumerator for
* the operating system based on the available resources. Not all different
* enumerator types are guaranteed to support all features.
*
* \return A pointer to the newly created device enumerator on success, or
* nullptr if an error occurs
*/
std::unique_ptr<DeviceEnumerator> DeviceEnumerator::create()
{
std::unique_ptr<DeviceEnumerator> enumerator;
/**
* \todo Add compile time checks to only try udev enumerator if libudev
* is available.
*/
enumerator = utils::make_unique<DeviceEnumeratorUdev>();
if (!enumerator->init())
return enumerator;
/*
* Either udev is not available or udev initialization failed. Fall back
* on the sysfs enumerator.
*/
/** \todo Add a sysfs-based enumerator. */
return nullptr;
}
DeviceEnumerator::~DeviceEnumerator()
{
for (MediaDevice *dev : devices_) {
if (dev->busy())
LOG(Error) &ljmondi/pinephonepro&id=45ebe9a209fc5bcce649b8b3f27f80131fc4e2c7'>plain |