ctkServiceTrackerCustomizer.h 4.3 KB

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