From patchwork Sat Dec 29 03:28:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 98 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 844F760B36 for ; Sat, 29 Dec 2018 04:29:53 +0100 (CET) X-Halon-ID: fa0c59bc-0b19-11e9-911a-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id fa0c59bc-0b19-11e9-911a-0050569116f7; Sat, 29 Dec 2018 04:29:41 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Dec 2018 04:28:46 +0100 Message-Id: <20181229032855.26249-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181229032855.26249-1-niklas.soderlund@ragnatech.se> References: <20181229032855.26249-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 03/12] libcamera: device_enumerator: add DeviceInfo class X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Dec 2018 03:29:54 -0000 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 --- * Changes since v1 - s/do/does in DeviceInfo::lookup(). - Fix typo in include guard. --- src/libcamera/device_enumerator.cpp | 78 +++++++++++++++++++++++ src/libcamera/include/device_enumerator.h | 44 +++++++++++++ src/libcamera/meson.build | 2 + 3 files changed, 124 insertions(+) create mode 100644 src/libcamera/device_enumerator.cpp create mode 100644 src/libcamera/include/device_enumerator.h diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp new file mode 100644 index 0000000000000000..83dcda9403526010 --- /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 */ diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h new file mode 100644 index 0000000000000000..ac40bafc5169c7c7 --- /dev/null +++ b/src/libcamera/include/device_enumerator.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2018, Google Inc. + * + * device_enumerator.h - API to enumerate and find media devices + */ +#ifndef __LIBCAMERA_DEVICE_ENUMERATOR_H__ +#define __LIBCAMERA_DEVICE_ENUMERATOR_H__ + +#include +#include +#include + +#include + +namespace libcamera { + +class DeviceInfo +{ +public: + DeviceInfo(const std::string &devnode, const struct media_device_info &info, + const std::map &entities); + + int acquire(); + void release(); + bool busy() const; + + const std::string &devnode() const; + const struct media_device_info &info() const; + std::vector entities() const; + + int lookup(const std::string &name, std::string &devnode) const; + +private: + bool acquired_; + + std::string devnode_; + struct media_device_info info_; + std::map entities_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_DEVICE_ENUMERATOR_H__ */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 52b556a8ed4050cb..581da1aa78ebb3ba 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -1,10 +1,12 @@ libcamera_sources = files([ 'camera.cpp', + 'device_enumerator.cpp', 'log.cpp', 'main.cpp', ]) libcamera_headers = files([ + 'include/device_enumerator.h', 'include/log.h', 'include/utils.h', ])