libcamera  v0.0.0
Supporting cameras in Linux since 2019
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  * device_enumerator.h - API to enumerate and find media devices
6  */
7 #ifndef __LIBCAMERA_INTERNAL_DEVICE_ENUMERATOR_H__
8 #define __LIBCAMERA_INTERNAL_DEVICE_ENUMERATOR_H__
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include <linux/media.h>
15 
16 #include <libcamera/signal.h>
17 
18 namespace libcamera {
19 
20 class MediaDevice;
21 
23 {
24 public:
25  DeviceMatch(const std::string &driver);
26 
27  void add(const std::string &entity);
28 
29  bool match(const MediaDevice *device) const;
30 
31 private:
32  std::string driver_;
33  std::vector<std::string> entities_;
34 };
35 
37 {
38 public:
39  static std::unique_ptr<DeviceEnumerator> create();
40 
41  virtual ~DeviceEnumerator();
42 
43  virtual int init() = 0;
44  virtual int enumerate() = 0;
45 
46  std::shared_ptr<MediaDevice> search(const DeviceMatch &dm);
47 
49 
50 protected:
51  std::unique_ptr<MediaDevice> createDevice(const std::string &deviceNode);
52  void addDevice(std::unique_ptr<MediaDevice> &&media);
53  void removeDevice(const std::string &deviceNode);
54 
55 private:
56  std::vector<std::shared_ptr<MediaDevice>> devices_;
57 };
58 
59 } /* namespace libcamera */
60 
61 #endif /* __LIBCAMERA_INTERNAL_DEVICE_ENUMERATOR_H__ */
The MediaDevice represents a Media Controller device with its full graph of connected objects...
Definition: media_device.h:24
Definition: bound_method.h:15
bool match(const MediaDevice *device) const
Compare a search pattern with a media device.
Definition: device_enumerator.cpp:93
Signal & slot implementation.
Description of a media device search pattern.
Definition: device_enumerator.h:22
Enumerate, store and search media devices.
Definition: device_enumerator.h:36
Generic signal and slot communication mechanism.
Definition: object.h:20
DeviceMatch(const std::string &driver)
Construct a media device search pattern.
Definition: device_enumerator.cpp:69
void add(const std::string &entity)
Add a media entity name to the search pattern.
Definition: device_enumerator.cpp:78
Signal devicesAdded
Notify of new media devices being found.
Definition: device_enumerator.h:48