ctkServiceTrackerCustomizer.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #ifndef CTKSERVICETRACKERCUSTOMIZER_H
  16. #define CTKSERVICETRACKERCUSTOMIZER_H
  17. #include <ctkServiceReference.h>
  18. /**
  19. * The <code>ctkServiceTrackerCustomizer</code> interface allows a
  20. * <code>ctkServiceTracker</code> to customize the service objects that are
  21. * tracked. A <code>ctkServiceTrackerCustomizer</code> is called when a service is
  22. * being added to a <code>ctkServiceTracker</code>. The
  23. * <code>ctkServiceTrackerCustomizer</code> can then return an object for the
  24. * tracked service. A <code>ctkServiceTrackerCustomizer</code> is also called when
  25. * a tracked service is modified or has been removed from a
  26. * <code>ctkServiceTracker</code>.
  27. *
  28. * <p>
  29. * The methods in this interface may be called as the result of a
  30. * <code>ctkServiceEvent</code> being received by a <code>ctkServiceTracker</code>.
  31. * Since <code>ctkServiceEvent</code>s are synchronously delivered by the
  32. * Framework, it is highly recommended that implementations of these methods do
  33. * not register (<code>ctkPluginContext::registerService</code>), modify (
  34. * <code>ctkServiceRegistration::setProperties</code>) or unregister (
  35. * <code>ctkServiceRegistration::unregister</code>) a service while being
  36. * synchronized on any object.
  37. *
  38. * <p>
  39. * The <code>ctkServiceTracker</code> class is thread-safe. It does not call a
  40. * <code>ctkServiceTrackerCustomizer</code> while holding any locks.
  41. * <code>ctkServiceTrackerCustomizer</code> implementations must also be
  42. * thread-safe.
  43. *
  44. * \tparam T The type of the tracked object.
  45. * \threadsafe
  46. */
  47. template<class T = QObject*>
  48. struct ctkServiceTrackerCustomizer {
  49. virtual ~ctkServiceTrackerCustomizer() {}
  50. /**
  51. * A service is being added to the <code>ctkServiceTracker</code>.
  52. *
  53. * <p>
  54. * This method is called before a service which matched the search
  55. * parameters of the <code>ctkServiceTracker</code> is added to the
  56. * <code>ctkServiceTracker</code>. This method should return the service object
  57. * to be tracked for the specified <code>ctkServiceReference</code>. The
  58. * returned service object is stored in the <code>ctkServiceTracker</code> and
  59. * is available from the <code>getService</code> and
  60. * <code>getServices</code> methods.
  61. *
  62. * @param reference The reference to the service being added to the
  63. * <code>ctkServiceTracker</code>.
  64. * @return The service object to be tracked for the specified referenced
  65. * service or <code>0</code> if the specified referenced service
  66. * should not be tracked.
  67. */
  68. virtual T addingService(const ctkServiceReference& reference) = 0;
  69. /**
  70. * A service tracked by the <code>ctkServiceTracker</code> has been modified.
  71. *
  72. * <p>
  73. * This method is called when a service being tracked by the
  74. * <code>ctkServiceTracker</code> has had it properties modified.
  75. *
  76. * @param reference The reference to the service that has been modified.
  77. * @param service The service object for the specified referenced service.
  78. */
  79. virtual void modifiedService(const ctkServiceReference& reference, T service) = 0;
  80. /**
  81. * A service tracked by the <code>ctkServiceTracker</code> has been removed.
  82. *
  83. * <p>
  84. * This method is called after a service is no longer being tracked by the
  85. * <code>ctkServiceTracker</code>.
  86. *
  87. * @param reference The reference to the service that has been removed.
  88. * @param service The service object for the specified referenced service.
  89. */
  90. virtual void removedService(const ctkServiceReference& reference, T service) = 0;
  91. };
  92. #endif // CTKSERVICETRACKERCUSTOMIZER_H