Program Listing for File gxf_extension_manager.hpp
↰ Return to documentation for file (include/holoscan/core/gxf/gxf_extension_manager.hpp
)
/*
* SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HOLOSCAN_CORE_GXF_GXF_EXTENSION_MANAGER_HPP
#define HOLOSCAN_CORE_GXF_GXF_EXTENSION_MANAGER_HPP
#include <yaml-cpp/yaml.h>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "gxf/core/gxf.h"
#include "gxf/std/extension.hpp"
#include "holoscan/core/common.hpp"
#include "holoscan/core/extension_manager.hpp"
namespace holoscan::gxf {
namespace {
// Method name to get the GXF extension factory
constexpr const char* kGxfExtensionFactoryName = "GxfExtensionFactory";
// Max size of extensions
constexpr int kGXFExtensionsMaxSize = 1024;
// Method signature for the GXF extension factory
using GxfExtensionFactory = gxf_result_t(void**);
} // namespace
class GXFExtensionManager : public ExtensionManager {
public:
explicit GXFExtensionManager(gxf_context_t context);
~GXFExtensionManager() override;
void reset_context(gxf_context_t context) override;
void refresh() override;
bool load_extension(const std::string& file_name, bool no_error_message = false,
const std::string& search_path_envs = "HOLOSCAN_LIB_PATH") override;
bool load_extensions_from_yaml(const YAML::Node& node, bool no_error_message = false,
const std::string& search_path_envs = "HOLOSCAN_LIB_PATH",
const std::string& key = "extensions") override;
bool is_extension_loaded(gxf_tid_t tid);
static std::vector<std::string> tokenize(const std::string& str, const std::string& delimiters);
protected:
bool load_extension(nvidia::gxf::Extension* extension);
void* open_extension_library(const std::string& file_path);
gxf_tid_t extension_tid_list_[kGXFExtensionsMaxSize] = {};
gxf_runtime_info runtime_info_{nullptr, kGXFExtensionsMaxSize, extension_tid_list_};
// Using ordered containers (std::set/std::map) rather than their unordered counterparts
// because gxf_tid_t lacks a std::hash specialization in the GXF API
std::set<gxf_tid_t> extension_tids_;
std::map<gxf_tid_t, nvidia::gxf::Extension*> loaded_extension_tids_map_;
std::vector<std::pair<gxf_tid_t, nvidia::gxf::Extension*>> loaded_extensions_;
std::map<std::string, void*> extension_handles_map_;
// std::set<void*> extension_handles_; ///< Set of extension handles
};
} // namespace holoscan::gxf
#endif/* HOLOSCAN_CORE_GXF_GXF_EXTENSION_MANAGER_HPP */