ctkPluginTrackerCustomizer.h 5.0 KB

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