ctkServiceRegistration_p.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 CTKSERVICEREGISTRATIONPRIVATE_H
  16. #define CTKSERVICEREGISTRATIONPRIVATE_H
  17. #include <QHash>
  18. #include <QMutex>
  19. #include "ctkServiceProperties_p.h"
  20. #include "ctkServiceReference.h"
  21. class ctkPluginPrivate;
  22. class ctkServiceRegistration;
  23. /**
  24. * \ingroup PluginFramework
  25. */
  26. class ctkServiceRegistrationPrivate
  27. {
  28. protected:
  29. friend class ctkServiceRegistration;
  30. // The ctkServiceReferencePrivate class holds a pointer to a
  31. // ctkServiceRegistrationPrivate instance and needs to manipulate
  32. // its reference count. This way it can keep the ctkServiceRegistrationPrivate
  33. // instance alive and keep returning service properties for
  34. // unregistered service instances.
  35. friend class ctkServiceReferencePrivate;
  36. /**
  37. * Reference count for implicitly shared private implementation.
  38. */
  39. QAtomicInt ref;
  40. /**
  41. * Service or ctkServiceFactory object.
  42. */
  43. QObject* service;
  44. public:
  45. /**
  46. * Plugin registering this service.
  47. */
  48. ctkPluginPrivate* plugin;
  49. /**
  50. * Reference object to this service registration.
  51. */
  52. ctkServiceReference reference;
  53. /**
  54. * Service properties.
  55. */
  56. ctkServiceProperties properties;
  57. /**
  58. * Plugins dependent on this service. Integer is used as
  59. * reference counter, counting number of unbalanced getService().
  60. */
  61. QHash<QSharedPointer<ctkPlugin>,int> dependents;
  62. /**
  63. * Object instances that factory has produced.
  64. */
  65. QHash<QSharedPointer<ctkPlugin>, QObject*> serviceInstances;
  66. /**
  67. * Is service available. I.e., if <code>true</code> then holders
  68. * of a ctkServiceReference for the service are allowed to get it.
  69. */
  70. volatile bool available;
  71. /**
  72. * Avoid recursive unregistrations. I.e., if <code>true</code> then
  73. * unregistration of this service has started but is not yet
  74. * finished.
  75. */
  76. volatile bool unregistering;
  77. /**
  78. * Lock object for synchronous event delivery.
  79. */
  80. QMutex eventLock;
  81. QMutex propsLock;
  82. ctkServiceRegistrationPrivate(ctkPluginPrivate* plugin, QObject* service,
  83. const ctkDictionary& props);
  84. virtual ~ctkServiceRegistrationPrivate();
  85. /**
  86. * Check if a plugin uses this service
  87. *
  88. * @param p Plugin to check
  89. * @return true if plugin uses this service
  90. */
  91. bool isUsedByPlugin(QSharedPointer<ctkPlugin> p);
  92. virtual QObject* getService();
  93. private:
  94. Q_DISABLE_COPY(ctkServiceRegistrationPrivate)
  95. };
  96. #endif // CTKSERVICEREGISTRATIONPRIVATE_H