ctkServiceEvent.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 CTKSERVICEEVENT_H
  16. #define CTKSERVICEEVENT_H
  17. #include <QSharedDataPointer>
  18. #include <QDebug>
  19. #include "ctkPluginFrameworkExport.h"
  20. #include "ctkServiceReference.h"
  21. class ctkServiceEventData;
  22. /**
  23. * An event from the Plugin Framework describing a service lifecycle change.
  24. * <p>
  25. * <code>ctkServiceEvent</code> objects are delivered to
  26. * slots connected via ctkPluginContext::connectServiceListener() when a
  27. * change occurs in this service's lifecycle. A type code is used to identify
  28. * the event type for future extendability.
  29. */
  30. class CTK_PLUGINFW_EXPORT ctkServiceEvent
  31. {
  32. QSharedDataPointer<ctkServiceEventData> d;
  33. public:
  34. enum Type {
  35. /**
  36. * This service has been registered.
  37. * <p>
  38. * This event is synchronously delivered <strong>after</strong> the service
  39. * has been registered with the Framework.
  40. *
  41. * @see ctkPluginContext#registerService()
  42. */
  43. REGISTERED = 0x00000001,
  44. /**
  45. * The properties of a registered service have been modified.
  46. * <p>
  47. * This event is synchronously delivered <strong>after</strong> the service
  48. * properties have been modified.
  49. *
  50. * @see ctkServiceRegistration#setProperties
  51. */
  52. MODIFIED = 0x00000002,
  53. /**
  54. * This service is in the process of being unregistered.
  55. * <p>
  56. * This event is synchronously delivered <strong>before</strong> the service
  57. * has completed unregistering.
  58. *
  59. * <p>
  60. * If a plugin is using a service that is <code>UNREGISTERING</code>, the
  61. * plugin should release its use of the service when it receives this event.
  62. * If the plugin does not release its use of the service when it receives
  63. * this event, the Framework will automatically release the plugin's use of
  64. * the service while completing the service unregistration operation.
  65. *
  66. * @see ctkServiceRegistration#unregister
  67. * @see ctkPluginContext#ungetService
  68. */
  69. UNREGISTERING = 0x00000004,
  70. /**
  71. * The properties of a registered service have been modified and the new
  72. * properties no longer match the listener's filter.
  73. * <p>
  74. * This event is synchronously delivered <strong>after</strong> the service
  75. * properties have been modified. This event is only delivered to slots
  76. * which were added with a non-<code>null</code> filter where the filter
  77. * matched the service properties prior to the modification but the filter
  78. * does not match the modified service properties.
  79. *
  80. * @see ctkServiceRegistration#setProperties
  81. */
  82. MODIFIED_ENDMATCH = 0x00000008
  83. };
  84. /**
  85. * Default constructor for use with the Qt meta object system.
  86. */
  87. ctkServiceEvent();
  88. ~ctkServiceEvent();
  89. /**
  90. * Can be used to check if this ctkServiceEvent instance is valid,
  91. * or if it has been constructed using the default constructor.
  92. *
  93. * @return <code>true</code> if this event object is valid,
  94. * <code>false</code> otherwise.
  95. */
  96. bool isNull() const;
  97. /**
  98. * Creates a new service event object.
  99. *
  100. * @param type The event type.
  101. * @param reference A <code>ServiceReference</code> object to the service
  102. * that had a lifecycle change.
  103. */
  104. ctkServiceEvent(Type type, const ctkServiceReference& plugin);
  105. ctkServiceEvent(const ctkServiceEvent& other);
  106. ctkServiceEvent& operator=(const ctkServiceEvent& other);
  107. /**
  108. * Returns a reference to the service that had a change occur in its
  109. * lifecycle.
  110. * <p>
  111. * This reference is the source of the event.
  112. *
  113. * @return Reference to the service that had a lifecycle change.
  114. */
  115. ctkServiceReference getServiceReference() const;
  116. /**
  117. * Returns the type of event. The event type values are:
  118. * <ul>
  119. * <li>{@link #REGISTERED} </li>
  120. * <li>{@link #MODIFIED} </li>
  121. * <li>{@link #MODIFIED_ENDMATCH} </li>
  122. * <li>{@link #UNREGISTERING} </li>
  123. * </ul>
  124. *
  125. * @return Type of service lifecycle change.
  126. */
  127. Type getType() const;
  128. };
  129. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug dbg, ctkServiceEvent::Type type);
  130. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug dbg, const ctkServiceEvent& event);
  131. #endif // CTKSERVICEEVENT_H