ctkEventHandler.h 2.8 KB

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