CARLA
 
载入中...
搜索中...
未找到
streaming/detail/tcp/Client.h
浏览该文件的文档.
1// Copyright (c) 2017 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"
14
15#include <boost/asio/deadline_timer.hpp>
16#include <boost/asio/io_context.hpp>
17#include <boost/asio/ip/tcp.hpp>
18#include <boost/asio/strand.hpp>
19
20#include <atomic>
21#include <functional>
22#include <memory>
23
24namespace carla {
25
26 class BufferPool;
27
28namespace streaming {
29namespace detail {
30namespace tcp {
31
32 /// A client that connects to a single stream.
33 ///
34 /// @warning This client should be stopped before releasing the shared pointer
35 /// or won't be destroyed.
36 class Client
37 : public std::enable_shared_from_this<Client>,
39 private NonCopyable {
40 public:
41
42 using endpoint = boost::asio::ip::tcp::endpoint;
43 using protocol_type = endpoint::protocol_type;
44 using callback_function_type = std::function<void (Buffer)>;
45
46 Client(
47 boost::asio::io_context &io_context,
48 const token_type &token,
49 callback_function_type callback);
50
52
53 void Connect();
54
56 return _token.get_stream_id();
57 }
58
59 void Stop();
60
61 private:
62
63 void Reconnect();
64
65 void ReadData();
66
68
70
71 boost::asio::ip::tcp::socket _socket;
72
73 boost::asio::io_context::strand _strand;
74
75 boost::asio::deadline_timer _connection_timer;
76
77 std::shared_ptr<BufferPool> _buffer_pool;
78
79 std::atomic_bool _done{false};
80 };
81
82} // namespace tcp
83} // namespace detail
84} // namespace streaming
85} // namespace carla
A piece of raw data.
Inherit (privately) to suppress copy/move construction and assignment.
A client that connects to a single stream.
std::function< void(Buffer)> callback_function_type
Client(boost::asio::io_context &io_context, const token_type &token, callback_function_type callback)
Serializes a stream endpoint.
uint32_t stream_id_type
Definition Types.h:18
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133