ctkServiceRegistration.h 5.9 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 CTKSERVICEREGISTRATION_H
  16. #define CTKSERVICEREGISTRATION_H
  17. #include "ctkDictionary.h"
  18. #include "ctkServiceReference.h"
  19. #include "ctkPluginFrameworkExport.h"
  20. class ctkServiceRegistrationPrivate;
  21. /**
  22. * A registered service.
  23. *
  24. * <p>
  25. * The Framework returns a <code>ctkServiceRegistration</code> object when a
  26. * <code>ctkPluginContext#registerService()</code> method invocation is successful.
  27. * The <code>ctkServiceRegistration</code> object is for the private use of the
  28. * registering plugin and should not be shared with other plugins.
  29. * <p>
  30. * The <code>ctkServiceRegistration</code> object may be used to update the
  31. * properties of the service or to unregister the service.
  32. *
  33. * @see ctkPluginContext#registerService()
  34. * @threadsafe
  35. */
  36. class CTK_PLUGINFW_EXPORT ctkServiceRegistration {
  37. Q_DECLARE_PRIVATE(ctkServiceRegistration)
  38. public:
  39. /**
  40. * Creates an invalid ctkServiceRegistration object. You can use
  41. * this object in boolean expressions and it will evaluate to
  42. * <code>false</code>.
  43. */
  44. ctkServiceRegistration();
  45. ctkServiceRegistration(const ctkServiceRegistration& reg);
  46. operator bool() const;
  47. /**
  48. * Releases any resources held or locked by this
  49. * <code>ctkServiceRegistration</code> and renders it invalid.
  50. */
  51. ctkServiceRegistration& operator=(int null);
  52. ~ctkServiceRegistration();
  53. /**
  54. * Returns a <code>ctkServiceReference</code> object for a service being
  55. * registered.
  56. * <p>
  57. * The <code>ctkServiceReference</code> object may be shared with other
  58. * plugins.
  59. *
  60. * @throws std::logic_error If this
  61. * <code>ctkServiceRegistration</code> object has already been
  62. * unregistered or if it is invalid.
  63. * @return <code>ctkServiceReference</code> object.
  64. */
  65. ctkServiceReference getReference() const;
  66. /**
  67. * Updates the properties associated with a service.
  68. *
  69. * <p>
  70. * The {@link ctkPluginConstants#OBJECTCLASS} and {@link ctkPluginConstants#SERVICE_ID} keys
  71. * cannot be modified by this method. These values are set by the Framework
  72. * when the service is registered in the environment.
  73. *
  74. * <p>
  75. * The following steps are required to modify service properties:
  76. * <ol>
  77. * <li>The service's properties are replaced with the provided properties.
  78. * <li>A service event of type {@link ServiceEvent#MODIFIED} is fired.
  79. * </ol>
  80. *
  81. * @param properties The properties for this service. See {@link ctkPluginConstants}
  82. * for a list of standard service property keys. Changes should not
  83. * be made to this object after calling this method. To update the
  84. * service's properties this method should be called again.
  85. *
  86. * @throws std::logic_error If this <code>ctkServiceRegistration</code>
  87. * object has already been unregistered or if it is invalid.
  88. * @throws std::invalid_argument If <code>properties</code> contains
  89. * case variants of the same key name.
  90. */
  91. void setProperties(const ctkDictionary& properties);
  92. /**
  93. * Unregisters a service. Remove a <code>ctkServiceRegistration</code> object
  94. * from the Framework service registry. All <code>ctkServiceReference</code>
  95. * objects associated with this <code>ctkServiceRegistration</code> object
  96. * can no longer be used to interact with the service once unregistration is
  97. * complete.
  98. *
  99. * <p>
  100. * The following steps are required to unregister a service:
  101. * <ol>
  102. * <li>The service is removed from the Framework service registry so that
  103. * it can no longer be obtained.
  104. * <li>A service event of type {@link ServiceEvent#UNREGISTERING} is fired
  105. * so that plugins using this service can release their use of the service.
  106. * Once delivery of the service event is complete, the
  107. * <code>ctkServiceReference</code> objects for the service may no longer be
  108. * used to get a service object for the service.
  109. * <li>For each plugin whose use count for this service is greater than
  110. * zero: <br>
  111. * The plugin's use count for this service is set to zero. <br>
  112. * If the service was registered with a {@link ctkServiceFactory} object, the
  113. * <code>ctkServiceFactory#ungetService</code> method is called to release
  114. * the service object for the plugin.
  115. * </ol>
  116. *
  117. * @throws std::logic_error If this
  118. * <code>ctkServiceRegistration</code> object has already been
  119. * unregistered or if it is invalid.
  120. * @see ctkPluginContext#ungetService
  121. * @see ctkServiceFactory#ungetService
  122. */
  123. virtual void unregister();
  124. bool operator<(const ctkServiceRegistration& o) const;
  125. bool operator==(const ctkServiceRegistration& registration) const;
  126. ctkServiceRegistration& operator=(const ctkServiceRegistration& registration);
  127. protected:
  128. friend class ctkServices;
  129. friend class ctkServiceReferencePrivate;
  130. friend uint CTK_PLUGINFW_EXPORT qHash(const ctkServiceRegistration&);
  131. ctkServiceRegistration(ctkServiceRegistrationPrivate* registrationPrivate);
  132. ctkServiceRegistration(ctkPluginPrivate* plugin, QObject* service,
  133. const ctkDictionary& props);
  134. ctkServiceRegistrationPrivate* d_ptr;
  135. };
  136. uint CTK_PLUGINFW_EXPORT qHash(const ctkServiceRegistration& serviceRef);
  137. #endif // CTKSERVICEREGISTRATION_H