ctkServiceFactory.h 4.1 KB

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