ctkServiceRegistration.h 6.0 KB

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