ctkServiceRegistration.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 "ctkPluginContext.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. ~ctkServiceRegistration();
  40. /**
  41. * Returns a <code>ctkServiceReference</code> object for a service being
  42. * registered.
  43. * <p>
  44. * The <code>ctkServiceReference</code> object may be shared with other
  45. * plugins.
  46. *
  47. * @throws std::logic_error If this
  48. * <code>ctkServiceRegistration</code> object has already been
  49. * unregistered.
  50. * @return <code>ctkServiceReference</code> object.
  51. */
  52. ctkServiceReference getReference() const;
  53. /**
  54. * Updates the properties associated with a service.
  55. *
  56. * <p>
  57. * The {@link ctkPluginConstants#OBJECTCLASS} and {@link ctkPluginConstants#SERVICE_ID} keys
  58. * cannot be modified by this method. These values are set by the Framework
  59. * when the service is registered in the environment.
  60. *
  61. * <p>
  62. * The following steps are required to modify service properties:
  63. * <ol>
  64. * <li>The service's properties are replaced with the provided properties.
  65. * <li>A service event of type {@link ServiceEvent#MODIFIED} is fired.
  66. * </ol>
  67. *
  68. * @param properties The properties for this service. See {@link ctkPluginConstants}
  69. * for a list of standard service property keys. Changes should not
  70. * be made to this object after calling this method. To update the
  71. * service's properties this method should be called again.
  72. *
  73. * @throws std::logic_error If this <code>ctkServiceRegistration</code>
  74. * object has already been unregistered.
  75. * @throws std::invalid_argument If <code>properties</code> contains
  76. * case variants of the same key name.
  77. */
  78. void setProperties(const ServiceProperties& properties);
  79. /**
  80. * Unregisters a service. Remove a <code>ctkServiceRegistration</code> object
  81. * from the Framework service registry. All <code>ctkServiceReference</code>
  82. * objects associated with this <code>ctkServiceRegistration</code> object
  83. * can no longer be used to interact with the service once unregistration is
  84. * complete.
  85. *
  86. * <p>
  87. * The following steps are required to unregister a service:
  88. * <ol>
  89. * <li>The service is removed from the Framework service registry so that
  90. * it can no longer be obtained.
  91. * <li>A service event of type {@link ServiceEvent#UNREGISTERING} is fired
  92. * so that plugins using this service can release their use of the service.
  93. * Once delivery of the service event is complete, the
  94. * <code>ctkServiceReference</code> objects for the service may no longer be
  95. * used to get a service object for the service.
  96. * <li>For each plugin whose use count for this service is greater than
  97. * zero: <br>
  98. * The plugin's use count for this service is set to zero. <br>
  99. * If the service was registered with a {@link ctkServiceFactory} object, the
  100. * <code>ctkServiceFactory#ungetService</code> method is called to release
  101. * the service object for the plugin.
  102. * </ol>
  103. *
  104. * @throws std::logic_error If this
  105. * <code>ctkServiceRegistration</code> object has already been
  106. * unregistered.
  107. * @see BundleContext#ungetService
  108. * @see ctkServiceFactory#ungetService
  109. */
  110. virtual void unregister();
  111. bool operator<(const ctkServiceRegistration& o) const;
  112. protected:
  113. friend class ctkServices;
  114. ctkServiceRegistration(ctkPluginPrivate* plugin, QObject* service,
  115. const ServiceProperties& props);
  116. ctkServiceRegistration(ctkServiceRegistrationPrivate& dd);
  117. const QScopedPointer<ctkServiceRegistrationPrivate> d_ptr;
  118. };
  119. #endif // CTKSERVICEREGISTRATION_H