CARLA
 
载入中...
搜索中...
未找到
secondary.h
浏览该文件的文档.
1// Copyright (c) 2022 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 "carla/Buffer.h"
10#include "carla/NonCopyable.h"
11#include "carla/TypeTraits.h"
17#include "carla/ThreadPool.h"
18
19#include <boost/asio/deadline_timer.hpp>
20#include <boost/asio/io_context.hpp>
21#include <boost/asio/ip/tcp.hpp>
22#include <boost/asio/strand.hpp>
23
24#include <atomic>
25#include <functional>
26#include <memory>
27
28namespace carla {
29
30 class BufferPool;
31
32namespace multigpu {
33
35 : public std::enable_shared_from_this<Secondary>,
37 private NonCopyable {
38 public:
39
40 using endpoint = boost::asio::ip::tcp::endpoint;
41 using protocol_type = endpoint::protocol_type;
42
43 Secondary(boost::asio::ip::tcp::endpoint ep, SecondaryCommands::callback_type callback);
44 Secondary(std::string ip, uint16_t port, SecondaryCommands::callback_type callback);
45 ~Secondary();
46
47 void Connect();
48
49 void Stop();
50
51 void AsyncRun(size_t worker_threads);
52
53 void Write(std::shared_ptr<const carla::streaming::detail::tcp::Message> message);
54 void Write(Buffer buffer);
55 void Write(std::string text);
56
60
61 template <typename... Buffers>
62 static auto MakeMessage(Buffers... buffers) {
63 static_assert(
64 are_same<SharedBufferView, Buffers...>::value,
65 "This function only accepts arguments of type BufferView.");
66 return std::make_shared<const carla::streaming::detail::tcp::Message>(buffers...);
67 }
68
69 private:
70
71 void Reconnect();
72
73 void ReadData();
74
76 boost::asio::ip::tcp::socket _socket;
77 boost::asio::ip::tcp::endpoint _endpoint;
78 boost::asio::io_context::strand _strand;
79 boost::asio::deadline_timer _connection_timer;
80 std::shared_ptr<BufferPool> _buffer_pool;
81 std::atomic_bool _done {false};
83 };
84
85} // namespace multigpu
86} // namespace carla
A piece of raw data.
Inherit (privately) to suppress copy/move construction and assignment.
A thread pool based on Boost.Asio's io context.
Definition ThreadPool.h:24
std::function< void(MultiGPUCommand, carla::Buffer)> callback_type
boost::asio::ip::tcp::endpoint _endpoint
Definition secondary.h:77
boost::asio::ip::tcp::endpoint endpoint
Definition secondary.h:40
std::shared_ptr< BufferPool > _buffer_pool
Definition secondary.h:80
Secondary(boost::asio::ip::tcp::endpoint ep, SecondaryCommands::callback_type callback)
Definition secondary.cpp:27
boost::asio::io_context::strand _strand
Definition secondary.h:78
SecondaryCommands _commander
Definition secondary.h:82
boost::asio::ip::tcp::socket _socket
Definition secondary.h:76
SecondaryCommands & GetCommander()
Definition secondary.h:57
void AsyncRun(size_t worker_threads)
std::atomic_bool _done
Definition secondary.h:81
boost::asio::deadline_timer _connection_timer
Definition secondary.h:79
static auto MakeMessage(Buffers... buffers)
Definition secondary.h:62
void Write(std::shared_ptr< const carla::streaming::detail::tcp::Message > message)
endpoint::protocol_type protocol_type
Definition secondary.h:41
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
std::shared_ptr< BufferView > SharedBufferView
Definition BufferView.h:151