ctkServiceFactory.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 <QObject>
  16. #include "ctkPlugin.h"
  17. #include "CTKPluginFrameworkExport.h"
  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. * @threadsafe
  48. */
  49. class CTK_PLUGINFW_EXPORT ctkServiceFactory : public QObject
  50. {
  51. Q_OBJECT
  52. public:
  53. /**
  54. * Creates a new service object.
  55. *
  56. * <p>
  57. * The Framework invokes this method the first time the specified
  58. * <code>plugin</code> requests a service object using the
  59. * <code>ctkPluginContext::getService(const ctkServiceReference&)</code> method. The
  60. * service factory can then return a specific service object for each
  61. * plugin.
  62. *
  63. * <p>
  64. * The Framework caches the value returned (unless it is 0),
  65. * and will return the same service object on any future call to
  66. * <code>ctkPluginContext::getService</code> for the same plugins. This means the
  67. * Framework must not allow this method to be concurrently called for the
  68. * same plugin.
  69. *
  70. * <p>
  71. * The Framework will check if the returned service object is an instance of
  72. * all the classes named when the service was registered. If not, then
  73. * <code>0</code> is returned to the plugin.
  74. *
  75. * @param plugin The plugin using the service.
  76. * @param registration The <code>ctkServiceRegistration</code> object for the
  77. * service.
  78. * @return A service object that <strong>must</strong> be an instance of all
  79. * the classes named when the service was registered.
  80. * @see ctkPluginContext#getService
  81. */
  82. virtual QObject* getService(ctkPlugin* plugin, ctkServiceRegistration* registration) = 0;
  83. /**
  84. * Releases a service object.
  85. *
  86. * <p>
  87. * The Framework invokes this method when a service has been released by a
  88. * plugin. The service object may then be destroyed.
  89. *
  90. * @param plugin The ctkPlugin releasing the service.
  91. * @param registration The <code>ctkServiceRegistration</code> object for the
  92. * service.
  93. * @param service The service object returned by a previous call to the
  94. * <code>ctkServiceFactory::getService</code> method.
  95. * @see ctkPluginContext#ungetService
  96. */
  97. virtual void ungetService(ctkPlugin* plugin, ctkServiceRegistration* registration,
  98. QObject* service) = 0;
  99. };