Program Listing for File fastdds_pubsub_context.hpp
↰ Return to documentation for file (include/holoscan/pubsub/fastdds/resources/fastdds_pubsub_context.hpp)
/*
* SPDX-FileCopyrightText: Copyright (c) 2026 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_PUBSUB_FASTDDS_RESOURCES_FASTDDS_PUBSUB_CONTEXT_HPP
#define HOLOSCAN_PUBSUB_FASTDDS_RESOURCES_FASTDDS_PUBSUB_CONTEXT_HPP
#include <cuda_runtime.h>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/topic/Topic.hpp>
#include <gxf/pubsub/endpoint_info.hpp>
#include <gxf/pubsub/pubsub_context.hpp>
#include <gxf/pubsub/qos_profile.hpp>
#include <holoscan/core/resource.hpp>
namespace holoscan {
// Forward declarations
class Allocator;
class FastDdsPubSubContext : public Resource {
public:
HOLOSCAN_RESOURCE_FORWARD_ARGS(FastDdsPubSubContext)
FastDdsPubSubContext() = default;
~FastDdsPubSubContext() override;
void setup(ComponentSpec& spec) override;
void initialize() override;
eprosima::fastdds::dds::DomainParticipant* participant() const { return participant_; }
std::shared_ptr<Allocator> allocator() const { return allocator_; }
cudaStream_t cuda_stream() const { return cuda_stream_; }
eprosima::fastdds::dds::Topic* get_or_create_topic(const std::string& topic_name,
const std::string& type_name);
std::vector<std::string> get_discovered_topics() const;
int32_t domain_id() const { return domain_id_.get(); }
std::string participant_name() const { return participant_name_.get(); }
std::string transport_profile() const { return transport_profile_.get(); }
nvidia::gxf::QoSProfile default_qos() const;
//----------------------------------------------------------------------------
// Native Buffer (CUDA IPC) Configuration
//----------------------------------------------------------------------------
nvidia::gxf::NativeBufferPolicy native_buffer_policy() const {
return native_buffer_policy_enum_;
}
int64_t native_buffer_acquire_timeout_ms() const;
int64_t native_buffer_export_ttl_ms() const;
const std::string& gpu_device_uuid() const { return gpu_device_uuid_; }
const std::string& host_id() const { return host_id_; }
int32_t gpu_device_id() const { return gpu_device_id_; }
nvidia::gxf::NativeBufferCapability native_buffer_capability() const;
private:
void configure_transports(eprosima::fastdds::dds::DomainParticipantQos& pqos);
void configure_discovery_peers(eprosima::fastdds::dds::DomainParticipantQos& pqos);
void cleanup();
// Parameters
Parameter<int32_t> domain_id_;
Parameter<std::string> participant_name_;
Parameter<std::vector<std::string>> discovery_peers_;
Parameter<std::string> transport_profile_;
Parameter<std::string> default_qos_profile_;
Parameter<std::shared_ptr<Allocator>> allocator_;
// Native buffer parameters
Parameter<std::string> native_buffer_policy_str_;
Parameter<int64_t> native_buffer_acquire_timeout_ms_;
Parameter<int64_t> native_buffer_export_ttl_ms_;
// DDS resources
eprosima::fastdds::dds::DomainParticipant* participant_ = nullptr;
std::unordered_map<std::string, eprosima::fastdds::dds::Topic*> topics_;
mutable std::mutex topics_mutex_;
// GPU staging resources
cudaStream_t cuda_stream_ = nullptr;
// Native buffer state
nvidia::gxf::NativeBufferPolicy native_buffer_policy_enum_{
nvidia::gxf::NativeBufferPolicy::kPreferred};
std::string gpu_device_uuid_;
int32_t gpu_device_id_{0};
bool cuda_ipc_supported_{false};
std::string host_id_;
};
} // namespace holoscan
#endif/* HOLOSCAN_PUBSUB_FASTDDS_RESOURCES_FASTDDS_PUBSUB_CONTEXT_HPP */