diff --git a/src/shared/Core/Message/Filter.h b/src/shared/Core/Message/Filter.h index 44d95c49ed3c38fb4990c007d60b52aa66484cf0..d711606936d1db725c6d1e0408793f18b1be9d17 100644 --- a/src/shared/Core/Message/Filter.h +++ b/src/shared/Core/Message/Filter.h @@ -29,7 +29,7 @@ * The topic can contain wildcard symbols * and ? as last token. For example: * - "*" and "?" match with all topics * - "Prefix/?" matches with "Prefix", "Prefix/A" and "Prefix/A/B" - * - "Prefix/*" matches with "Prefix/A" and "Prefix/A/B" + * - "Prefix/any" matches with "Prefix/A" and "Prefix/A/B" * * The difference between * and ? is that the latter also matches when only the * prefix is present. diff --git a/src/shared/Core/MessageBroker/MessageBroker.cpp b/src/shared/Core/MessageBroker/MessageBroker.cpp index 6065f0bbccd50aa1808e4adbee03e4d4fa3e97df..ba0a26e803de3d01245518999a7b3e3b48809910 100644 --- a/src/shared/Core/MessageBroker/MessageBroker.cpp +++ b/src/shared/Core/MessageBroker/MessageBroker.cpp @@ -25,8 +25,8 @@ void MessageBroker::subscribe(Filter filter, Module* observer, { observers.insert(filter, {observer, new Callback(std::move(callback))}); - // Register the beforeDelete slot of the module to automatically remove the - // subscriber + // Register the beforeDelete slot of the module to automatically + // remove the subscriber connect(observer->getEventHandler(), &EventHandler::beforeDelete, this, &MessageBroker::onModuleDeleted); } @@ -44,9 +44,11 @@ void MessageBroker::unsubscribe(Filter filter, Module* module) void MessageBroker::publish(const Message& message) { - for (auto filter : observers.keys()) + // Iterate over all filters to check if the message matches any + for (auto filter : observers.uniqueKeys()) { - // If the message matches the filed, then notify all its subscribers + // If the message matches this particular filter, then notify all the + // subscribers if (filter.match(message)) { for (auto subscriber : observers.values(filter))