CARLA
Loading...
Searching...
No Matches
ISubscriberMiddleware.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma de Barcelona (UAB).
2// This work is licensed under the terms of the MIT license.
3// For a copy, see <https://opensource.org/licenses/MIT>.
4
5#pragma once
6
7#include <string>
8
10
11namespace carla {
12namespace ros2 {
13
14/// Type-erased abstract interface for a subscriber middleware.
15/// Concrete implementations write received messages directly into the caller-provided
16/// storage (message_ptr / new_message_flag) to avoid an extra copy.
17///
18/// Contract: when an implementation establishes its process-wide transport
19/// context (a DDS DomainParticipant, a Zenoh session, ...) it must honor
20/// carla::ros2::MiddlewareConfig::GetDomainId(), mapping kUnsetDomainId to its
21/// own native default. This keeps the ROS 2 domain id configurable and
22/// middleware-agnostic (see MiddlewareConfig.h).
24 public:
25 virtual ~ISubscriberMiddleware() = default;
26
27 /// Initialize the underlying middleware entities.
28 /// The middleware writes incoming messages to *message_ptr and sets *new_message_flag = true.
29 /// @param topic_name Full topic name.
30 /// @param message_ptr Pointer to the message storage owned by the caller.
31 /// @param new_message_flag Pointer to the new-message flag owned by the caller.
32 /// @return true on success.
33 virtual bool Init(
34 const std::string& topic_name,
35 void* message_ptr,
36 bool* new_message_flag) = 0;
37
38 /// Initialize with an explicit per-topic QoS profile (see QosProfile.h).
39 /// The default implementation ignores the profile and falls back to the
40 /// QoS-less Init so test fakes and QoS-agnostic middlewares keep working;
41 /// concrete backends override this to honor the profile.
42 virtual bool Init(
43 const std::string& topic_name,
44 void* message_ptr,
45 bool* new_message_flag,
46 const QosProfile& qos) {
47 (void)qos;
48 return Init(topic_name, message_ptr, new_message_flag);
49 }
50
51 /// @return true if at least one publisher is matched.
52 virtual bool IsAlive() const = 0;
53
54 /// @return The topic name this subscriber is bound to.
55 virtual std::string GetTopicName() const = 0;
56};
57
58} // namespace ros2
59} // namespace carla
Type-erased abstract interface for a subscriber middleware.
virtual bool Init(const std::string &topic_name, void *message_ptr, bool *new_message_flag)=0
Initialize the underlying middleware entities.
virtual bool IsAlive() const =0
virtual bool Init(const std::string &topic_name, void *message_ptr, bool *new_message_flag, const QosProfile &qos)
Initialize with an explicit per-topic QoS profile (see QosProfile.h).
virtual std::string GetTopicName() const =0
virtual ~ISubscriberMiddleware()=default
This file contains definitions of common data structures used in traffic manager.
Middleware-neutral QoS profile passed to IPublisherMiddleware::Init / ISubscriberMiddleware::Init whe...
Definition QosProfile.h:27