Event dispatching in MAF v3
Summary
Why creating an event bus?
Event Bus inside MAF3 Architecture
Characteristics
How register a signal and a call...
Event Bus - Reasons
Communication between modules
Independency between modules
Need of flexibility
3
MAF3 Architecture
4
Communication
There are several types of communication:
Publish-Subscribe: Modules may subscribe to certain
message type...
Examples of Event Bus
Enterprise Service Bus:
6
D-Bus
Mbus
http://www.mbus.org/
Signal/Slot
7
Characteristics
mafEventBus is based on Signal/Slot connecting
mechanism implemented in Qt.
Extends the Qt mechanism to ...
Patterns involved
Façade
The class mafEventBusManager allows to access all
the functionalities of event emit and observe...
Event Topic Taxonomy
1023
maf.local.resources.viewManager.create
Reverse DNS notation:
How it works (Basic)
Register in the Bus any Signal Emitter.
Register in the Bus any Callback associating it
to a partic...
Register
Signal
Attach the
Observer/s
Notify
Events
How It Works (Remote side)
Remote notification are achieved by asking the
bus module to create a client for the given
rem...
mafEvent
Class for storing information into a QHash.
Into the hash stores keys and values related to the
event to be not...
Signal Emitter
Register as a signal emitter:
Create a Qt Signal inside the class header used as a
signal emitter.
Defin...
Register as Signal Emitter
In your .h file define the signal:
...
signals:
void loadPluginLibrary(const mafString &plugin...
Observer
Register as Observer:
Define a Qt slot into the class that wants to become an
observer.
Register that slot in ...
Register as Observer
In your .h file define the slot:
public slots:
/// Loads a plugin
void loadPlugin(const mafString &p...
Notify an Event
Event Notification can be done in three different way:
No Arguments and No Return Value
With Arguments ...
Notification with
No Argument and No return value
Get the mafEventBusManager instance:
mafEventBusManager *m_EventBus = m...
Notification with
Arguments and No Return Value
Create the list of arguments to send through the
notification:
mafEventAr...
Notification with
Arguments and Return Value
Create the list of argument (as before)
Create the placeholder for the Retu...
Remote Notification
Same as the three cases shown in the slides before,
but instead of mafEventTypeLocal, use
mafEventTyp...
Remote Notification
Remote Event Pack
The local call needs the flag mafEventTypeRemote
and a list of parameters containing:
information on t...
Remote Event Unpack
Remote application receive the list of parameters (Event
and Data Parameters).
Extract from the Even...
References
MAF http://www.openmaf.org
Qt http://qt.nokia.com
Design Pattern http://sourcemaking.com/design_patterns
Thank You
Authors
Paolo Quadrani: p.quadrani@scsolutions.it
Daniele Giunchi: d.giunchi@scsolutions.it
Roberto Mucci: r.muc...
Upcoming SlideShare
Loading in...5
×

Maf Event Bus

1,210

Published on

MAF3 Framework (Part 2)
The cross-platform MAF Event Bus make use of Qt Signal/Slot to dispatch events between objects locally and remotely. Qt mechanism has been extended to manage also a remote communication transparently to the EventBus user and decouple the sender from the receiver allowing sending events remotely using different network connectors expandable through the strategy pattern.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,210
On Slideshare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Maf Event Bus

  1. 1. Event dispatching in MAF v3
  2. 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. 3. Event Bus - Reasons Communication between modules Independency between modules Need of flexibility 3
  4. 4. MAF3 Architecture 4
  5. 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. 6. Examples of Event Bus Enterprise Service Bus: 6 D-Bus Mbus http://www.mbus.org/
  7. 7. Signal/Slot 7
  8. 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. 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.
  10. 10. Event Topic Taxonomy 1023 maf.local.resources.viewManager.create Reverse DNS notation:
  11. 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.
  12. 12. Register Signal Attach the Observer/s Notify Events
  13. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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.
  24. 24. Remote Notification
  25. 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. 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
  27. 27. References MAF http://www.openmaf.org Qt http://qt.nokia.com Design Pattern http://sourcemaking.com/design_patterns
  28. 28. Thank You Authors Paolo Quadrani: p.quadrani@scsolutions.it Daniele Giunchi: d.giunchi@scsolutions.it Roberto Mucci: r.mucci@cineca.it

×