Holoscan SDK v4.2.0

Class InMemoryPubSubSession

Base Type

  • public std::enable_shared_from_this< InMemoryPubSubSession >

class InMemoryPubSubSession : public std::enable_shared_from_this<InMemoryPubSubSession>

Process-global shared state for a group of in-memory pub/sub participants.

InMemoryPubSubSession consolidates the SharedInMemoryPubSubBackend and SharedInMemoryPubSubSession into a single, reusable class. It owns a shared InMemoryDiscovery and InMemoryTransport, and provides per-participant discovery/transport frontends that multiplex callbacks so that each PubSubContext’s init_context() wiring is independent. This was implemented to enable test cases that involve launching multiple GXF contexts from the same process.

Public Functions

~InMemoryPubSubSession()
Frontends create_frontends()
void join(gxf_context_t context)

Join this session from a specific GXF context.

void leave(gxf_context_t context)

Leave this session from a specific GXF context.

bool is_multi_context() const

Returns true if more than one distinct GXF context has joined.

inline const std::string &session_id() const
nvidia::gxf::Expected<void> ensure_backends()
nvidia::gxf::Expected<void> retain_participant(const std::shared_ptr<InMemorySessionParticipant> &participant)
nvidia::gxf::Expected<void> release_participant(const std::shared_ptr<InMemorySessionParticipant> &participant)
nvidia::gxf::Expected<void> replay_existing_publishers(const std::shared_ptr<InMemorySessionParticipant> &participant) const
nvidia::gxf::Expected<void> replay_existing_subscribers(const std::shared_ptr<InMemorySessionParticipant> &participant) const
nvidia::gxf::Expected<void> announce_publisher(const std::shared_ptr<InMemorySessionParticipant> &participant, const nvidia::gxf::PublisherInfo &info)
nvidia::gxf::Expected<void> announce_subscriber(const std::shared_ptr<InMemorySessionParticipant> &participant, const nvidia::gxf::SubscriberInfo &info)
nvidia::gxf::Expected<void> remove_publisher(const std::shared_ptr<InMemorySessionParticipant> &participant, const nvidia::gxf::PublisherGid &gid)
nvidia::gxf::Expected<void> remove_subscriber(const std::shared_ptr<InMemorySessionParticipant> &participant, const nvidia::gxf::SubscriberGid &gid)
nvidia::gxf::Expected<std::vector<nvidia::gxf::PublisherInfo>> query_publishers(const std::string &topic_name) const
nvidia::gxf::Expected<std::vector<nvidia::gxf::SubscriberInfo>> query_subscribers(const std::string &topic_name) const
nvidia::gxf::Expected<std::vector<std::string>> get_all_topics() const
bool wait_for_subscribers(const std::string &topic_name, size_t expected_count, std::chrono::milliseconds timeout) const
nvidia::gxf::Expected<void> send(const nvidia::gxf::Gid &destination_gid, const std::vector<uint8_t> &payload, const nvidia::gxf::MessageMetadata &metadata) const
nvidia::gxf::Expected<void> send(const nvidia::gxf::Gid &destination_gid, std::vector<uint8_t> &&payload, const nvidia::gxf::MessageMetadata &metadata) const
size_t send_queue_size() const

Public Static Functions

static std::shared_ptr<InMemoryPubSubSession> get_or_create(const std::string &session_id)

Get or create a session by ID. Thread-safe. Returns the same shared_ptr for the same session_id within the process.

static void reset_all_for_testing()

Release all sessions and reset shared state for tests. Must only be called when no session frontends are active.

struct Frontends

Create a paired discovery + transport frontend that share the same participant state. The discovery and transport frontends must be used together for a single PubSubContext — they share per-participant callback state so that PubSubContext::init_context() wiring is independent per context.

Public Members

std::shared_ptr<nvidia::gxf::PubSubDiscovery> discovery
std::shared_ptr<nvidia::gxf::PubSubTransport> transport

Previous Class InMemoryPubSubNetworkContext
Next Class InputContext
© Copyright 2022-2026, NVIDIA. Last updated on May 11, 2026