ctkServiceTrackerPrivate.tpp 4.8 KB

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