CARLA
streaming/Server.h
Go to the documentation of this file.
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"
12 
13 #include <boost/asio/io_context.hpp>
14 
15 namespace carla {
16 namespace streaming {
17 
18  /// A streaming server. Each new stream has a token associated, this token can
19  /// be used by a client to subscribe to the stream.
20  class Server {
23  public:
24 
25  explicit Server(uint16_t port)
26  : _server(_pool.io_context(), make_endpoint<protocol_type>(port)) {}
27 
28  explicit Server(const std::string &address, uint16_t port)
29  : _server(_pool.io_context(), make_endpoint<protocol_type>(address, port)) {}
30 
31  explicit Server(
32  const std::string &address, uint16_t port,
33  const std::string &external_address, uint16_t external_port)
34  : _server(
35  _pool.io_context(),
36  make_endpoint<protocol_type>(address, port),
37  make_endpoint<protocol_type>(external_address, external_port)) {}
38 
39  ~Server() {
40  _pool.Stop();
41  }
42 
43  auto GetLocalEndpoint() const {
44  return _server.GetLocalEndpoint();
45  }
46 
47  void SetTimeout(time_duration timeout) {
48  _server.SetTimeout(timeout);
49  }
50 
52  return _server.MakeStream();
53  }
54 
55  void Run() {
56  _pool.Run();
57  }
58 
59  void AsyncRun(size_t worker_threads) {
60  _pool.AsyncRun(worker_threads);
61  }
62 
63  void SetSynchronousMode(bool is_synchro) {
64  _server.SetSynchronousMode(is_synchro);
65  }
66 
67  private:
68 
69  // The order of these two arguments is very important.
70 
72 
74  };
75 
76 } // namespace streaming
77 } // namespace carla
void AsyncRun(size_t worker_threads)
A streaming server.
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
low_level::Server< detail::tcp::Server >::protocol_type protocol_type
static auto make_endpoint(boost::asio::ip::basic_endpoint< Protocol > ep)
Definition: EndPoint.h:90
void SetTimeout(time_duration timeout)
Server(const std::string &address, uint16_t port, const std::string &external_address, uint16_t external_port)
Server(const std::string &address, uint16_t port)
void Run()
Run tasks in this thread.
Definition: ThreadPool.h:63
A thread pool based on Boost.Asio&#39;s io context.
Definition: ThreadPool.h:24
void Stop()
Stop the ThreadPool and join all its threads.
Definition: ThreadPool.h:76
typename underlying_server::protocol_type protocol_type
Positive time duration up to milliseconds resolution.
Definition: Time.h:19
underlying_server _server
void AsyncRun(size_t worker_threads)
Launch threads to run tasks asynchronously.
Definition: ThreadPool.h:51
underlying_server::endpoint GetLocalEndpoint() const
void SetSynchronousMode(bool is_synchro)