CARLA
Loading...
Searching...
No Matches
BaseSubscriber.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include <string>
10
12
13namespace carla {
14namespace ros2 {
15
17public:
18 BaseSubscriber() = default;
19
20 explicit BaseSubscriber(std::string base_topic_name)
21 : _base_topic_name(std::move(base_topic_name)) {}
22
23 BaseSubscriber(std::string base_topic_name, std::string frame_id)
24 : _base_topic_name(std::move(base_topic_name)),
25 _frame_id(std::move(frame_id)) {}
26
27 BaseSubscriber(void *actor, std::string base_topic_name, std::string frame_id)
28 : _actor(actor),
29 _base_topic_name(std::move(base_topic_name)),
30 _frame_id(std::move(frame_id)) {}
31
32 virtual ~BaseSubscriber() = default;
33
34 // Polymorphic base held only via std::shared_ptr<BaseSubscriber>; copying or
35 // moving one would slice the derived subscriber, so disable it outright.
36 BaseSubscriber(const BaseSubscriber &) = delete;
40
41 virtual void ProcessMessages(ActorCallback callback) = 0;
42
43 [[nodiscard]] void *GetActor() const noexcept { return _actor; }
44 [[nodiscard]] const std::string &GetBaseTopicName() const noexcept { return _base_topic_name; }
45 [[nodiscard]] const std::string &GetFrameId() const noexcept { return _frame_id; }
46
47protected:
48 // Decoding the latest sample yields stale data unless gated behind the impl's
49 // HasNewMessage(); kept protected so only ProcessMessages can reach it.
51
52 void *_actor{nullptr};
53 std::string _base_topic_name;
54 std::string _frame_id;
55};
56
57} // namespace ros2
58} // namespace carla
BaseSubscriber & operator=(BaseSubscriber &&)=delete
BaseSubscriber & operator=(const BaseSubscriber &)=delete
BaseSubscriber(BaseSubscriber &&)=delete
virtual ~BaseSubscriber()=default
virtual ROS2CallbackData GetMessage()=0
BaseSubscriber(const BaseSubscriber &)=delete
const std::string & GetFrameId() const noexcept
virtual void ProcessMessages(ActorCallback callback)=0
BaseSubscriber(std::string base_topic_name, std::string frame_id)
const std::string & GetBaseTopicName() const noexcept
void * GetActor() const noexcept
BaseSubscriber(void *actor, std::string base_topic_name, std::string frame_id)
BaseSubscriber(std::string base_topic_name)
std::function< void(void *actor, ROS2CallbackData data)> ActorCallback
std::variant< VehicleControl, AckermannControl, VehicleAccelerationControl > ROS2CallbackData
This file contains definitions of common data structures used in traffic manager.