libcamera: include/libcamera/internal/device_enumerator.h Source File

libcamera v0.7.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
device_enumerator.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2018, Google Inc.
4 *
5 * API to enumerate and find media devices
6 */
7
8#pragma once
9
10#include <memory>
11#include <string>
12#include <vector>
13
14#include <libcamera/base/regex.h>
15#include <libcamera/base/signal.h>
16
17namespace libcamera {
18
19class MediaDevice;
20
21 class DeviceMatch
22{
23public:
24 DeviceMatch(const std::string &driver);
25
26 void add(const std::string &entity);
27 void add(std::regex entity);
28
29 bool match(const MediaDevice *device) const;
30
31private:
32 std::string driver_;
33 std::vector<std::string> entities_;
34 std::vector<std::regex> entityRegexs_;
35};
36
37 class DeviceEnumerator
38{
39public:
40 static std::unique_ptr<DeviceEnumerator> create();
41
42 virtual ~DeviceEnumerator();
43
44 virtual int init() = 0;
45 virtual int enumerate() = 0;
46
47 std::shared_ptr<MediaDevice> search(const DeviceMatch &dm);
48
49 Signal<> devicesAdded;
50
51protected:
52 std::unique_ptr<MediaDevice> createDevice(const std::string &deviceNode);
53 void addDevice(std::unique_ptr<MediaDevice> media);
54 void removeDevice(const std::string &deviceNode);
55
56private:
57 std::vector<std::shared_ptr<MediaDevice>> devices_;
58};
59
60} /* namespace libcamera */
libcamera::DeviceEnumerator
Enumerate, store and search media devices.
Definition device_enumerator.h:38
libcamera::DeviceEnumerator::search
std::shared_ptr< MediaDevice > search(const DeviceMatch &dm)
Search available media devices for a pattern match.
Definition device_enumerator.cpp:348
libcamera::DeviceEnumerator::create
static std::unique_ptr< DeviceEnumerator > create()
Create a new device enumerator matching the systems capabilities.
Definition device_enumerator.cpp:184
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:293
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:312
libcamera::DeviceEnumerator::devicesAdded
Signal devicesAdded
Notify of new media devices being found.
Definition device_enumerator.h:49
libcamera::DeviceEnumerator::createDevice
std::unique_ptr< MediaDevice > createDevice(const std::string &deviceNode)
Create a media device instance.
Definition device_enumerator.cpp:255
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::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.