The document discusses event dispatching in MAF v3. It describes how an event bus allows for modular communication and independence between modules. Events can be dispatched locally or remotely. Modules register signals and callbacks with the event bus by topic. The event bus uses a publish-subscribe model to deliver events to subscribed modules. It extends Qt's signal/slot mechanism to allow runtime connections. Remote events are dispatched via a network connector using protocols like XMLRPC.
2. Summary
Why creating an event bus?
Event Bus inside MAF3 Architecture
Characteristics
How register a signal and a callback
Local vs Remote Dispatching.
2
3. Event Bus - Reasons
Communication between modules
Independency between modules
Need of flexibility
3
5. Communication
There are several types of communication:
Publish-Subscribe: Modules may subscribe to certain
message types. Whenever a module publishes a message
to the bus, it will be delivered to all modules that
subscribed to its message type.
Broadcast: The message will be delivered to all (other)
modules.
Point-to-point: The message has one and only one
recipient.
5
6. Examples of Event Bus
Enterprise Service Bus:
6
D-Bus
Mbus
http://www.mbus.org/
8. Characteristics
mafEventBus is based on Signal/Slot connecting
mechanism implemented in Qt.
Extends the Qt mechanism to allow connection also at
run-time without to include the class that define the signal
with which the connection has to be established.
Can manage local to the application or remote events
through mafEventDispatcher exchanging event
information written into the mafEvent token.
Remote connection can be managed with different
extensible protocols through mafNetworkConnector.
Event filtering by topic.
Independent from mafCore.
9. Patterns involved
Façade
The class mafEventBusManager allows to access all
the functionalities of event emit and observe
registration/notification.
Observer
An event must be registered with its Topic as
signal or callback without a specific order.
A topic represents an unique string associated with
one signal.
11. How it works (Basic)
Register in the Bus any Signal Emitter.
Register in the Bus any Callback associating it
to a particular Topic to observe.
Notify through the Bus an event (local or
remote) to update all the observers (with or
without arguments and return values)
Only QObjects (or inherited class) can be a
signal emitter or observer due to the
signal/slot mechanism used into the bus.
13. How It Works (Remote side)
Remote notification are achieved by asking the
bus module to create a client for the given
remote communication protocol: “XMLRPC”,
“SOAP”…
Network protocols are extensible through the
plug of new mafNetworkConnector into the
mafEventBusManager:
plugNetworkConnector("SOAP", new mafNetworkConnectorQtSoap());
All these steps are accessible through the
mafEventBusManager façade class.
14. mafEvent
Class for storing information into a QHash.
Into the hash stores keys and values related to the
event to be notified.
Define some API to simplify the access of the event
information stored into the hash.
15. Signal Emitter
Register as a signal emitter:
Create a Qt Signal inside the class header used as a
signal emitter.
Define a string topic to associate to a signal.
Register to the Event Bus as emitter using the
mafRegisterLocalSignal or
mafRegisterRemoteSignal macros or giving to the
mafEventBusManager (through the call of
addEventProperty method) the mafEvent filled with
proper information.
16. Register as Signal Emitter
In your .h file define the signal:
...
signals:
void loadPluginLibrary(const mafString &pluginFilename);
...
… then in .cpp create the topic and register the
signal into the Event Bus:
mafString load_library_topic =
“maf.local.resources.pluginManager.loadPlugin”;
mafRegisterLocalSignal(load_library_topic, this,
"loadPluginLibrary(const mafString &)");
17. Observer
Register as Observer:
Define a Qt slot into the class that wants to become an
observer.
Register that slot in the bus associating it with a Signal
through the predefined topic through the macro
mafRegisterLocalCallback or giving to the
mafEventBusManager (through the call of
addEventProperty method) the mafEvent filled with
proper information.
18. Register as Observer
In your .h file define the slot:
public slots:
/// Loads a plugin
void loadPlugin(const mafString &pluginFilename);
… then in .cpp register it into the Event Bus:
mafRegisterLocalCallback(“maf.local.resources.pluginManager.loadPlugi
n”, this, "loadPlugin(const mafString &)");
19. Notify an Event
Event Notification can be done in three different way:
No Arguments and No Return Value
With Arguments and No Return Value
With Arguments and With Return Value
20. Notification with
No Argument and No return value
Get the mafEventBusManager instance:
mafEventBusManager *m_EventBus = mafEventBusManager::instance();
Send the notification for a given topic:
m_EventBus->notifyEvent("maf.local.eventBus.globalUpdate");
21. Notification with
Arguments and No Return Value
Create the list of arguments to send through the
notification:
mafEventArgumentsList arglist;
mafEventGenericArgument value = mafEventArgument(int, 35)
arglist.append(value);
Notify the event associated to the topic:
m_EventBus->notifyEvent("maf.local.myTopic", mafEventTypeLocal,
&arglist);
22. Notification with
Arguments and Return Value
Create the list of argument (as before)
Create the placeholder for the Return Value
(here is show an ‘int’ return value):
mafEventArgumentsList arglist;
mafEventGenericArgument value = mafEventArgument(int, 35)
arglist.append(value);
int returnValue = 0;
Notify the event associated to the topic. The
return value will be present into the variable
after the call:
mafGenericReturnArgument ret_val =
mafEventReturnArgument(int,returnValue);
m_EventBus->notifyEvent("maf.local.myTopic", mafEventTypeLocal,
&arglist, &ret_val);
23. Remote Notification
Same as the three cases shown in the slides before,
but instead of mafEventTypeLocal, use
mafEventTypeRemote.
mafEventDispatcherRemote will be in charge of
dispatching those events through the
mafNetworkConnector.
25. Remote Event Pack
The local call needs the flag mafEventTypeRemote
and a list of parameters containing:
information on the topic to be called by the remote
application on its Event Bus (called remote event
parameters)
related optional parameters (called remote data
parameters)
26. Remote Event Unpack
Remote application receive the list of parameters (Event
and Data Parameters).
Extract from the Event Parameter the ID to be called
locally.
Extract the Data Parameters to build the local Arguments
list for the new event.
Return to the caller application the connection result: Fail
or Ok which will cause the notification of the two related
events:
maf.local.eventBus.remoteCommunicationFailed
and
maf.local.eventBus.remoteCommunicationDone