ctkServiceFactory.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #include "ctkServiceRegistration.h"
  16. /**
  17. * \ingroup PluginFramework
  18. *
  19. * Allows services to provide customized service objects in the plugin
  20. * environment.
  21. *
  22. * <p>
  23. * When registering a service, a <code>ctkServiceFactory</code> object can be
  24. * used instead of a service object, so that the plugin developer can gain
  25. * control of the specific service object granted to a plugin that is using the
  26. * service.
  27. *
  28. * <p>
  29. * When this happens, the
  30. * <code>ctkPluginContext::getService(const ctkServiceReference&)</code> method calls the
  31. * <code>ctkServiceFactory::getService</code> method to create a service object
  32. * specifically for the requesting plugin. The service object returned by the
  33. * <code>ctkServiceFactory</code> is cached by the Framework until the plugin
  34. * releases its use of the service.
  35. *
  36. * <p>
  37. * When the plugin's use count for the service equals zero (including the plugin
  38. * stopping or the service being unregistered), the
  39. * <code>ctkServiceFactory::ungetService</code> method is called.
  40. *
  41. * <p>
  42. * <code>ctkServiceFactory</code> objects are only used by the Framework and are
  43. * not made available to other plugins in the plugin environment. The Framework
  44. * may concurrently call a <code>ctkServiceFactory</code>.
  45. *
  46. * @see ctkPluginContext#getService
  47. * @remarks This class is thread safe.
  48. */
  49. class ctkServiceFactory
  50. {
  51. public:
  52. /**
  53. * Creates a new service object.
  54. *
  55. * <p>
  56. * The Framework invokes this method the first time the specified
  57. * <code>plugin</code> requests a service object using the
  58. * <code>ctkPluginContext::getService(const ctkServiceReference&)</code> method. The
  59. * service factory can then return a specific service object for each
  60. * plugin.
  61. *
  62. * <p>
  63. * The Framework caches the value returned (unless it is 0),
  64. * and will return the same service object on any future call to
  65. * <code>ctkPluginContext::getService</code> for the same plugins. This means the
  66. * Framework must not allow this method to be concurrently called for the
  67. * same plugin.
  68. *
  69. * <p>
  70. * The Framework will check if the returned service object is an instance of
  71. * all the classes named when the service was registered. If not, then
  72. * <code>0</code> is returned to the plugin.
  73. *
  74. * @param plugin The plugin using the service.
  75. * @param registration The <code>ctkServiceRegistration</code> object for the
  76. * service.
  77. * @return A service object that <strong>must</strong> be an instance of all
  78. * the classes named when the service was registered.
  79. * @see ctkPluginContext#getService
  80. */
  81. virtual QObject* getService(QSharedPointer<ctkPlugin> plugin, ctkServiceRegistration registration) = 0;
  82. /**
  83. * Releases a service object.
  84. *
  85. * <p>
  86. * The Framework invokes this method when a service has been released by a
  87. * plugin. The service object may then be destroyed.
  88. *
  89. * @param plugin The ctkPlugin releasing the service.
  90. * @param registration The <code>ctkServiceRegistration</code> object for the
  91. * service.
  92. * @param service The service object returned by a previous call to the
  93. * <code>ctkServiceFactory::getService</code> method.
  94. * @see ctkPluginContext#ungetService
  95. */
  96. virtual void ungetService(QSharedPointer<ctkPlugin> plugin, ctkServiceRegistration registration,
  97. QObject* service) = 0;
  98. };
  99. Q_DECLARE_INTERFACE(ctkServiceFactory, "org.commontk.services.ctkServiceFactory")