CARLA
 
载入中...
搜索中...
未找到
Dispatcher.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
14
15#include <memory>
16#include <mutex>
17#include <unordered_map>
18
19namespace carla {
20namespace streaming {
21namespace detail {
22
23 class MultiStreamState;
24 using StreamMap = std::unordered_map<stream_id_type, std::shared_ptr<MultiStreamState>>;
25
26 /// Keeps the mapping between streams and sessions.
27 class Dispatcher {
28 public:
29
30 template <typename Protocol, typename EndPointType>
32 : _cached_token(0u, ep) {}
33
35
37
39
40 bool RegisterSession(std::shared_ptr<Session> session);
41
42 void DeregisterSession(std::shared_ptr<Session> session);
43
45
46 void EnableForROS(stream_id_type sensor_id) {
47 auto search = _stream_map.find(sensor_id);
48 if (search != _stream_map.end()) {
49 search->second->EnableForROS();
50 }
51 }
52
53 void DisableForROS(stream_id_type sensor_id) {
54 auto search = _stream_map.find(sensor_id);
55 if (search != _stream_map.end()) {
56 search->second->DisableForROS();
57 }
58 }
59
61 auto search = _stream_map.find(sensor_id);
62 if (search != _stream_map.end()) {
63 return search->second->IsEnabledForROS();
64 }
65 return false;
66 }
67
68 private:
69
70 // We use a mutex here, but we assume that sessions and streams won't be
71 // created too often.
72 std::mutex _mutex;
73
75
77 };
78
79} // namespace detail
80} // namespace streaming
81} // namespace carla
Keeps the mapping between streams and sessions.
Definition Dispatcher.h:27
void DeregisterSession(std::shared_ptr< Session > session)
Dispatcher(const EndPoint< Protocol, EndPointType > &ep)
Definition Dispatcher.h:31
carla::streaming::Stream MakeStream()
bool RegisterSession(std::shared_ptr< Session > session)
void DisableForROS(stream_id_type sensor_id)
Definition Dispatcher.h:53
bool IsEnabledForROS(stream_id_type sensor_id)
Definition Dispatcher.h:60
void CloseStream(carla::streaming::detail::stream_id_type id)
void EnableForROS(stream_id_type sensor_id)
Definition Dispatcher.h:46
token_type GetToken(stream_id_type sensor_id)
Serializes a stream endpoint.
std::unordered_map< stream_id_type, std::shared_ptr< MultiStreamState > > StreamMap
Definition Dispatcher.h:24
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