File topic_refcount.hpp

FileList > astutedds > rmw > topic_refcount.hpp

Go to the source code of this file

Local reference-counting helpers for AstuteDDS Topics. More...

  • #include <string>
  • #include <astutedds/rmw/types.hpp>

Public Functions

Type Name
void acquire_topic_ref (AstuteDDSContext * ctx, const std::string & dds_topic_name)
void release_topic_ref (AstuteDDSContext * ctx, const std::string & dds_topic_name, AstuteDDS_Topic topic)

Detailed Description

AstuteDDS's Topic is deduplicated-by-name but not refcounted: creating a second Topic for a name already in use on the same DomainParticipant returns the existing handle rather than a fresh one. A publisher and a subscription on the same topic name therefore share one underlying AstuteDDS_Topic, so deleting it on the first entity's destroy path would leave the second entity's topic pointer dangling. These helpers track a local refcount per topic name (see AstuteDDSContext::topic_refcount) so the topic is only deleted once the last local publisher or subscription referencing it is gone.

Public Functions Documentation

function acquire_topic_ref

void acquire_topic_ref (
    AstuteDDSContext * ctx,
    const std::string & dds_topic_name
) 

Increment the local reference count for dds_topic_name on ctx. Call once, right after a successful astutedds_create_topic(), from both rmw_create_publisher and rmw_create_subscription.


function release_topic_ref

void release_topic_ref (
    AstuteDDSContext * ctx,
    const std::string & dds_topic_name,
    AstuteDDS_Topic topic
) 

Decrement the reference count for dds_topic_name and delete the underlying AstuteDDS topic only once the last local publisher or subscription referencing it is gone. Use this everywhere a topic created via acquire_topic_ref() would otherwise be passed to astutedds_delete_topic() directly (both the destroy paths and any later failure path inside create).



The documentation for this class was generated from the following file include/astutedds/rmw/topic_refcount.hpp