CARLA
 
载入中...
搜索中...
未找到
streaming/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/Logging.h"
10#include "carla/ThreadPool.h"
14
15#include <boost/asio/io_context.hpp>
16
17namespace carla {
18namespace streaming {
19
21
22 /// A client able to subscribe to multiple streams.
23 class Client {
25 public:
26
27 Client() = default;
28
29 explicit Client(const std::string &fallback_address)
30 : _client(fallback_address) {}
31
33 _service.Stop();
34 }
35
36 /// @warning cannot subscribe twice to the same stream (even if it's a
37 /// MultiStream).
38 template <typename Functor>
39 void Subscribe(const Token &token, Functor &&callback) {
40 _client.Subscribe(_service.io_context(), token, std::forward<Functor>(callback));
41 }
42
43 void UnSubscribe(const Token &token) {
44 _client.UnSubscribe(token);
45 }
46
47 void Run() {
48 _service.Run();
49 }
50
51 void AsyncRun(size_t worker_threads) {
52 _service.AsyncRun(worker_threads);
53 }
54
55 private:
56
57 // The order of these two arguments is very important.
58
60
62 };
63
64} // namespace streaming
65} // 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
auto & io_context()
Return the underlying io_context.
Definition ThreadPool.h:35
A client able to subscribe to multiple streams.
void AsyncRun(size_t worker_threads)
void Subscribe(const Token &token, Functor &&callback)
void UnSubscribe(const Token &token)
Client(const std::string &fallback_address)
underlying_client _client
A token that uniquely identify a stream.
Definition Token.h:17
Serializes a stream endpoint.
void Subscribe(boost::asio::io_context &io_context, token_type token, Functor &&callback)
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133