ctkTrackedService.tpp 3.6 KB

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