blob: 61b32bb921581f491b9f3e5c84789f4ac908f223 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* device_enumerator.cpp - Enumeration and matching
*/
#include "device_enumerator.h"
#include "log.h"
namespace libcamera {
/* -----------------------------------------------------------------------------
* DeviceInfo
*/
DeviceInfo::DeviceInfo(const std::string &devnode, const struct media_device_info &info,
const std::map<std::string, std::string> &entities)
: acquired_(false), devnode_(devnode), info_(info), entities_(entities)
{
for (const auto &entity : entities_)
LOG(Info) << "Device: " << devnode_ << " Entity: '" << entity.first << "' -> " << entity.second;
}
int DeviceInfo::acquire()
{
if (acquired_)
return -EBUSY;
acquired_ = true;
return 0;
}
void DeviceInfo::release()
{
acquired_ = false;
}
bool DeviceInfo::busy() const
{
return acquired_;
}
const std::string &DeviceInfo::devnode() const
{
return devnode_;
}
const struct media_device_info &DeviceInfo::info() const
{
return info_;
}
std::vector<std::string> DeviceInfo::entities() const
{
std::vector<std::string> entities;
for (const auto &entity : entities_)
entities.push_back(entity.first);
return entities;
}
int DeviceInfo::lookup(const std::string &name, std::string &devnode) const
{
auto it = entities_.find(name);
if (it == entities_.end()) {
LOG(Error) << "Trying to lookup entity '" << name << "' which does not exist";
return -ENODEV;
}
devnode = it->second;
return 0;
}
/* -----------------------------------------------------------------------------
* DeviceMatch
*/
DeviceMatch::DeviceMatch(const std::string &driver)
: driver_(driver)
{
}
void DeviceMatch::add(const std::string &entity)
{
entities_.push_back(entity);
}
bool DeviceMatch::match(const DeviceInfo *info) const
{
if (driver_ != info->info().driver)
return false;
for (const std::string &name : entities_) {
bool found = false;
for (const std::string &entity : info->entities()) {
if (name == entity) {
found = true;
break;
}
}
if (!found)
return false;
}
return true;
}
} /* namespace libcamera */
|