ctkPluginTrackerCustomizer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 CTKPLUGINTRACKERCUSTOMIZER_H
  16. #define CTKPLUGINTRACKERCUSTOMIZER_H
  17. #include <QVariant>
  18. #include "ctkPluginEvent.h"
  19. class QObject;
  20. class ctkPlugin;
  21. /**
  22. * The <code>ctkPluginTrackerCustomizer</code> interface allows a
  23. * <code>ctkPluginTracker</code> to customize the <code>ctkPlugin</code>s that are
  24. * tracked. A <code>ctkPluginTrackerCustomizer</code> is called when a plugin is
  25. * being added to a <code>ctkPluginTracker</code>. The
  26. * <code>ctkPluginTrackerCustomizer</code> can then return an object for the
  27. * tracked plugin. A <code>ctkPluginTrackerCustomizer</code> is also called when a
  28. * tracked plugin is modified or has been removed from a
  29. * <code>ctkPluginTracker</code>.
  30. *
  31. * <p>
  32. * The methods in this interface may be called as the result of a
  33. * <code>ctkPluginEvent</code> being received by a <code>ctkPluginTracker</code>.
  34. * Since <code>ctkPluginEvent</code>s are received synchronously by the
  35. * <code>ctkPluginTracker</code>, it is highly recommended that implementations of
  36. * these methods do not alter plugin states while being synchronized on any
  37. * object.
  38. *
  39. * <p>
  40. * The <code>ctkPluginTracker</code> class is thread-safe. It does not call a
  41. * <code>ctkPluginTrackerCustomizer</code> while holding any locks.
  42. * <code>ctkPluginTrackerCustomizer</code> implementations must also be
  43. * thread-safe.
  44. *
  45. * \tparam T The type of the tracked object.
  46. * \threadsafe
  47. */
  48. template<class T>
  49. struct ctkPluginTrackerCustomizer {
  50. virtual ~ctkPluginTrackerCustomizer() {}
  51. /**
  52. * A plugin is being added to the <code>ctkPluginTracker</code>.
  53. *
  54. * <p>
  55. * This method is called before a plugin which matched the search parameters
  56. * of the <code>ctkPluginTracker</code> is added to the
  57. * <code>ctkPluginTracker</code>. This method should return the object to be
  58. * tracked for the specified <code>ctkPlugin</code>. The returned object is
  59. * stored in the <code>ctkPluginTracker</code> and is available from the
  60. * ctkPluginTracker::getObject(ctkPlugin*) method.
  61. *
  62. * @param plugin The <code>ctkPlugin</code> being added to the
  63. * <code>ctkPluginTracker</code>.
  64. * @param event The plugin event which caused this customizer method to be
  65. * called or an invalid event (ctkPluginEvent::isNull() returns <code>true</code>)
  66. * if there is no plugin event associated
  67. * with the call to this method.
  68. * @return The object to be tracked for the specified <code>ctkPlugin</code>
  69. * object or <code>null</code> if the specified <code>ctkPlugin</code>
  70. * object should not be tracked.
  71. */
  72. virtual T addingPlugin(QSharedPointer<ctkPlugin> plugin, const ctkPluginEvent& event) = 0;
  73. /**
  74. * A plugin tracked by the <code>ctkPluginTracker</code> has been modified.
  75. *
  76. * <p>
  77. * This method is called when a plugin being tracked by the
  78. * <code>ctkPluginTracker</code> has had its state modified.
  79. *
  80. * @param plugin The <code>ctkPlugin</code> whose state has been modified.
  81. * @param event The plugin event which caused this customizer method to be
  82. * called or an invalid event (ctkPluginEvent::isNull() returns <code>true</code>)
  83. * if there is no plugin event associated
  84. * with the call to this method.
  85. * @param object The tracked object for the specified plugin.
  86. */
  87. virtual void modifiedPlugin(QSharedPointer<ctkPlugin> plugin, const ctkPluginEvent& event,
  88. T object) = 0;
  89. /**
  90. * A plugin tracked by the <code>ctkPluginTracker</code> has been removed.
  91. *
  92. * <p>
  93. * This method is called after a plugin is no longer being tracked by the
  94. * <code>ctkPluginTracker</code>.
  95. *
  96. * @param plugin The <code>ctkPlugin</code> that has been removed.
  97. * @param event The plugin event which caused this customizer method to be
  98. * called or an invalid event (ctkPluginEvent::isNull() returns <code>true</code>)
  99. * if there is no plugin event associated
  100. * with the call to this method.
  101. * @param object The tracked object for the specified plugin.
  102. */
  103. virtual void removedPlugin(QSharedPointer<ctkPlugin> plugin, const ctkPluginEvent& event,
  104. T object) = 0;
  105. };
  106. #endif // CTKPLUGINTRACKERCUSTOMIZER_H