ctkServiceRegistrationPrivate.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 CTKSERVICEREGISTRATIONPRIVATE_H
  16. #define CTKSERVICEREGISTRATIONPRIVATE_H
  17. #include <QHash>
  18. #include <QMutex>
  19. #include "ctkServiceReference.h"
  20. namespace ctk {
  21. class PluginPrivate;
  22. class ServiceRegistration;
  23. class ServiceRegistrationPrivate
  24. {
  25. protected:
  26. ServiceRegistration* const q_ptr;
  27. /**
  28. * Service or ServiceFactory object.
  29. */
  30. QObject* service;
  31. public:
  32. Q_DECLARE_PUBLIC(ServiceRegistration);
  33. /**
  34. * Plugin registering this service.
  35. */
  36. PluginPrivate* plugin;
  37. /**
  38. * Reference object to this service registration.
  39. */
  40. ServiceReference* reference;
  41. /**
  42. * Service properties.
  43. */
  44. ServiceProperties properties;
  45. /**
  46. * Plugins dependent on this service. Integer is used as
  47. * reference counter, counting number of unbalanced getService().
  48. */
  49. QHash<Plugin*,int> dependents;
  50. /**
  51. * Object instances that factory has produced.
  52. */
  53. QHash<Plugin*, QObject*> serviceInstances;
  54. /**
  55. * Is service available. I.e., if <code>true</code> then holders
  56. * of a ServiceReference for the service are allowed to get it.
  57. */
  58. volatile bool available;
  59. /**
  60. * Avoid recursive unregistrations. I.e., if <code>true</code> then
  61. * unregistration of this service has started but is not yet
  62. * finished.
  63. */
  64. volatile bool unregistering;
  65. /**
  66. * Lock object for synchronous event delivery.
  67. */
  68. QMutex eventLock;
  69. QMutex propsLock;
  70. ServiceRegistrationPrivate(ServiceRegistration* sr, PluginPrivate* plugin, QObject* service,
  71. const ServiceProperties& props);
  72. virtual ~ServiceRegistrationPrivate();
  73. /**
  74. * Check if a plugin uses this service
  75. *
  76. * @param p Plugin to check
  77. * @return true if plugin uses this service
  78. */
  79. bool isUsedByPlugin(Plugin* p);
  80. virtual QObject* getService();
  81. };
  82. }
  83. #endif // CTKSERVICEREGISTRATIONPRIVATE_H