Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/everest/framework/lib/message_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ bool check_topic_matches(const std::string& full_topic, const std::string& wildc

return full_split.size() == wildcard_split.size();
}

template <typename HandlerMap, typename ExecuteFn>
void execute_handlers_from_vector_with_wildcards(HandlerMap& handlers, std::mutex& handler_mutex,
const std::string& topic, ExecuteFn execute_fn) {
std::vector<std::shared_ptr<TypedHandler>> handlers_copy;
{
std::lock_guard<std::mutex> lock(handler_mutex);
for (const auto& [wildcard_topic, handlers_vec] : handlers) {
if (check_topic_matches(topic, wildcard_topic)) {
handlers_copy.insert(handlers_copy.end(), handlers_vec.begin(), handlers_vec.end());
}
}
}
for (const auto& handler : handlers_copy) {
execute_fn(handler);
}
}
} // namespace

MessageHandler::MessageHandler() {
Expand Down Expand Up @@ -378,6 +395,10 @@ void MessageHandler::execute_handlers_from_vector(HandlerMap& handlers, const st
handlers_copy = it->second;
}
}
if (handlers_copy.empty()) {
execute_handlers_from_vector_with_wildcards(handlers, handler_mutex, topic, execute_fn);
return;
}
for (const auto& handler : handlers_copy) {
execute_fn(handler);
}
Expand Down
Loading