ctkEventAdmin.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 CTKEVENTADMIN_H
  16. #define CTKEVENTADMIN_H
  17. #include "ctkEvent.h"
  18. /**
  19. * \ingroup EventAdmin
  20. *
  21. * The Event Admin service. Plugins wishing to publish events can either
  22. * obtain the Event Admin service and call one of the event delivery methods
  23. * or publish a Qt signal for a specific event topic.
  24. *
  25. */
  26. struct ctkEventAdmin
  27. {
  28. virtual ~ctkEventAdmin() {}
  29. /**
  30. * Initiate asynchronous, ordered delivery of an event. This method returns
  31. * to the caller before delivery of the event is completed. Events are
  32. * delivered in the order that they are received by this method.
  33. *
  34. * @param event The event to send to all listeners which subscribe to the
  35. * topic of the event.
  36. *
  37. */
  38. virtual void postEvent(const ctkEvent& event) = 0;
  39. /**
  40. * Initiate synchronous delivery of an event. This method does not return to
  41. * the caller until delivery of the event is completed.
  42. *
  43. * @param event The event to send to all listeners which subscribe to the
  44. * topic of the event.
  45. *
  46. */
  47. virtual void sendEvent(const ctkEvent& event) = 0;
  48. /**
  49. * Publish (register) a Qt signal for event delivery. Emitting the signal
  50. * has the same effect as calling postEvent() if <code>type</code> is
  51. * Qt::QueuedConnection and as sendEvent() if <code>type</code> is
  52. * Qt::DirectConnection.
  53. *
  54. * The signal will be associated with the given topic and must have the
  55. * following signature:
  56. * \code
  57. * someSignal(const ctkDictionary& props)
  58. * \endcode
  59. * where <code>props</code> will be used to construct a ctkEvent class which
  60. * will additionally have the EVENT_TOPIC property set to the given <code>topic</code>.
  61. *
  62. * This method can be called multiple times for the same signal to publish
  63. * it under multiple topics. In that case, emitting the signal will result in
  64. * multiple events being send.
  65. *
  66. * @param publisher The owner of the signal.
  67. * @param signal The signal in normalized form.
  68. * @param topic The event topic to use.
  69. * @param type Qt::QueuedConnection for asynchronous delivery and
  70. * Qt::DirectConnection for synchronous delivery.
  71. *
  72. * @see unpublishSignal()
  73. */
  74. virtual void publishSignal(const QObject* publisher, const char* signal,
  75. const QString& topic,
  76. Qt::ConnectionType type = Qt::QueuedConnection) = 0;
  77. /**
  78. * Unpublish (unregister) a previously published signal. After unpublishing a
  79. * signal, no events will be send when the signal is emitted.
  80. *
  81. * @param publisher The owner of the signal.
  82. * @param signal The signal in normalized form. If the signal is <code>NULL</code>
  83. * all signals from the given publisher published under the given
  84. * <code>topic</code> will be unpublished.
  85. * @param topic The event topic under which the given <code>signal</code> was
  86. * published. If the <code>topic</code> is empty, the signal is
  87. * unpublished for all topics it was previously pubished under.
  88. *
  89. * @see publishSlot()
  90. */
  91. virtual void unpublishSignal(const QObject* publisher, const char* signal = 0,
  92. const QString& topic = "") = 0;
  93. /**
  94. * Subsribe for (observe) events. The slot is called whenever an event is sent
  95. * which matches the topic string and LDAP search expression contained
  96. * in the properties.
  97. *
  98. * Slots should be registered with a property ctkEventConstants::EVENT_TOPIC.
  99. * The value being a QString or QStringList object that describes which
  100. * topics the slot is interested in. A wildcard (’*’ \\u002A) may be used as
  101. * the last token of a topic name, for example com/action&#47*. This matches any
  102. * topic that shares the same first tokens. For example, com/action&#47* matches
  103. * com/action/listen. Slots which have not been specified with the EVENT_TOPIC
  104. * property must not receive events.
  105. * The value of each entry in the EVENT_TOPIC property must conform to the
  106. * following grammar:
  107. * \verbatim
  108. * topic-scope ::= ’*’ | ( topic ’&#47*’ ? )
  109. * \endverbatim
  110. *
  111. * Slots can also be registered with a property named ctkEventConstants::EVENT_FILTER.
  112. * The value of this property must be a string containing a filter specification.
  113. * Any of the event's properties can be used in the filter expression.
  114. * Each slot is notified for any event which belongs to the topics the
  115. * slot has expressed an interest in. If the handler has defined a
  116. * EVENT_FILTER property then the event properties must also match the filter
  117. * expression. If the filter is an error, then the Event Admin service
  118. * should log a warning and further ignore the registered slot.
  119. *
  120. * @param subscriber The owner of the slot.
  121. * @param member The slot in normalized form.
  122. * @param properties A map containing topics and a filter expression.
  123. * @return Returns an id which can be used to update the properties.
  124. *
  125. * @see unsubscribeSlot(qlonglong)
  126. */
  127. virtual qlonglong subscribeSlot(const QObject* subscriber, const char* member, const ctkDictionary& properties) = 0;
  128. /**
  129. * Unsubscribe a previously subscribed slot. Use this method to allow the EventAdmin
  130. * implementation to clean up resources.
  131. *
  132. * @param subscriptionId The id obtained from a previous call to subscribeSlot()
  133. *
  134. * @see subscribeSlot()
  135. */
  136. virtual void unsubscribeSlot(qlonglong subscriptionId) = 0;
  137. /**
  138. * Updates the properties of a previously registered slot. This can be used
  139. * to change the topics the slot is interested in or to change the filter expression.
  140. * A previously registered property can be removed by providing an invalid QVariant.
  141. *
  142. * @param subscriptionId The slot id obtained by a call to subscribeSlot().
  143. * @param properties The properties which should be updated.
  144. * @return <code>true</code> if a slot was registered under this subscriptionId and its
  145. * properties where changed, <code>false</code> otherwise.
  146. */
  147. virtual bool updateProperties(qlonglong subscriptionId, const ctkDictionary& properties) = 0;
  148. };
  149. Q_DECLARE_INTERFACE(ctkEventAdmin, "org.commontk.service.event.EventAdmin")
  150. #endif // CTKEVENTADMIN_H