ctkPluginEvent.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 CTKPLUGINEVENT_H
  16. #define CTKPLUGINEVENT_H
  17. #include <QObject>
  18. #include <QSharedDataPointer>
  19. #include "CTKPluginFrameworkExport.h"
  20. namespace ctk {
  21. class Plugin;
  22. class PluginEventData;
  23. /**
  24. * An event from the Framework describing a plugin lifecycle change.
  25. * <p>
  26. * <code>PluginEvent</code> objects are delivered to slots connected
  27. * to PluginContext::pluginChanged() or to registerd event handlers
  28. * for the topic "org.commontk/framework/pluginChanged"
  29. * when a change occurs in a plugins's lifecycle. A type code is used to identify
  30. * the event type for future extendability.
  31. *
  32. * @see PluginContext#connectPluginListener
  33. * @see EventBus
  34. */
  35. class CTK_PLUGINFW_EXPORT PluginEvent : public QObject
  36. {
  37. Q_OBJECT
  38. Q_PROPERTY(Type type READ getType CONSTANT)
  39. Q_PROPERTY(Plugin* plugin READ getPlugin CONSTANT)
  40. Q_ENUMS(Type)
  41. QSharedDataPointer<PluginEventData> d;
  42. public:
  43. enum Type {
  44. INSTALLED,
  45. STARTED,
  46. STOPPED,
  47. UPDATED,
  48. UNINSTALLED,
  49. RESOLVED,
  50. UNRESOLVED,
  51. STARTING,
  52. STOPPING,
  53. LAZY_ACTIVATION
  54. };
  55. /**
  56. * Creates a plugin event of the specified type.
  57. *
  58. * @param type The event type.
  59. * @param plugin The plugin which had a lifecycle change.
  60. */
  61. PluginEvent(Type type, Plugin* plugin);
  62. PluginEvent(const PluginEvent& other);
  63. /**
  64. * Returns the plugin which had a lifecycle change.
  65. *
  66. * @return The plugin that had a change occur in its lifecycle.
  67. */
  68. Plugin* getPlugin() const;
  69. /**
  70. * Returns the type of lifecyle event. The type values are:
  71. * <ul>
  72. * <li>{@link #INSTALLED}
  73. * <li>{@link #RESOLVED}
  74. * <li>{@link #LAZY_ACTIVATION}
  75. * <li>{@link #STARTING}
  76. * <li>{@link #STARTED}
  77. * <li>{@link #STOPPING}
  78. * <li>{@link #STOPPED}
  79. * <li>{@link #UPDATED}
  80. * <li>{@link #UNRESOLVED}
  81. * <li>{@link #UNINSTALLED}
  82. * </ul>
  83. *
  84. * @return The type of lifecycle event.
  85. */
  86. Type getType() const;
  87. };
  88. class PluginEventData : public QSharedData
  89. {
  90. public:
  91. PluginEventData(PluginEvent::Type type, Plugin* plugin)
  92. : type(type), plugin(plugin)
  93. {
  94. }
  95. PluginEventData(const PluginEventData& other)
  96. : QSharedData(other), type(other.type), plugin(other.plugin)
  97. {
  98. }
  99. const PluginEvent::Type type;
  100. Plugin* const plugin;
  101. };
  102. }
  103. #endif // CTKPLUGINEVENT_H