File type_support.hpp

File List > astutedds > rmw > type_support.hpp

Go to the documentation of this file

//
// Copyright (c) 2026, Astute Systems PTY LTD
//
// This file is part of the AstuteDDS RMW implementation.
//
// See the commercial LICENSE file in the project root for full license details.
//

#pragma once

#include <cstdint>
#include <string>

#include <rosidl_runtime_c/message_type_support_struct.h>
#include <rosidl_runtime_c/service_type_support_struct.h>
#include <rosidl_runtime_c/string.h>
#include <rosidl_runtime_c/string_functions.h>
#include <rosidl_typesupport_introspection_c/field_types.h>
#include <rosidl_typesupport_introspection_c/identifier.h>
#include <rosidl_typesupport_introspection_c/message_introspection.h>
#include <rosidl_typesupport_introspection_c/service_introspection.h>
#include <rosidl_typesupport_introspection_cpp/identifier.hpp>
#include <rosidl_typesupport_introspection_cpp/message_introspection.hpp>
#include <rosidl_typesupport_introspection_cpp/service_introspection.hpp>

// ---------------------------------------------------------------------------
// Introspection type aliases
// ---------------------------------------------------------------------------

using MembersC   = rosidl_typesupport_introspection_c__MessageMembers;
using MemberC    = rosidl_typesupport_introspection_c__MessageMember;
using MembersCpp = rosidl_typesupport_introspection_cpp::MessageMembers;
using MemberCpp  = rosidl_typesupport_introspection_cpp::MessageMember;
using ServiceMembersC   = rosidl_typesupport_introspection_c__ServiceMembers;
using ServiceMembersCpp = rosidl_typesupport_introspection_cpp::ServiceMembers;

// ---------------------------------------------------------------------------
// TypeSupportHandle
// ---------------------------------------------------------------------------

struct TypeSupportHandle
{
    bool is_cpp { false };
    union
    {
        const MembersC   * c;    
        const MembersCpp * cpp;  
    } members {};

    bool valid() const { return members.c != nullptr; }

    const char * message_namespace() const
    {
        return is_cpp ? members.cpp->message_namespace_ : members.c->message_namespace_;
    }

    const char * message_name() const
    {
        return is_cpp ? members.cpp->message_name_ : members.c->message_name_;
    }

    uint32_t member_count() const
    {
        return is_cpp ? members.cpp->member_count_ : members.c->member_count_;
    }
};

// ---------------------------------------------------------------------------
// Resolution + naming
// ---------------------------------------------------------------------------

TypeSupportHandle
get_type_support(const rosidl_message_type_support_t * type_support);

bool
get_service_type_support(
    const rosidl_service_type_support_t * type_support,
    TypeSupportHandle & request_out,
    TypeSupportHandle & response_out);

std::string
dds_topic_name(const char * ros_topic);

std::string
dds_type_name(const TypeSupportHandle & ts);

// ---------------------------------------------------------------------------
// Reverse mangling — DDS wire names → ROS 2 graph-query names
//
// Used by the graph query entry points (`get_topic_names_and_types.cpp`,
// `get_service_names_and_types.cpp`, `get_node_info_and_types.cpp`,
// `get_topic_endpoint_info.cpp`) to present the same names a caller would
// have passed to `rmw_create_publisher()` / `rmw_create_subscription()` /
// `rmw_create_client()` / `rmw_create_service()`, per
// http://design.ros2.org/articles/topic_and_service_names.html.
// ---------------------------------------------------------------------------

bool
is_regular_ros_topic(const std::string & dds_topic);

bool
is_ros_service_request_topic(const std::string & dds_topic);

bool
is_ros_service_reply_topic(const std::string & dds_topic);

std::string
demangle_ros_topic(const std::string & dds_topic);

std::string
demangle_ros_service_name(const std::string & dds_topic);

std::string
demangle_ros_type(const std::string & dds_type_name);