Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SkywardHub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
SkywardHub
Commits
9d431358
Commit
9d431358
authored
3 years ago
by
Riccardo Musso
Browse files
Options
Downloads
Patches
Plain Diff
Replaced Topics with TopicFilters
parent
e8264541
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Core/modulemessagesbroker.cpp
+11
-11
11 additions, 11 deletions
Core/modulemessagesbroker.cpp
Core/modulemessagesbroker.h
+5
-5
5 additions, 5 deletions
Core/modulemessagesbroker.h
with
16 additions
and
16 deletions
Core/modulemessagesbroker.cpp
+
11
−
11
View file @
9d431358
...
...
@@ -13,13 +13,13 @@ ModuleMessagesBroker::~ModuleMessagesBroker() {
}
void
ModuleMessagesBroker
::
subscribe
(
Topic
topic
,
Module
*
observer
,
std
::
function
<
void
(
const
ModuleMessage
&
msg
)
>
callBack
)
{
void
ModuleMessagesBroker
::
subscribe
(
Topic
Filter
topic
,
Module
*
observer
,
std
::
function
<
void
(
const
ModuleMessage
&
msg
)
>
callBack
)
{
CallbackCollection
&
collection
=
topic
.
isWildcard
()
?
wildcardObservers
:
exactObservers
;
collection
.
insert
(
topic
.
toString
(),
qMakePair
(
observer
,
callBack
));
connect
(
observer
->
getModuleEventsHandler
(),
&
ModuleEventsHandler
::
beforeDelete
,
this
,
&
ModuleMessagesBroker
::
onModuleDeleted
);
}
void
ModuleMessagesBroker
::
unsubscribe
(
Topic
topic
,
Module
*
module
)
{
void
ModuleMessagesBroker
::
unsubscribe
(
Topic
Filter
topic
,
Module
*
module
)
{
CallbackCollection
&
collection
=
topic
.
isWildcard
()
?
wildcardObservers
:
exactObservers
;
QList
<
QPair
<
Module
*
,
MessageCallback
>>
callbackList
=
collection
.
values
(
topic
.
toString
());
for
(
int
i
=
0
;
i
<
callbackList
.
size
();
)
{
...
...
@@ -42,7 +42,7 @@ void ModuleMessagesBroker::publish(const ModuleMessage& msg) {
}
for
(
auto
it
=
wildcardObservers
.
keyBegin
();
it
!=
wildcardObservers
.
keyEnd
();
++
it
)
{
if
(
msg
.
getTopic
()
.
match
(
*
it
))
{
if
(
TopicFilter
(
*
it
).
match
(
msg
.
getTopic
()))
{
auto
list
=
wildcardObservers
.
values
(
*
it
);
for
(
auto
&
item
:
list
)
{
item
.
second
(
msg
);
...
...
@@ -51,18 +51,18 @@ void ModuleMessagesBroker::publish(const ModuleMessage& msg) {
}
}
QList
<
Topic
>
ModuleMessagesBroker
::
getSubscriptionsOf
(
Module
*
module
)
{
QList
<
Topic
>
topics
;
QList
<
Topic
Filter
>
ModuleMessagesBroker
::
getSubscriptionsOf
(
Module
*
module
)
{
QList
<
Topic
Filter
>
topics
;
for
(
auto
it
=
wildcardObservers
.
keyValueBegin
();
it
!=
wildcardObservers
.
keyValueEnd
();
++
it
)
{
if
(
it
->
second
.
first
==
module
)
{
topics
.
append
(
Topic
(
it
->
first
));
topics
.
append
(
Topic
Filter
(
it
->
first
));
}
}
for
(
auto
it
=
exactObservers
.
keyValueBegin
();
it
!=
wildcardObservers
.
keyValueEnd
();
++
it
)
{
if
(
it
->
second
.
first
==
module
)
{
topics
.
append
(
Topic
(
it
->
first
));
topics
.
append
(
Topic
Filter
(
it
->
first
));
}
}
...
...
@@ -73,10 +73,10 @@ void ModuleMessagesBroker::onModuleDeleted(Module* module) {
// Deletion of modules happens so rarely that we can afford
// this "slow" way:
auto
listOf
Topic
s
=
getSubscriptionsOf
(
module
);
for
(
Topic
topic
:
listOf
Topic
s
)
{
CallbackCollection
&
collection
=
topic
.
isWildcard
()
?
wildcardObservers
:
exactObservers
;
auto
subList
=
collection
.
values
(
topic
.
toString
());
auto
listOf
Filter
s
=
getSubscriptionsOf
(
module
);
for
(
Topic
Filter
filter
:
listOf
Filter
s
)
{
CallbackCollection
&
collection
=
filter
.
isWildcard
()
?
wildcardObservers
:
exactObservers
;
auto
subList
=
collection
.
values
(
filter
.
toString
());
for
(
int
i
=
0
;
i
!=
subList
.
size
();
)
{
if
(
subList
[
i
].
first
==
module
)
{
subList
.
removeAt
(
i
);
...
...
This diff is collapsed.
Click to expand it.
Core/modulemessagesbroker.h
+
5
−
5
View file @
9d431358
...
...
@@ -7,7 +7,7 @@
#include
<QList>
#include
"Message/modulemessage.h"
#include
"Message/topic.h"
#include
"Message/topic
filter
.h"
class
Module
;
...
...
@@ -21,12 +21,12 @@ class ModuleMessagesBroker : public QObject {
ModuleMessagesBroker
();
~
ModuleMessagesBroker
();
void
subscribe
(
Topic
topic
,
Module
*
observer
,
MessageCallback
callBack
);
// unsubscribe remove ALL callbacks associated with (topic, module)
void
unsubscribe
(
Topic
topic
,
Module
*
module
);
void
subscribe
(
Topic
Filter
topic
,
Module
*
observer
,
MessageCallback
callBack
);
// unsubscribe remove ALL callbacks associated with (topic
Filter
, module)
void
unsubscribe
(
Topic
Filter
topic
,
Module
*
module
);
void
publish
(
const
ModuleMessage
&
msg
);
QList
<
Topic
>
getSubscriptionsOf
(
Module
*
module
);
QList
<
Topic
Filter
>
getSubscriptionsOf
(
Module
*
module
);
public
slots
:
void
onModuleDeleted
(
Module
*
module
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment