CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
multigpu
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
"
8
#include "
carla/multigpu/secondaryCommands.h
"
9
10
#include <cstring>
11
12
namespace
carla
{
13
namespace
multigpu
{
14
15
void
SecondaryCommands::set_secondary
(std::shared_ptr<Secondary> secondary) {
16
_secondary
= secondary;
17
}
18
19
void
SecondaryCommands::set_callback
(
callback_type
callback) {
20
_callback
= callback;
21
}
22
23
void
SecondaryCommands::process_command
(
Buffer
buffer) {
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
Logging.h
carla::Buffer
A piece of raw data.
Definition
carla/Buffer.h:42
carla::Buffer::data
const value_type * data() const noexcept
Direct access to the allocated memory or nullptr if no memory is allocated.
Definition
carla/Buffer.h:156
carla::Buffer::size
size_type size() const noexcept
Definition
carla/Buffer.h:197
carla::multigpu::SecondaryCommands::callback_type
std::function< void(MultiGPUCommand, carla::Buffer)> callback_type
Definition
secondaryCommands.h:22
carla::multigpu::SecondaryCommands::_callback
callback_type _callback
Definition
secondaryCommands.h:30
carla::multigpu::SecondaryCommands::set_secondary
void set_secondary(std::shared_ptr< Secondary > secondary)
Definition
secondaryCommands.cpp:15
carla::multigpu::SecondaryCommands::process_command
void process_command(Buffer buffer)
Definition
secondaryCommands.cpp:23
carla::multigpu::SecondaryCommands::_secondary
std::shared_ptr< Secondary > _secondary
Definition
secondaryCommands.h:29
carla::multigpu::SecondaryCommands::set_callback
void set_callback(callback_type callback)
Definition
secondaryCommands.cpp:19
carla::multigpu
Definition
commands.h:17
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
secondaryCommands.h
carla::multigpu::CommandHeader
Definition
commands.h:29
carla::multigpu::CommandHeader::size
uint32_t size
Definition
commands.h:31
carla::multigpu::CommandHeader::id
MultiGPUCommand id
Definition
commands.h:30
Generated by
1.18.0