ctkPlugins_p.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 CTKPLUGINS_H
  16. #define CTKPLUGINS_H
  17. #include <QUrl>
  18. #include <QHash>
  19. #include <QReadWriteLock>
  20. #include <QMutex>
  21. #include <QSharedPointer>
  22. // CTK class forward declarations
  23. class ctkPlugin;
  24. class ctkPluginFrameworkContext;
  25. class ctkVersion;
  26. class ctkVersionRange;
  27. /**
  28. * \ingroup PluginFramework
  29. *
  30. * Here we handle all the plugins that are installed in the framework.
  31. * Also handles load and save of bundle states to a database, so that we
  32. * can restart the platform.
  33. */
  34. class ctkPlugins {
  35. private:
  36. /**
  37. * Table of all installed plugins in this framework.
  38. * Key is the plugin location.
  39. */
  40. QHash<QString, QSharedPointer<ctkPlugin> > plugins;
  41. /**
  42. * Link to framework object.
  43. */
  44. ctkPluginFrameworkContext* fwCtx;
  45. /**
  46. * Read write lock for protecting the plugins object
  47. */
  48. mutable QReadWriteLock pluginsLock;
  49. /**
  50. * Lock for protecting this object.
  51. */
  52. QMutex objectLock;
  53. void checkIllegalState() const;
  54. public:
  55. /**
  56. * Create a container for all plugins in this framework.
  57. */
  58. ctkPlugins(ctkPluginFrameworkContext* fw);
  59. void clear();
  60. /**
  61. * Install a new plugin.
  62. *
  63. * @param location The location to be installed
  64. */
  65. QSharedPointer<ctkPlugin> install(const QUrl& location, QIODevice* in);
  66. /**
  67. * Remove plugin registration.
  68. *
  69. * @param location The location to be removed
  70. */
  71. void remove(const QUrl& location);
  72. /**
  73. * Get the plugin that has the specified plugin identifier.
  74. *
  75. * @param id The identifier of the plugin to get.
  76. * @return ctkPlugin or null
  77. * if the plugin was not found.
  78. */
  79. QSharedPointer<ctkPlugin> getPlugin(int id) const;
  80. /**
  81. * Get the plugin that has specified plugin location.
  82. *
  83. * @param location The location of the plugin to get.
  84. * @return ctkPlugin or null
  85. * if the plugin was not found.
  86. */
  87. QSharedPointer<ctkPlugin> getPlugin(const QString& location) const;
  88. /**
  89. * Get the plugin that has specified plugin symbolic name and version.
  90. *
  91. * @param name The symbolic name of the plugin to get.
  92. * @param version The plugin version of the plugin to get.
  93. * @return ctkPlugin or null.
  94. */
  95. QSharedPointer<ctkPlugin> getPlugin(const QString& name, const ctkVersion& version) const;
  96. /**
  97. * Get all installed plugins.
  98. *
  99. * @return A ctkPlugin list with plugins.
  100. */
  101. QList<QSharedPointer<ctkPlugin> > getPlugins() const;
  102. /**
  103. * Get all plugins that have specified plugin symbolic name.
  104. *
  105. * @param name The symbolic name of plugins to get.
  106. * @return A list of ctkPlugins.
  107. */
  108. QList<ctkPlugin*> getPlugins(const QString& name) const;
  109. /**
  110. * Get all plugins that have specified plugin symbolic name and
  111. * version range. Result is sorted in decreasing version order.
  112. *
  113. * @param name The symbolic name of plugins to get.
  114. * @param range ctkVersion range of plugins to get.
  115. * @return A List of ctkPlugins.
  116. */
  117. QList<ctkPlugin*> getPlugins(const QString& name, const ctkVersionRange& range) const;
  118. /**
  119. * Get all plugins currently in plugin state ACTIVE.
  120. *
  121. * @return A List of ctkPlugins.
  122. */
  123. QList<QSharedPointer<ctkPlugin> > getActivePlugins() const;
  124. /**
  125. * Try to load any saved framework state.
  126. * This is done by installing all saved plugins and restoring
  127. * the saved state for each plugin. This is only
  128. * intended to be executed during the start of the framework.
  129. *
  130. */
  131. void load();
  132. /**
  133. * Start a list of plugins in order
  134. *
  135. * @param slist ctkPlugins to start.
  136. */
  137. void startPlugins(const QList<ctkPlugin*>& slist) const;
  138. };
  139. #endif // CTKPLUGINS_H