ctkServiceReference.h 7.1 KB

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