ctkServiceTrackerPrivate.tpp 4.2 KB

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