ctkServiceEvent.h 4.9 KB

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