ctkServiceTracker_p.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 CTKSERVICETRACKERPRIVATE_H
  16. #define CTKSERVICETRACKERPRIVATE_H
  17. #include "ctkServiceReference.h"
  18. #include "ctkLDAPSearchFilter.h"
  19. #include <QMutex>
  20. #include <QSharedPointer>
  21. /**
  22. * \ingroup PluginFramework
  23. */
  24. template<class S, class T>
  25. class ctkServiceTrackerPrivate
  26. {
  27. public:
  28. ctkServiceTrackerPrivate(ctkServiceTracker<S,T>* st,
  29. ctkPluginContext* context,
  30. const ctkServiceReference& reference,
  31. ctkServiceTrackerCustomizer<T>* customizer);
  32. ctkServiceTrackerPrivate(ctkServiceTracker<S,T>* st,
  33. ctkPluginContext* context, const QString& clazz,
  34. ctkServiceTrackerCustomizer<T>* customizer);
  35. ctkServiceTrackerPrivate(
  36. ctkServiceTracker<S,T>* st,
  37. ctkPluginContext* context, const ctkLDAPSearchFilter& filter,
  38. ctkServiceTrackerCustomizer<T>* customizer);
  39. ~ctkServiceTrackerPrivate();
  40. /**
  41. * Returns the list of initial <code>ctkServiceReference</code>s that will be
  42. * tracked by this <code>ctkServiceTracker</code>.
  43. *
  44. * @param className The class name with which the service was registered, or
  45. * <code>null</code> for all services.
  46. * @param filterString The filter criteria or <code>null</code> for all
  47. * services.
  48. * @return The list of initial <code>ctkServiceReference</code>s.
  49. * @throws ctkInvalidArgumentException If the specified filterString has an
  50. * invalid syntax.
  51. */
  52. QList<ctkServiceReference> getInitialReferences(const QString& className,
  53. const QString& filterString);
  54. QList<ctkServiceReference> getServiceReferences_unlocked(ctkTrackedService<S,T>* t) const;
  55. /* set this to true to compile in debug messages */
  56. static const bool DEBUG_FLAG; // = false;
  57. /**
  58. * The Plugin Context used by this <code>ctkServiceTracker</code>.
  59. */
  60. ctkPluginContext* const context;
  61. /**
  62. * The filter used by this <code>ctkServiceTracker</code> which specifies the
  63. * search criteria for the services to track.
  64. */
  65. ctkLDAPSearchFilter filter;
  66. /**
  67. * The <code>ctkServiceTrackerCustomizer</code> for this tracker.
  68. */
  69. ctkServiceTrackerCustomizer<T>* customizer;
  70. /**
  71. * Filter string for use when adding the ServiceListener. If this field is
  72. * set, then certain optimizations can be taken since we don't have a user
  73. * supplied filter.
  74. */
  75. QString listenerFilter;
  76. /**
  77. * Class name to be tracked. If this field is set, then we are tracking by
  78. * class name.
  79. */
  80. QString trackClass;
  81. /**
  82. * Reference to be tracked. If this field is set, then we are tracking a
  83. * single ctkServiceReference.
  84. */
  85. ctkServiceReference trackReference;
  86. /**
  87. * Tracked services: <code>ctkServiceReference</code> -> customized Object and
  88. * <code>ctkServiceSlotEntry</code> object
  89. */
  90. QSharedPointer<ctkTrackedService<S,T> > trackedService;
  91. /**
  92. * Accessor method for the current ctkTrackedService object. This method is only
  93. * intended to be used by the unsynchronized methods which do not modify the
  94. * trackedService field.
  95. *
  96. * @return The current Tracked object.
  97. */
  98. QSharedPointer<ctkTrackedService<S,T> > tracked() const;
  99. /**
  100. * Called by the ctkTrackedService object whenever the set of tracked services is
  101. * modified. Clears the cache.
  102. */
  103. /*
  104. * This method must not be synchronized since it is called by ctkTrackedService while
  105. * ctkTrackedService is synchronized. We don't want synchronization interactions
  106. * between the listener thread and the user thread.
  107. */
  108. void modified();
  109. /**
  110. * Cached ctkServiceReference for getServiceReference.
  111. */
  112. mutable ctkServiceReference cachedReference;
  113. /**
  114. * Cached service object for getService.
  115. *
  116. * This field is volatile since it is accessed by multiple threads.
  117. */
  118. mutable T volatile cachedService;
  119. mutable QMutex mutex;
  120. private:
  121. inline ctkServiceTracker<S,T>* q_func()
  122. {
  123. return static_cast<ctkServiceTracker<S,T> *>(q_ptr);
  124. }
  125. inline const ctkServiceTracker<S,T>* q_func() const
  126. {
  127. return static_cast<const ctkServiceTracker<S,T> *>(q_ptr);
  128. }
  129. friend class ctkServiceTracker<S,T>;
  130. ctkServiceTracker<S,T> * const q_ptr;
  131. };
  132. #include "ctkServiceTracker_p.tpp"
  133. #endif // CTKSERVICETRACKERPRIVATE_H