ctkPluginEvent.h 3.3 KB

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