ctkServiceEvent.h 5.2 KB

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