CARLA
Loading...
Searching...
No Matches
secondaryCommands.cpp
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#include "carla/Logging.h"
9
10#include <cstring>
11
12namespace carla {
13namespace multigpu {
14
15void SecondaryCommands::set_secondary(std::shared_ptr<Secondary> secondary) {
16 _secondary = secondary;
17}
18
20 _callback = callback;
21}
22
24 // Each message is framed by the transport's size prefix, so dropping a
25 // malformed one never desynchronizes the stream.
26 CommandHeader header;
27 if (buffer.size() < sizeof(header)) {
28 log_error("multigpu: dropping a", buffer.size(), "byte command shorter than its header");
29 return;
30 }
31 std::memcpy(&header, buffer.data(), sizeof(header));
32 const std::size_t available = buffer.size() - sizeof(header);
33 if (header.size > available) {
34 log_error("multigpu: dropping command", static_cast<uint32_t>(header.id), "declaring",
35 header.size, "payload bytes in a message holding", available);
36 return;
37 }
38 if (header.size < available) {
39 log_warning("multigpu: command", static_cast<uint32_t>(header.id), "has",
40 available - header.size, "trailing bytes; ignored");
41 }
42
43 // send only data to the callback
44 Buffer data(buffer.data() + sizeof(header), header.size);
45 _callback(header.id, std::move(data));
46}
47
48
49} // namespace multigpu
50} // namespace carla
A piece of raw data.
const value_type * data() const noexcept
Direct access to the allocated memory or nullptr if no memory is allocated.
size_type size() const noexcept
std::function< void(MultiGPUCommand, carla::Buffer)> callback_type
void set_secondary(std::shared_ptr< Secondary > secondary)
std::shared_ptr< Secondary > _secondary
void set_callback(callback_type callback)
This file contains definitions of common data structures used in traffic manager.
static void log_error(Args &&... args)
Definition Logging.h:110
static void log_warning(Args &&... args)
Definition Logging.h:96