From 0eab433d057ba5ed0feffe89c9f5b67f3557fb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Fri, 21 Dec 2018 15:52:14 +0100 Subject: libcamera: device_enumerator: add DeviceInfo class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Provide a DeviceInfo class which holds all information from the initial enumeration of a media device. Not all information available at a media device is stored, only the information needed for a pipeline handler to find a specific device. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/device_enumerator.cpp | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/libcamera/device_enumerator.cpp (limited to 'src/libcamera/device_enumerator.cpp') diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp new file mode 100644 index 00000000..83dcda94 --- /dev/null +++ b/src/libcamera/device_enumerator.cpp @@ -0,0 +1,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 &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 DeviceInfo::entities() const +{ + std::vector 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 */ -- cgit v1.2.1