ctkServiceReference.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 CTKSERVICEREFERENCE_H
  16. #define CTKSERVICEREFERENCE_H
  17. #include <QVariant>
  18. #include "ctkPlugin.h"
  19. #include "ctkPluginFrameworkExport.h"
  20. class ctkServiceRegistrationPrivate;
  21. class ctkServiceReferencePrivate;
  22. class ctkServiceEvent;
  23. template<class Item, class Related> class ctkPluginAbstractTracked;
  24. /**
  25. * A reference to a service.
  26. *
  27. * <p>
  28. * The Framework returns <code>ctkServiceReference</code> objects from the
  29. * <code>ctkPluginContext::getServiceReference</code> and
  30. * <code>ctkPluginContext::getServiceReferences</code> methods.
  31. * <p>
  32. * A <code>ctkServiceReference</code> object may be shared between plugins and
  33. * can be used to examine the properties of the service and to get the service
  34. * object.
  35. * <p>
  36. * Every service registered in the Framework has a unique
  37. * <code>ctkServiceRegistration</code> object and may have multiple, distinct
  38. * <code>ctkServiceReference</code> objects referring to it.
  39. * <code>ctkServiceReference</code> objects associated with a
  40. * <code>ctkServiceRegistration</code> are considered equal
  41. * (more specifically, their <code>operator==()</code>
  42. * method will return <code>true</code> when compared).
  43. * <p>
  44. * If the same service object is registered multiple times,
  45. * <code>ctkServiceReference</code> objects associated with different
  46. * <code>ctkServiceRegistration</code> objects are not equal.
  47. *
  48. * @see ctkPluginContext::getServiceReference
  49. * @see ctkPluginContext::getServiceReferences
  50. * @see ctkPluginContext::getService
  51. * @threadsafe
  52. */
  53. class CTK_PLUGINFW_EXPORT ctkServiceReference {
  54. Q_DECLARE_PRIVATE(ctkServiceReference)
  55. public:
  56. ctkServiceReference(const ctkServiceReference& ref);
  57. ~ctkServiceReference();
  58. /**
  59. * Returns the property value to which the specified property key is mapped
  60. * in the properties <code>ServiceProperties</code> object of the service
  61. * referenced by this <code>ctkServiceReference</code> object.
  62. *
  63. * <p>
  64. * Property keys are case-insensitive.
  65. *
  66. * <p>
  67. * This method must continue to return property values after the service has
  68. * been unregistered. This is so references to unregistered services can
  69. * still be interrogated.
  70. *
  71. * @param key The property key.
  72. * @return The property value to which the key is mapped; an invalid QVariant
  73. * if there is no property named after the key.
  74. */
  75. QVariant getProperty(const QString& key) const;
  76. /**
  77. * Returns a list of the keys in the <code>ServiceProperties</code>
  78. * object of the service referenced by this <code>ctkServiceReference</code>
  79. * object.
  80. *
  81. * <p>
  82. * This method will continue to return the keys after the service has been
  83. * unregistered. This is so references to unregistered services can
  84. * still be interrogated.
  85. *
  86. * <p>
  87. * This method is not <i>case-preserving</i>; this means that every key in the
  88. * returned array is in lower case, which may not be the case for the corresponding key in the
  89. * properties <code>ServiceProperties</code> that was passed to the
  90. * {@link ctkPluginContext::registerService(const QStringList&, QObject*, const ServiceProperties&)} or
  91. * {@link ctkServiceRegistration::setProperties} methods.
  92. *
  93. * @return A list of property keys.
  94. */
  95. QStringList getPropertyKeys() const;
  96. /**
  97. * Returns the plugin that registered the service referenced by this
  98. * <code>ctkServiceReference</code> object.
  99. *
  100. * <p>
  101. * This method must return <code>0</code> when the service has been
  102. * unregistered. This can be used to determine if the service has been
  103. * unregistered.
  104. *
  105. * @return The plugin that registered the service referenced by this
  106. * <code>ctkServiceReference</code> object; <code>0</code> if that
  107. * service has already been unregistered.
  108. * @see ctkPluginContext::registerService(const QStringList&, QObject* , const ServiceProperties&)
  109. */
  110. ctkPlugin* getPlugin() const;
  111. /**
  112. * Returns the plugins that are using the service referenced by this
  113. * <code>ctkServiceReference</code> object. Specifically, this method returns
  114. * the plugins whose usage count for that service is greater than zero.
  115. *
  116. * @return A list of plugins whose usage count for the service referenced
  117. * by this <code>ctkServiceReference</code> object is greater than
  118. * zero.
  119. */
  120. QList<ctkPlugin*> getUsingPlugins() const;
  121. /**
  122. * Compares this <code>ctkServiceReference</code> with the specified
  123. * <code>ctkServiceReference</code> for order.
  124. *
  125. * <p>
  126. * If this <code>ctkServiceReference</code> and the specified
  127. * <code>ctkServiceReference</code> have the same {@link ctkPluginConstants::SERVICE_ID
  128. * service id} they are equal. This <code>ctkServiceReference</code> is less
  129. * than the specified <code>ctkServiceReference</code> if it has a lower
  130. * {@link ctkPluginConstants::SERVICE_RANKING service ranking} and greater if it has a
  131. * higher service ranking. Otherwise, if this <code>ctkServiceReference</code>
  132. * and the specified <code>ctkServiceReference</code> have the same
  133. * {@link ctkPluginConstants::SERVICE_RANKING service ranking}, this
  134. * <code>ctkServiceReference</code> is less than the specified
  135. * <code>ctkServiceReference</code> if it has a higher
  136. * {@link ctkPluginConstants::SERVICE_ID service id} and greater if it has a lower
  137. * service id.
  138. *
  139. * @param reference The <code>ctkServiceReference</code> to be compared.
  140. * @return Returns a false or true if this
  141. * <code>ctkServiceReference</code> is less than or greater
  142. * than the specified <code>ctkServiceReference</code>.
  143. * @throws std::invalid_argument If the specified
  144. * <code>ctkServiceReference</code> was not created by the same
  145. * framework instance as this <code>ctkServiceReference</code>.
  146. */
  147. bool operator<(const ctkServiceReference& reference) const;
  148. bool operator==(const ctkServiceReference& reference) const;
  149. ctkServiceReference& operator=(const ctkServiceReference& reference);
  150. protected:
  151. friend class ctkLDAPSearchFilter;
  152. friend class ctkServiceRegistrationPrivate;
  153. friend class ctkPluginContext;
  154. friend class ctkPluginPrivate;
  155. friend class ctkPluginFrameworkListeners;
  156. friend class ctkServiceTrackerPrivate;
  157. friend class ctkServiceTracker;
  158. friend class ctkPluginAbstractTracked<ctkServiceReference, ctkServiceEvent>;
  159. ctkServiceReference(ctkServiceRegistrationPrivate* reg);
  160. bool isNull() const;
  161. ctkServiceReferencePrivate * d_ptr;
  162. };
  163. uint CTK_PLUGINFW_EXPORT qHash(const ctkServiceReference& serviceRef);
  164. QDebug CTK_PLUGINFW_EXPORT operator<<(QDebug dbg, const ctkServiceReference& serviceRef);
  165. #endif // CTKSERVICEREFERENCE_H