ctkServiceTracker_p.tpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #include "ctkTrackedService_p.h"
  16. #include "ctkPluginContext.h"
  17. #include "ctkPluginConstants.h"
  18. #include "ctkLDAPSearchFilter.h"
  19. //----------------------------------------------------------------------------
  20. template<class S, class T>
  21. const bool ctkServiceTrackerPrivate<S,T>::DEBUG = false;
  22. //----------------------------------------------------------------------------
  23. template<class S, class T>
  24. ctkServiceTrackerPrivate<S,T>::ctkServiceTrackerPrivate(
  25. ctkServiceTracker<S,T>* st, ctkPluginContext* context,
  26. const ctkServiceReference& reference,
  27. ctkServiceTrackerCustomizer<T>* customizer)
  28. : context(context), customizer(customizer), trackReference(reference),
  29. trackedService(0), cachedReference(0), cachedService(0), q_ptr(st)
  30. {
  31. this->customizer = customizer ? customizer : q_func();
  32. this->listenerFilter = QString("(") + ctkPluginConstants::SERVICE_ID +
  33. "=" + reference.getProperty(ctkPluginConstants::SERVICE_ID).toString() + ")";
  34. try
  35. {
  36. this->filter = ctkLDAPSearchFilter(listenerFilter);
  37. }
  38. catch (const ctkInvalidArgumentException& e)
  39. {
  40. /*
  41. * we could only get this exception if the ServiceReference was
  42. * invalid
  43. */
  44. ctkInvalidArgumentException ia(QString("unexpected ctkInvalidArgumentException exception: %1").arg(e.what()));
  45. throw ia;
  46. }
  47. }
  48. //----------------------------------------------------------------------------
  49. template<class S, class T>
  50. ctkServiceTrackerPrivate<S,T>::ctkServiceTrackerPrivate(
  51. ctkServiceTracker<S,T>* st,
  52. ctkPluginContext* context, const QString& clazz,
  53. ctkServiceTrackerCustomizer<T>* customizer)
  54. : context(context), customizer(customizer), trackClass(clazz),
  55. trackReference(0), trackedService(0), cachedReference(0),
  56. cachedService(0), q_ptr(st)
  57. {
  58. this->customizer = customizer ? customizer : q_func();
  59. this->listenerFilter = QString("(") + ctkPluginConstants::OBJECTCLASS + "="
  60. + clazz + ")";
  61. try
  62. {
  63. this->filter = ctkLDAPSearchFilter(listenerFilter);
  64. }
  65. catch (const ctkInvalidArgumentException& e)
  66. {
  67. /*
  68. * we could only get this exception if the clazz argument was
  69. * malformed
  70. */
  71. ctkInvalidArgumentException ia(
  72. QString("unexpected ctkInvalidArgumentException exception: %1").arg(e.what()));
  73. throw ia;
  74. }
  75. }
  76. //----------------------------------------------------------------------------
  77. template<class S, class T>
  78. ctkServiceTrackerPrivate<S,T>::ctkServiceTrackerPrivate(
  79. ctkServiceTracker<S,T>* st,
  80. ctkPluginContext* context, const ctkLDAPSearchFilter& filter,
  81. ctkServiceTrackerCustomizer<T>* customizer)
  82. : context(context), filter(filter), customizer(customizer),
  83. listenerFilter(filter.toString()), trackReference(0),
  84. trackedService(0), cachedReference(0), cachedService(0), q_ptr(st)
  85. {
  86. this->customizer = customizer ? customizer : q_func();
  87. if (context == 0)
  88. {
  89. throw ctkInvalidArgumentException("The plugin context cannot be null.");
  90. }
  91. }
  92. //----------------------------------------------------------------------------
  93. template<class S, class T>
  94. ctkServiceTrackerPrivate<S,T>::~ctkServiceTrackerPrivate()
  95. {
  96. }
  97. //----------------------------------------------------------------------------
  98. template<class S, class T>
  99. QList<ctkServiceReference> ctkServiceTrackerPrivate<S,T>::getInitialReferences(const QString& className,
  100. const QString& filterString)
  101. {
  102. return context->getServiceReferences(className, filterString);
  103. }
  104. //----------------------------------------------------------------------------
  105. template<class S, class T>
  106. QList<ctkServiceReference> ctkServiceTrackerPrivate<S,T>::getServiceReferences_unlocked(ctkTrackedService<S,T>* t) const
  107. {
  108. if (t->size() == 0)
  109. {
  110. return QList<ctkServiceReference>();
  111. }
  112. return t->getTracked();
  113. }
  114. //----------------------------------------------------------------------------
  115. template<class S, class T>
  116. QSharedPointer<ctkTrackedService<S,T> > ctkServiceTrackerPrivate<S,T>::tracked() const
  117. {
  118. return trackedService;
  119. }
  120. //----------------------------------------------------------------------------
  121. template<class S, class T>
  122. void ctkServiceTrackerPrivate<S,T>::modified()
  123. {
  124. cachedReference = 0; /* clear cached value */
  125. cachedService = 0; /* clear cached value */
  126. if (DEBUG)
  127. {
  128. qDebug() << "ctkServiceTracker::modified:" << filter;
  129. }
  130. }