ctkServiceTrackerPrivate.cpp 4.0 KB

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