ctkServiceEvent.h 5.2 KB

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