ctkServiceTrackerPrivate.h 4.6 KB

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