ctkEventBus.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKEVENTBUS_H
  16. #define CTKEVENTBUS_H
  17. #include "ctkEvent.h"
  18. /**
  19. * The Event Bus service. Plugins wishing to publish events can either
  20. * obtain the Event Bus service and call one of the event delivery methods
  21. * or publish a Qt signal for a specific event topic.
  22. *
  23. */
  24. class ctkEventBus {
  25. public:
  26. virtual ~ctkEventBus() {}
  27. /**
  28. * Initiate asynchronous delivery of an event. This method returns to the
  29. * caller before delivery of the event is completed.
  30. *
  31. * @param event The event to send to all listeners which subscribe to the
  32. * topic of the event.
  33. *
  34. */
  35. virtual void postEvent(const ctkEvent& event) = 0;
  36. /**
  37. * Initiate synchronous delivery of an event. This method does not return to
  38. * the caller until delivery of the event is completed.
  39. *
  40. * @param event The event to send to all listeners which subscribe to the
  41. * topic of the event.
  42. *
  43. */
  44. virtual void sendEvent(const ctkEvent& event) = 0;
  45. /**
  46. * Publish (register) a Qt signal for event delivery. Emitting the signal
  47. * has the same effect as calling postEvent() if <code>type</code> is
  48. * Qt::QueuedConnection and as sendEvent() if <code>type</code> is
  49. * Qt::DirectConnection.
  50. *
  51. * @param publisher The owner of the signal.
  52. * @param signal The signal in normalized form.
  53. * @param signal_topic The topic string for the events this signal is emitting.
  54. * @param type Qt::QueuedConnection for asynchronous delivery and
  55. * Qt::DirectConnection for synchronous delivery.
  56. */
  57. virtual void publishSignal(const QObject* publisher, const char* signal,
  58. const QString& signal_topic, Qt::ConnectionType type = Qt::QueuedConnection) = 0;
  59. /**
  60. * Subsribe for (observe) events. The slot is called whenever an event is sent
  61. * which matches the topic string and LDAP search expression contained
  62. * in the properties.
  63. *
  64. * Slots should be registered with a property EventConstants::EVENT_TOPIC.
  65. * The value being a QString or QStringList object that describes which
  66. * topics the slot is interested in. A wildcard (’*’ \u002A) may be used as
  67. * the last token of a topic name, for example com/action&#47*. This matches any
  68. * topic that shares the same first tokens. For example, com/action&#47* matches
  69. * com/action/listen. Slot which have not been specified with the EVENT_TOPIC
  70. * property must not receive events.
  71. * The value of each entry in the EVENT_TOPIC property must conform to the
  72. * following grammar:
  73. * \verbatim
  74. * topic-scope ::= ’*’ | ( topic ’&#47*’ ? )
  75. * \endverbatim
  76. *
  77. * Slots can also be registered with a property named EventConstants::EVENT_FILTER.
  78. * The value of this property must be a string containing a filter specification.
  79. * Any of the event's properties can be used in the filter expression.
  80. * Each slot is notified for any event which belongs to the topics the
  81. * slot has expressed an interest in. If the handler has defined a
  82. * EVENT_FILTER property then the event properties must also match the filter
  83. * expression. If the filter is an error, then the Event Bus service
  84. * should log a warning and further ignore the registered slot.
  85. *
  86. * @param subscriber The owner of the slot.
  87. * @param member The slot in normalized form.
  88. * @param properties A map containing topics and a filter expression.
  89. * @return Returns an id which can be used to update the properties.
  90. */
  91. virtual QString subscribeSlot(const QObject* subscriber, const char* member, const ctkProperties& properties) = 0;
  92. /**
  93. * Updates the properties of a previously registered slot. This can be used
  94. * to change the topics the slot is interested in or to change the filter expression.
  95. * A previously registered property can be removed by providing an invalid QVariant.
  96. *
  97. * @param subscriptionId The slot id obtained by a call to subscribeSlot().
  98. * @param properties The properties which should be updated.
  99. */
  100. virtual void updateProperties(const QString& subsriptionId, const ctkProperties& properties) = 0;
  101. };
  102. Q_DECLARE_INTERFACE(ctkEventBus, "org.commontk.core.ctkEventBus")
  103. #endif // CTKEVENTBUS_H