Loading...
Searching...
No Matches
device_enumerator.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* API to enumerate and find media devices
*/
#pragma once
#include <memory>
#include <string>
#include <vector>
#include <libcamera/base/regex.h>
#include <libcamera/base/signal.h>
namespace libcamera {
class MediaDevice;
class DeviceMatch
{
public:
DeviceMatch(const std::string &driver);
void add(const std::string &entity);
void add(std::regex entity);
bool match(const MediaDevice *device) const;
void clear();
private:
std::string driver_;
std::vector<std::string> entities_;
std::vector<std::regex> entityRegexs_;
};
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 */
libcamera::DeviceEnumerator
Enumerate, store and search media devices.
Definition device_enumerator.h:40
libcamera::DeviceEnumerator::search
std::shared_ptr< MediaDevice > search(const DeviceMatch &dm)
Search available media devices for a pattern match.
Definition device_enumerator.cpp:356
libcamera::DeviceEnumerator::create
static std::unique_ptr< DeviceEnumerator > create()
Create a new device enumerator matching the systems capabilities.
Definition device_enumerator.cpp:192
libcamera::DeviceEnumerator::init
virtual int init()=0
Initialize the enumerator.
libcamera::DeviceEnumerator::addDevice
void addDevice(std::unique_ptr< MediaDevice > media)
Add a media device to the enumerator.
Definition device_enumerator.cpp:301
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:320
libcamera::DeviceEnumerator::devicesAdded
Signal devicesAdded
Notify of new media devices being found.
Definition device_enumerator.h:51
libcamera::DeviceEnumerator::createDevice
std::unique_ptr< MediaDevice > createDevice(const std::string &deviceNode)
Create a media device instance.
Definition device_enumerator.cpp:263
libcamera::DeviceMatch
Description of a media device search pattern.
Definition device_enumerator.h:22
libcamera::DeviceMatch::DeviceMatch
DeviceMatch(const std::string &driver)
Construct a media device search pattern.
Definition device_enumerator.cpp:71
libcamera::DeviceMatch::clear
void clear()
Clear the entities search pattern vector.
Definition device_enumerator.cpp:162
libcamera::DeviceMatch::add
void add(const std::string &entity)
Add a media entity name to the search pattern.
Definition device_enumerator.cpp:80
libcamera::DeviceMatch::match
bool match(const MediaDevice *device) const
Compare a search pattern with a media device.
Definition device_enumerator.cpp:104
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition media_device.h:28
libcamera::Signal
Generic signal and slot communication mechanism.
Definition signal.h:39
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
signal.h
Signal & slot implementation.