ctkEventHandler.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 CTKEVENTHANDLER_H
  16. #define CTKEVENTHANDLER_H
  17. #include "ctkEvent.h"
  18. /**
  19. * \ingroup EventAdmin
  20. *
  21. * Listener for Events.
  22. *
  23. * <p>
  24. * <code>ctkEventHandler</code> objects are registered with the Framework service
  25. * registry and are notified with an <code>ctkEvent</code> object when an event
  26. * is sent or posted.
  27. * <p>
  28. * <code>ctkEventHandler</code> objects can inspect the received
  29. * <code>ctkEvent</code> object to determine its topic and properties.
  30. *
  31. * <p>
  32. * <code>ctkEventHandler</code> objects must be registered with a service
  33. * property {@link ctkEventConstants#EVENT_TOPIC} whose value is the list of topics
  34. * in which the event handler is interested.
  35. * <p>
  36. * For example:
  37. *
  38. * \code
  39. * QStringList topics("com/isv/&#42;");
  40. * ctkDictionary props;
  41. * props.insert(ctkEventConstants::EVENT_TOPIC, topics);
  42. * context->registerService<ctkEventHandler>(this, props);
  43. * \endcode
  44. *
  45. * Event Handler services can also be registered with an
  46. * {@link ctkEventConstants#EVENT_FILTER} service property to further filter the
  47. * events. If the syntax of this filter is invalid, then the Event Handler must
  48. * be ignored by the Event Admin service. The Event Admin service should log a
  49. * warning.
  50. * <p>
  51. * Security Considerations. Plugins wishing to monitor <code>ctkEvent</code>
  52. * objects will require <code>ctkServicePermission[ctkEventHandler,REGISTER]</code>
  53. * to register a <code>ctkEventHandler</code> service. The plugin must also have
  54. * <code>ctkTopicPermission[topic,SUBSCRIBE]</code> for the topic specified in
  55. * the event in order to receive the event.
  56. *
  57. * @see ctkEvent
  58. *
  59. * @ThreadSafe
  60. * @version $Id: 2b8202d10e77b774897c74714115059f46abc7e1 $
  61. */
  62. struct ctkEventHandler
  63. {
  64. virtual ~ctkEventHandler() {}
  65. /**
  66. * Called by the {@link ctkEventAdmin} service to notify the listener of an
  67. * event.
  68. *
  69. * @param event The event that occurred.
  70. */
  71. virtual void handleEvent(const ctkEvent& event) = 0;
  72. };
  73. Q_DECLARE_INTERFACE(ctkEventHandler, "org.commontk.service.event.EventHandler")
  74. #endif // CTKEVENTHANDLER_H