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