CARLA
Loading...
Searching...
No Matches
IPublisherMiddleware.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 publisher middleware.
15/// Concrete implementations handle all vendor-specific entity creation,
16/// type registration, and data writing.
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 ~IPublisherMiddleware() = default;
26
27 /// Initialize the underlying middleware entities.
28 /// @param topic_name Full topic name including "rt/" prefix.
29 /// @return true on success.
30 virtual bool Init(const std::string& topic_name) = 0;
31
32 /// Initialize with an explicit per-topic QoS profile (see QosProfile.h).
33 /// The default implementation ignores the profile and falls back to the
34 /// QoS-less Init so test fakes and QoS-agnostic middlewares keep working;
35 /// concrete backends override this to honor the profile.
36 virtual bool Init(const std::string& topic_name, const QosProfile& qos) {
37 (void)qos;
38 return Init(topic_name);
39 }
40
41 /// Serialize and write a message to the network.
42 /// @param message_data Pointer to the message object (type-erased, cast internally).
43 /// @return true if the write succeeded.
44 virtual bool Publish(void* message_data) = 0;
45
46 /// @return true if at least one subscriber is matched.
47 virtual bool IsAlive() const = 0;
48
49 /// @return The topic name this publisher is bound to.
50 virtual std::string GetTopicName() const = 0;
51};
52
53} // namespace ros2
54} // namespace carla
Type-erased abstract interface for a publisher middleware.
virtual bool Publish(void *message_data)=0
Serialize and write a message to the network.
virtual std::string GetTopicName() const =0
virtual bool Init(const std::string &topic_name, const QosProfile &qos)
Initialize with an explicit per-topic QoS profile (see QosProfile.h).
virtual ~IPublisherMiddleware()=default
virtual bool Init(const std::string &topic_name)=0
Initialize the underlying middleware entities.
virtual bool IsAlive() const =0
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