Class PubSubContext
Defined in File pubsub_context.hpp
Base Type
public holoscan::gxf::GXFNetworkContext(Class GXFNetworkContext)
-
class PubSubContext : public holoscan::gxf::GXFNetworkContext
Pub/Sub NetworkContext class for topic-based inter-fragment communication.
PubSubContext provides topic-based publish/subscribe messaging for distributed Holoscan applications. It wraps the GXF
nvidia::gxf::PubSubContextcomponent, which is backend-agnostic and supports different discovery and transport implementations.Public Functions
-
template<typename ArgT, typename ...ArgsT, typename = std::enable_if_t<!std::is_base_of_v<::holoscan::NetworkContext, std::decay_t<ArgT>> && (std::is_same_v<::holoscan::Arg, std::decay_t<ArgT>> || std::is_same_v<::holoscan::ArgList, std::decay_t<ArgT>>)>>
inline explicit PubSubContext(ArgT &&arg, ArgsT&&... args)
-
PubSubContext() = default
-
inline virtual const char *gxf_typename() const override
Get the type name of the GXF network context.
The returned string is the type name of the GXF network context and is used to create the GXF network context.
Example: “nvidia::holoscan::UcxContext”
- Returns
The type name of the GXF network context.
-
virtual void setup(ComponentSpec &spec) override
Define the network context specification.
- Parameters
spec – The reference to the component specification.
-
virtual void initialize() override
Initialize the network context.
This function is called after the network context is created by holoscan::Fragment::make_network_context().
-
virtual std::shared_ptr<Clock> clock() override
Get the Clock used by the network context.
- Returns
The Clock used by the network context, or nullptr if not applicable.
-
nvidia::gxf::PubSubContext *get() const
Get the underlying GXF PubSubContext component.
- Returns
Pointer to the GXF PubSubContext, or nullptr if not initialized.
-
std::string node_name() const
Get the node name for this context.
- Returns
The node name string.
-
std::vector<nvidia::gxf::TopicInfo> get_topics() const
Get information about all known topics.
- Returns
Vector of TopicInfo structures.
-
size_t get_publisher_count(const std::string &topic) const
Get number of publishers on a topic.
- Parameters
topic – Topic name to query.
- Returns
Number of publishers.
-
size_t get_subscriber_count(const std::string &topic) const
Get number of subscribers on a topic.
- Parameters
topic – Topic name to query.
- Returns
Number of subscribers.
-
std::vector<nvidia::gxf::Gid> registered_publisher_gids() const
Get the GIDs of all locally registered publishers.
- Returns
Vector of publisher GIDs (snapshot under lock).
-
std::vector<nvidia::gxf::Gid> registered_subscriber_gids() const
Get the GIDs of all locally registered subscribers.
- Returns
Vector of subscriber GIDs (snapshot under lock).
-
nvidia::gxf::Expected<nvidia::gxf::Handle<nvidia::gxf::Transmitter>> get_publisher_transmitter(const nvidia::gxf::Gid &gid) const
Look up the transmitter Handle for a registered publisher.
- Parameters
gid – Publisher GID.
- Returns
Handle to the Transmitter, or Unexpected with GXF_ENTITY_NOT_FOUND.
-
nvidia::gxf::Expected<nvidia::gxf::Handle<nvidia::gxf::Receiver>> get_subscriber_receiver(const nvidia::gxf::Gid &gid) const
Look up the receiver Handle for a registered subscriber.
- Parameters
gid – Subscriber GID.
- Returns
Handle to the Receiver, or Unexpected with GXF_ENTITY_NOT_FOUND.
Protected Functions
-
virtual void setup_backend()
Set up the PubSub backend (discovery, transport, serializer).
Called automatically from initialize() after the GXF component is created and
get()returns a valid pointer.The default implementation is a no-op. Subclasses should override this to create backend components and inject them into the GXF PubSubContext:
void setup_backend() override { auto* gxf_ctx = get(); gxf_ctx->set_discovery(std::make_shared<MyDiscovery>(...)); gxf_ctx->set_transport(std::make_shared<MyTransport>(...)); gxf_ctx->set_serializer(std::make_shared<MySerializer>(...)); gxf_ctx->initialize(); gxf_ctx->init_context(); }
See alsoDDSPubSubNetworkContext for the FastDDS backend implementation.
-
template<typename ArgT, typename ...ArgsT, typename = std::enable_if_t<!std::is_base_of_v<::holoscan::NetworkContext, std::decay_t<ArgT>> && (std::is_same_v<::holoscan::Arg, std::decay_t<ArgT>> || std::is_same_v<::holoscan::ArgList, std::decay_t<ArgT>>)>>