ctkServices_p.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 CTKSERVICES_P_H
  16. #define CTKSERVICES_P_H
  17. #include <QHash>
  18. #include <QObject>
  19. #include <QMutex>
  20. #include <QStringList>
  21. #include "ctkServiceRegistration.h"
  22. #include "ctkPluginPrivate_p.h"
  23. /**
  24. * \ingroup PluginFramework
  25. *
  26. * Here we handle all the services that are registered in the framework.
  27. */
  28. class ctkServices {
  29. public:
  30. mutable QMutex mutex;
  31. /**
  32. * Creates a new ctkDictionary object containing <code>in</code>
  33. * with the keys converted to lower case.
  34. *
  35. * @param classes A list of class names which will be added to the
  36. * created ctkDictionary object under the key
  37. * PluginConstants::OBJECTCLASS.
  38. * @param sid A service id which will be used instead of a default one.
  39. */
  40. static ctkDictionary createServiceProperties(const ctkDictionary& in,
  41. const QStringList& classes = QStringList(),
  42. long sid = -1);
  43. /**
  44. * All registered services in the current framework.
  45. * Mapping of registered service to class names under which
  46. * the service is registerd.
  47. */
  48. QHash<ctkServiceRegistration, QStringList> services;
  49. /**
  50. * Mapping of classname to registered service.
  51. * The List of registered services are ordered with the highest
  52. * ranked service first.
  53. */
  54. QHash<QString, QList<ctkServiceRegistration> > classServices;
  55. ctkPluginFrameworkContext* framework;
  56. ctkServices(ctkPluginFrameworkContext* fwCtx);
  57. ~ctkServices();
  58. void clear();
  59. /**
  60. * Register a service in the framework wide register.
  61. *
  62. * @param plugin The plugin registering the service.
  63. * @param classes The class names under which the service can be located.
  64. * @param service The service object.
  65. * @param properties The properties for this service.
  66. * @return A ctkServiceRegistration object.
  67. * @exception std::invalid_argument If one of the following is true:
  68. * <ul>
  69. * <li>The service object is 0.</li>
  70. * <li>The service parameter is not a ctkServiceFactory or an
  71. * instance of all the named classes in the classes parameter.</li>
  72. * </ul>
  73. */
  74. ctkServiceRegistration registerService(ctkPluginPrivate* plugin,
  75. const QStringList& classes,
  76. QObject* service,
  77. const ctkDictionary& properties);
  78. /**
  79. * Service ranking changed, reorder registered services
  80. * according to ranking.
  81. *
  82. * @param serviceRegistration The ctkServiceRegistrationPrivate object.
  83. * @param rank New rank of object.
  84. */
  85. void updateServiceRegistrationOrder(const ctkServiceRegistration& sr,
  86. const QStringList& classes);
  87. /**
  88. * Checks that a given service object is an instance of the given
  89. * class name.
  90. *
  91. * @param service The service object to check.
  92. * @param cls The class name to check for.
  93. */
  94. bool checkServiceClass(QObject* service, const QString& cls) const;
  95. /**
  96. * Get all services implementing a certain class.
  97. * Only used internally by the framework.
  98. *
  99. * @param clazz The class name of the requested service.
  100. * @return A sorted list of {@link ctkServiceRegistrationPrivate} objects.
  101. */
  102. QList<ctkServiceRegistration> get(const QString& clazz) const;
  103. /**
  104. * Get a service implementing a certain class.
  105. *
  106. * @param plugin The plugin requesting reference
  107. * @param clazz The class name of the requested service.
  108. * @return A {@link ctkServiceReference} object.
  109. */
  110. ctkServiceReference get(ctkPluginPrivate* plugin, const QString& clazz) const;
  111. /**
  112. * Get all services implementing a certain class and then
  113. * filter these with a property filter.
  114. *
  115. * @param clazz The class name of requested service.
  116. * @param filter The property filter.
  117. * @param plugin The plugin requesting reference.
  118. * @return A list of {@link ctkServiceReference} object.
  119. */
  120. QList<ctkServiceReference> get(const QString& clazz, const QString& filter,
  121. ctkPluginPrivate* plugin) const;
  122. /**
  123. * Remove a registered service.
  124. *
  125. * @param sr The ctkServiceRegistration object that is registered.
  126. */
  127. void removeServiceRegistration(const ctkServiceRegistration& sr) ;
  128. /**
  129. * Get all services that a plugin has registered.
  130. *
  131. * @param p The plugin
  132. * @return A set of {@link ctkServiceRegistration} objects
  133. */
  134. QList<ctkServiceRegistration> getRegisteredByPlugin(ctkPluginPrivate* p) const;
  135. /**
  136. * Get all services that a plugin uses.
  137. *
  138. * @param p The plugin
  139. * @return A set of {@link ctkServiceRegistration} objects
  140. */
  141. QList<ctkServiceRegistration> getUsedByPlugin(QSharedPointer<ctkPlugin> p) const;
  142. };
  143. #endif // CTKSERVICES_P_H