ctkPluginContext.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 CTKPLUGINCONTEXT_H_
  16. #define CTKPLUGINCONTEXT_H_
  17. #include <QHash>
  18. #include <QString>
  19. #include <QVariant>
  20. #include <QUrl>
  21. #include "ctkPluginEvent.h"
  22. #include "CTKPluginFrameworkExport.h"
  23. namespace ctk {
  24. // CTK class forward declarations
  25. class Plugin;
  26. class PluginPrivate;
  27. class ServiceRegistration;
  28. class ServiceReference;
  29. class PluginContextPrivate;
  30. /**
  31. * A plugin's execution context within the Framework. The context is used to
  32. * grant access to other methods so that this plugin can interact with the
  33. * Framework.
  34. *
  35. * <p>
  36. * <code>PluginContext</code> methods allow a plugin to:
  37. * <ul>
  38. * <li>Subscribe to events published by the Framework.
  39. * <li>Register service objects with the Framework service registry.
  40. * <li>Retrieve <code>ServiceReferences</code> from the Framework service
  41. * registry.
  42. * <li>Get and release service objects for a referenced service.
  43. * <li>Install new plugins in the Framework.
  44. * <li>Get the list of plugins installed in the Framework.
  45. * <li>Get the {@link Plugin} object for a plugin.
  46. * <li>Create <code>QFile</code> objects for files in a persistent storage
  47. * area provided for the plugin by the Framework.
  48. * </ul>
  49. *
  50. * <p>
  51. * A <code>PluginContext</code> object will be created and provided to the
  52. * plugin associated with this context when it is started using the
  53. * {@link PluginActivator#start} method. The same <code>PluginContext</code>
  54. * object will be passed to the plugin associated with this context when it is
  55. * stopped using the {@link PluginActivator#stop} method. A
  56. * <code>PluginContext</code> object is generally for the private use of its
  57. * associated plugin and is not meant to be shared with other plugins in the
  58. * plugin environment.
  59. *
  60. * <p>
  61. * The <code>Plugin</code> object associated with a <code>PluginContext</code>
  62. * object is called the <em>context plugin</em>.
  63. *
  64. * <p>
  65. * The <code>PluginContext</code> object is only valid during the execution of
  66. * its context plugin; that is, during the period from when the context plugin
  67. * is in the <code>STARTING</code>, <code>STOPPING</code>, and
  68. * <code>ACTIVE</code> plugin states. If the <code>PluginContext</code>
  69. * object is used subsequently, a <code>std::logic_error</code> must be
  70. * thrown. The <code>PluginContext</code> object must never be reused after
  71. * its context plugin is stopped.
  72. *
  73. * <p>
  74. * The Framework is the only entity that can create <code>PluginContext</code>
  75. * objects and they are only valid within the Framework that created them.
  76. *
  77. * @threadsafe
  78. */
  79. class CTK_PLUGINFW_EXPORT PluginContext : public QObject
  80. {
  81. Q_OBJECT
  82. Q_DECLARE_PRIVATE(PluginContext)
  83. public:
  84. typedef QHash<QString, QVariant> ServiceProperties;
  85. ~PluginContext();
  86. /**
  87. * Returns the <code>Plugin</code> object associated with this
  88. * <code>PluginContext</code>. This plugin is called the context plugin.
  89. *
  90. * @return The <code>Plugin</code> object associated with this
  91. * <code>PluginContext</code>.
  92. * @throws std::logic_error If this PluginContext is no
  93. * longer valid.
  94. */
  95. Plugin* getPlugin(int id) const;
  96. /**
  97. * Returns a list of all installed plugins.
  98. * <p>
  99. * This method returns a list of all plugins installed in the plugin
  100. * environment at the time of the call to this method. However, since the
  101. * Framework is a very dynamic environment, plugins can be installed or
  102. * uninstalled at anytime.
  103. *
  104. * @return A QList of <code>Plugin</code> objects, one object per
  105. * installed plugin.
  106. */
  107. QList<Plugin*> getPlugins() const;
  108. ServiceRegistration registerService(const QStringList& clazzes, QObject* service, const ServiceProperties& properties = ServiceProperties());
  109. QList<ServiceReference> getServiceReferences(const QString& clazz, const QString& filter = QString());
  110. ServiceReference getServiceReference(const QString& clazz);
  111. QObject* getService(const ServiceReference& reference);
  112. Plugin* installPlugin(const QUrl& location, QIODevice* in = 0);
  113. signals:
  114. /**
  115. *
  116. */
  117. void pluginChanged(const PluginEvent& event);
  118. /**
  119. *
  120. */
  121. //void frameworkEvent(const FrameworkEvent& event);
  122. /**
  123. *
  124. */
  125. //void serviceChanged(const ServiceEvent& event);
  126. protected:
  127. friend class PluginFrameworkPrivate;
  128. PluginContext(PluginPrivate* plugin);
  129. PluginContextPrivate * const d_ptr;
  130. };
  131. }
  132. #endif /* CTKPLUGINCONTEXT_H_ */