ctkEventBus.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef CTKEVENTBUS_H
  2. #define CTKEVENTBUS_H
  3. #include "ctkEvent.h"
  4. /**
  5. * The Event Bus service. Plugins wishing to publish events can either
  6. * obtain the Event Bus service and call one of the event delivery methods
  7. * or publish a Qt signal for a specific event topic.
  8. *
  9. */
  10. class CTK_PLUGINFW_EXPORT ctkEventBus {
  11. public:
  12. virtual ~ctkEventBus() {}
  13. /**
  14. * Initiate asynchronous delivery of an event. This method returns to the
  15. * caller before delivery of the event is completed.
  16. *
  17. * @param event The event to send to all listeners which subscribe to the
  18. * topic of the event.
  19. *
  20. */
  21. virtual void postEvent(const ctkEvent& event) = 0;
  22. /**
  23. * Initiate synchronous delivery of an event. This method does not return to
  24. * the caller until delivery of the event is completed.
  25. *
  26. * @param event The event to send to all listeners which subscribe to the
  27. * topic of the event.
  28. *
  29. */
  30. virtual void sendEvent(const ctkEvent& event) = 0;
  31. /**
  32. * Publish (register) a Qt signal for event delivery. Emitting the signal
  33. * has the same effect as calling postEvent() if <code>type</code> is
  34. * Qt::QueuedConnection and as sendEvent() if <code>type</code> is
  35. * Qt::DirectConnection.
  36. *
  37. * @param publisher The owner of the signal.
  38. * @param signal The signal in normalized form.
  39. * @param signal_topic The topic string for the events this signal is emitting.
  40. * @param type Qt::QueuedConnection for asynchronous delivery and
  41. * Qt::DirectConnection for synchronous delivery.
  42. */
  43. virtual void publishSignal(const QObject* publisher, const char* signal,
  44. const QString& signal_topic, Qt::ConnectionType type = Qt::QueuedConnection) = 0;
  45. /**
  46. * Subsribe for (observe) events. The slot is called whenever an event is sent
  47. * which matches the supplied properties.
  48. *
  49. * Slots should be registered with a property EventConstants::EVENT_TOPIC.
  50. * The value being a QString or QStringList object that describes which
  51. * topics the slot is interested in. A wildcard (’*’ \u002A) may be used as
  52. * the last token of a topic name, for example com/action/*. This matches any
  53. * topic that shares the same first tokens. For example, com/action/* matches
  54. * com/action/listen. Slot which have not been specified with the EVENT_TOPIC
  55. * property must not receive events.
  56. * The value of each entry in the EVENT_TOPIC property must conform to the
  57. * following grammar:
  58. * \verbatim
  59. * topic-scope ::= ’*’ | ( topic ’/*’ ? )
  60. * \endverbatim
  61. *
  62. * Slots can also be registered with a property named EventConstants::EVENT_FILTER.
  63. * The value of this property must be a string containing a filter specification.
  64. * Any of the event's properties can be used in the filter expression.
  65. * Each slot is notified for any event which belongs to the topics the
  66. * slot has expressed an interest in. If the handler has defined a
  67. * EVENT_FILTER property then the event properties must also match the filter
  68. * expression. If the filter is an error, then the Event Bus service
  69. * should log a warning and further ignore the registered slot.
  70. *
  71. * @param subscriber The owner of the slot.
  72. * @param member The slot in normalized form.
  73. * @param properties A map containing topics and a filter expression.
  74. * @return Returns an id which can be used to update the properties.
  75. */
  76. virtual QString subscribeSlot(const QObject* subscriber, const char* member, const ctkProperties& properties) = 0;
  77. /**
  78. * Updates the properties of a previously registered slot. This can be used
  79. * to change the topics the slot is interested in or to change the filter expression.
  80. * A previously registered property can be removed by providing an invalid QVariant.
  81. *
  82. * @param subscriptionId The slot id obtained by a call to subscribeSlot().
  83. * @param properties The properties which should be updated.
  84. */
  85. virtual void updateProperties(const QString& subsriptionId, const ctkProperties& properties) = 0;
  86. };
  87. Q_DECLARE_INTERFACE(ctkEventBus, "org.commontk.core.ctkEventBus")
  88. #endif // CTKEVENTBUS_H