blob: 83dcda9403526010fb9de4a491ff2a80de6b2d1a (
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
|
/* 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;
}
} /* namespace libcamera */
|