ctkTrackedService.tpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 <QtGlobal>
  16. //----------------------------------------------------------------------------
  17. template<class S, class T>
  18. ctkTrackedService<S,T>::ctkTrackedService(ctkServiceTracker<S,T>* serviceTracker,
  19. ctkServiceTrackerCustomizer<T>* customizer)
  20. : serviceTracker(serviceTracker), customizer(customizer)
  21. {
  22. }
  23. //----------------------------------------------------------------------------
  24. template<class S, class T>
  25. void ctkTrackedService<S,T>::serviceChanged(const ctkServiceEvent& event)
  26. {
  27. /*
  28. * Check if we had a delayed call (which could happen when we
  29. * close).
  30. */
  31. if (this->closed)
  32. {
  33. return;
  34. }
  35. ctkServiceReference reference = event.getServiceReference();
  36. if (serviceTracker->d_func()->DEBUG)
  37. {
  38. qDebug() << "ctkTrackedService::serviceChanged["
  39. << event.getType() << "]: " << reference;
  40. }
  41. switch (event.getType())
  42. {
  43. case ctkServiceEvent::REGISTERED :
  44. case ctkServiceEvent::MODIFIED :
  45. {
  46. if (!serviceTracker->d_func()->listenerFilter.isNull())
  47. { // service listener added with filter
  48. this->track(reference, event);
  49. /*
  50. * If the customizer throws an unchecked exception, it
  51. * is safe to let it propagate
  52. */
  53. }
  54. else
  55. { // service listener added without filter
  56. if (serviceTracker->d_func()->filter.match(reference))
  57. {
  58. this->track(reference, event);
  59. /*
  60. * If the customizer throws an unchecked exception,
  61. * it is safe to let it propagate
  62. */
  63. }
  64. else
  65. {
  66. this->untrack(reference, event);
  67. /*
  68. * If the customizer throws an unchecked exception,
  69. * it is safe to let it propagate
  70. */
  71. }
  72. }
  73. break;
  74. }
  75. case ctkServiceEvent::MODIFIED_ENDMATCH :
  76. case ctkServiceEvent::UNREGISTERING :
  77. this->untrack(reference, event);
  78. /*
  79. * If the customizer throws an unchecked exception, it is
  80. * safe to let it propagate
  81. */
  82. break;
  83. }
  84. }
  85. //----------------------------------------------------------------------------
  86. template<class S, class T>
  87. void ctkTrackedService<S,T>::modified()
  88. {
  89. Superclass::modified(); /* increment the modification count */
  90. serviceTracker->d_func()->modified();
  91. }
  92. //----------------------------------------------------------------------------
  93. template<class S, class T>
  94. T ctkTrackedService<S,T>::customizerAdding(ctkServiceReference item,
  95. const ctkServiceEvent& related)
  96. {
  97. Q_UNUSED(related)
  98. return customizer->addingService(item);
  99. }
  100. //----------------------------------------------------------------------------
  101. template<class S, class T>
  102. void ctkTrackedService<S,T>::customizerModified(ctkServiceReference item,
  103. const ctkServiceEvent& related,
  104. T object)
  105. {
  106. Q_UNUSED(related)
  107. customizer->modifiedService(item, object);
  108. }
  109. //----------------------------------------------------------------------------
  110. template<class S, class T>
  111. void ctkTrackedService<S,T>::customizerRemoved(ctkServiceReference item,
  112. const ctkServiceEvent& related,
  113. T object)
  114. {
  115. Q_UNUSED(related)
  116. customizer->removedService(item, object);
  117. }