ctkServices_p.h 5.5 KB

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