From d6cb55ef08f51c9ebef57e5bbcb95b03a65972a9 Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Mon, 22 Jun 2020 18:06:38 -0500 Subject: uhd: Create discoverable feature registry implementation Classes which want to implement discoverable_feature can simply inherit from this registry and get access to an ergonomic map-backed registry of features. --- host/lib/features/CMakeLists.txt | 12 ++++++++ .../lib/features/discoverable_feature_registry.cpp | 34 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 host/lib/features/CMakeLists.txt create mode 100644 host/lib/features/discoverable_feature_registry.cpp (limited to 'host/lib/features') diff --git a/host/lib/features/CMakeLists.txt b/host/lib/features/CMakeLists.txt new file mode 100644 index 000000000..2cdd1dd56 --- /dev/null +++ b/host/lib/features/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright 2020 Ettus Research, a National Instruments Brand +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +######################################################################## +# This file included, use CMake directory variables +######################################################################## +LIBUHD_APPEND_SOURCES( + ${CMAKE_CURRENT_SOURCE_DIR}/discoverable_feature_registry.cpp +) diff --git a/host/lib/features/discoverable_feature_registry.cpp b/host/lib/features/discoverable_feature_registry.cpp new file mode 100644 index 000000000..5bed6a06e --- /dev/null +++ b/host/lib/features/discoverable_feature_registry.cpp @@ -0,0 +1,34 @@ +// +// Copyright 2020 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include +#include +#include +#include + +namespace uhd { namespace features { + +std::vector +discoverable_feature_registry::enumerate_features() +{ + std::vector features; + for (auto& entry : _features) { + features.push_back(entry.second->get_feature_name()); + } + return features; +} + +discoverable_feature::sptr discoverable_feature_registry::get_feature_ptr( + discoverable_feature::feature_id_t feature_id) +{ + auto it = _features.find(feature_id); + if (it == _features.end()) { + return discoverable_feature::sptr(); + } + return it->second; +} + +}} // namespace uhd::features -- cgit v1.2.3