ctkServiceTrackerPrivate.h 4.9 KB

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