24#ifndef LIBCARLA_NO_EXCEPTIONS
27 auto stream_state = pair.second;
28 stream_state->ClearSessions();
29#ifndef LIBCARLA_NO_EXCEPTIONS
30 }
catch (
const std::exception &e) {
31 log_error(
"failed to clear sessions:", e.what());
38 std::scoped_lock<std::mutex> lock(
_mutex);
41 std::shared_ptr<MultiStreamState> ptr;
64 std::scoped_lock<std::mutex> lock(
_mutex);
65 log_debug(
"Calling CloseStream for ",
id);
68 auto stream_state = search->second;
70 log_debug(
"Disconnecting all sessions (stream ",
id,
")");
71 stream_state->ClearSessions();
79 return session_stream_id;
90 std::scoped_lock<std::mutex> lock(
_mutex);
94 auto stream_state = search->second;
96 log_debug(
"Connecting session (stream ", session->get_stream_id(),
")");
98 stream_state->ConnectSession(std::move(session));
104 log_error(
"Invalid session: no stream available with id", session->get_stream_id());
110 std::scoped_lock<std::mutex> lock(
_mutex);
111 log_debug(
"Calling DeregisterSession for ", session->get_stream_id());
118 auto stream_state = search->second.lock();
121 log_debug(
"Disconnecting session (stream ", session->get_stream_id(),
")");
122 stream_state->DisconnectSession(session);
128 std::scoped_lock<std::mutex> lock(
_mutex);
129 log_debug(
"Searching sensor id: ", sensor_id);
132 log_debug(
"Found sensor id: ", sensor_id);
133 auto stream_state = search->second;
134 stream_state->ForceActive();
135 log_debug(
"Getting token from stream ", sensor_id,
" on port ", stream_state->token().get_port());
136 return stream_state->token();
138 log_debug(
"Not Found sensor id, creating sensor stream: ", sensor_id);
141 auto ptr = std::make_shared<MultiStreamState>(temp_token);
148 if (!result.second) {
149 log_debug(
"Failed to create multistream for stream ", sensor_id,
" on port ", temp_token.
get_port());
152 log_debug(
"Created token from stream ", sensor_id,
" on port ", temp_token.
get_port());
159 std::scoped_lock<std::mutex> lock(
_mutex);
164 auto stream_state = search->second;
165 stream_state->ForceActive();
166 return stream_state->token();
170 std::scoped_lock<std::mutex> lock(
_mutex);
175 std::scoped_lock<std::mutex> lock(
_mutex);
180 std::scoped_lock<std::mutex> lock(
_mutex);
185 std::scoped_lock<std::mutex> lock(
_mutex);
190 return search->second;
#define DEBUG_ASSERT(predicate)
bool _topic_visibility_default_enabled
void SetSessionsUseStreamAliases(bool enabled)
When enabled, a session subscribes through an alias (see SetStreamAlias) and a stream id without an a...
void SetStreamAlias(stream_id_type alias, stream_id_type stream_id)
Routes sessions subscribing to alias to the local stream stream_id.
void DeregisterSession(std::shared_ptr< Session > session)
std::unordered_map< const Session *, std::weak_ptr< MultiStreamState > > _session_streams
std::optional< stream_id_type > ResolveSessionStreamId(stream_id_type session_stream_id) const
Stream a session subscribing to session_stream_id belongs to.
bool _sessions_use_stream_aliases
carla::streaming::Stream MakeStream()
std::optional< token_type > FindToken(stream_id_type stream_id)
Like GetToken(), but returns std::nullopt for an unknown stream_id instead of creating an empty strea...
bool RegisterSession(std::shared_ptr< Session > session)
std::optional< stream_id_type > FindStreamAlias(stream_id_type alias)
void CloseStream(carla::streaming::detail::stream_id_type id)
std::unordered_map< stream_id_type, stream_id_type > _stream_aliases
void RemoveStreamAlias(stream_id_type alias)
token_type GetToken(stream_id_type sensor_id)
Serializes a stream endpoint.
const auto & get_stream_id() const
void set_stream_id(stream_id_type id)
detail::Stream< detail::MultiStreamState > Stream
A stream represents an unidirectional channel for sending data from server to client.
This file contains definitions of common data structures used in traffic manager.
static void log_error(Args &&... args)
void throw_exception(const ExceptionT &e)
Templated on the static type so the thrown object keeps its dynamic type: taking a const std::excepti...
static void log_debug(Args &&... args)