CARLA
 
载入中...
搜索中...
未找到
streaming/Server.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/ThreadPool.h"
13
14#include <boost/asio/io_context.hpp>
15
16namespace carla {
17namespace streaming {
18
19 /// A streaming server. Each new stream has a token associated, this token can
20 /// be used by a client to subscribe to the stream.
21 class Server {
26 public:
27
28 explicit Server(uint16_t port)
29 : _server(_pool.io_context(), make_endpoint<protocol_type>(port)) {}
30
31 explicit Server(const std::string &address, uint16_t port)
32 : _server(_pool.io_context(), make_endpoint<protocol_type>(address, port)) {}
33
34 explicit Server(
35 const std::string &address, uint16_t port,
36 const std::string &external_address, uint16_t external_port)
37 : _server(
38 _pool.io_context(),
39 make_endpoint<protocol_type>(address, port),
40 make_endpoint<protocol_type>(external_address, external_port)) {}
41
43 _pool.Stop();
44 }
45
46 auto GetLocalEndpoint() const {
48 }
49
50 void SetTimeout(time_duration timeout) {
51 _server.SetTimeout(timeout);
52 }
53
55 return _server.MakeStream();
56 }
57
61
62 void Run() {
63 _pool.Run();
64 }
65
66 void AsyncRun(size_t worker_threads) {
67 _pool.AsyncRun(worker_threads);
68 }
69
70 void SetSynchronousMode(bool is_synchro) {
71 _server.SetSynchronousMode(is_synchro);
72 }
73
75 return _server.GetToken(sensor_id);
76 }
77
78 void EnableForROS(stream_id sensor_id) {
79 _server.EnableForROS(sensor_id);
80 }
81
82 void DisableForROS(stream_id sensor_id) {
83 _server.DisableForROS(sensor_id);
84 }
85
86 bool IsEnabledForROS(stream_id sensor_id) {
87 return _server.IsEnabledForROS(sensor_id);
88 }
89
90 private:
91
92 // The order of these two arguments is very important.
93
95
97 };
98
99} // namespace streaming
100} // namespace carla
A thread pool based on Boost.Asio's io context.
Definition ThreadPool.h:24
void Stop()
Stop the ThreadPool and join all its threads.
Definition ThreadPool.h:76
void AsyncRun(size_t worker_threads)
Launch threads to run tasks asynchronously.
Definition ThreadPool.h:51
void Run()
Run tasks in this thread.
Definition ThreadPool.h:63
A streaming server.
carla::streaming::detail::stream_id_type stream_id
token_type GetToken(stream_id sensor_id)
void SetTimeout(time_duration timeout)
Server(const std::string &address, uint16_t port)
bool IsEnabledForROS(stream_id sensor_id)
void CloseStream(carla::streaming::detail::stream_id_type id)
void EnableForROS(stream_id sensor_id)
low_level::Server< detail::tcp::Server >::protocol_type protocol_type
underlying_server _server
Server(const std::string &address, uint16_t port, const std::string &external_address, uint16_t external_port)
void AsyncRun(size_t worker_threads)
void DisableForROS(stream_id sensor_id)
void SetSynchronousMode(bool is_synchro)
Serializes a stream endpoint.
void CloseStream(carla::streaming::detail::stream_id_type id)
typename underlying_server::protocol_type protocol_type
token_type GetToken(stream_id sensor_id)
underlying_server::endpoint GetLocalEndpoint() const
Positive time duration up to milliseconds resolution.
Definition Time.h:19
uint32_t stream_id_type
Definition Types.h:18
static auto make_endpoint(boost::asio::ip::basic_endpoint< Protocol > ep)
Definition EndPoint.h:90
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133