ctkPluginFrameworkLauncher.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 CTKPLUGINFRAMEWORKLAUNCHER_H
  16. #define CTKPLUGINFRAMEWORKLAUNCHER_H
  17. #include <QString>
  18. #include <QScopedPointer>
  19. #include <ctkPluginFrameworkExport.h>
  20. #include "ctkPlugin.h"
  21. #include "ctkPluginFramework_global.h"
  22. class ctkPluginFramework;
  23. class ctkPluginFrameworkLauncherPrivate;
  24. /**
  25. * \ingroup PluginFramework
  26. *
  27. * Sets up and starts the CTK Plugin Framework.
  28. *
  29. * This is a convenience class to start an instance of the CTK Plugin
  30. * Framework and to install and start plugins.
  31. */
  32. class CTK_PLUGINFW_EXPORT ctkPluginFrameworkLauncher
  33. {
  34. public:
  35. /**
  36. * Specify the set of framework properties to be used when
  37. * initializing the Plugin Framework.
  38. *
  39. * <p>
  40. * If the framework has already been initialized by a call
  41. * to #install or #start, the
  42. * new properties do not have any effect until the framework
  43. * is restarted.
  44. *
  45. * \param props The initial Plugin Framework properties.
  46. */
  47. static void setFrameworkProperties(const ctkProperties& props);
  48. /**
  49. * Install the plugin with the given symbolic name using the provided
  50. * <code>ctkPluginContext</code>.
  51. *
  52. * <p>
  53. * This method instantiates and initializes an instance of a
  54. * ctkPluginFramework object, if no plugin context is provided and
  55. * if there is no framework already initialized.
  56. *
  57. * <p>
  58. * The plugin is searched in the paths previously given by calls
  59. * to #addSearchPath(const QString&, bool) and in the default
  60. * CTK plugin installation path.
  61. *
  62. * \param symbolicName The symbolic name of the plugin to install.
  63. * \param context The plugin context used for installing the plugin.
  64. * \return The plugin id if the plugin was found and successfully
  65. * installed, <code>-1</code> otherwise.
  66. */
  67. static long install(const QString& symbolicName, ctkPluginContext* context = 0);
  68. /**
  69. * This method instantiates, initializes, and starts an instance of a
  70. * ctkPluginFramework object, if no plugin context is provided and
  71. * if there is no framework already running. It then installs and
  72. * starts the plugin with the given symbolic name (if not empty).
  73. *
  74. * <p>
  75. * If a symbolic name is given, the plugin is searched in the paths previously given by calls
  76. * to #addSearchPath(const QString&, bool) and in the default
  77. * CTK plugin installation path and is started using the given <code>options</code>.
  78. *
  79. * <p>
  80. * If a plugin context is provided, this context is used to install the plugin,
  81. * otherwise the Plugin Framework context is used.
  82. *
  83. * \param symbolicName The symbolic name of the plugin to install.
  84. * \param options The options used to start the plugin.
  85. * \param context The plugin context to use for installing the plugin.
  86. * \return <code>true</code> if the plugin was found and successfully
  87. * installed, <code>false</code> otherwise.
  88. *
  89. * \see ctkPlugin::StartOptions
  90. */
  91. static bool start(const QString& symbolicName = QString(),
  92. ctkPlugin::StartOptions options = ctkPlugin::START_ACTIVATION_POLICY,
  93. ctkPluginContext* context = 0);
  94. /**
  95. * This method either stops the plug-in with the given <code>symbolicName</code> using
  96. * the supplied stop options <code>options</code>
  97. * or the complete framework (if <code>symbolicName</code> is empty).
  98. *
  99. * <p>
  100. * If a plugin context is provided, this context is used to find the plug-in,
  101. * otherwise the Plugin Framework context is used.
  102. *
  103. * \param symbolicName The symbolic name of the plugin to stop.
  104. * \param options The options used to stop the plugin.
  105. * \param context The plugin context to use for finding the plugin.
  106. * \return <code>true</code> if the plugin was found and successfully
  107. * stopped or the complete framework was successfully stopped,
  108. * <code>false</code> otherwise.
  109. *
  110. * \see ctkPlugin::StopOptions
  111. */
  112. static bool stop(const QString& symbolicName = QString(),
  113. ctkPlugin::StopOptions options = 0, ctkPluginContext* context = 0);
  114. /**
  115. * Get the plugin context for the Plugin Framework.
  116. *
  117. * \return The context associated to the Plugin Framework, or <code>null</code>
  118. * if the framework has not been initialized yet.
  119. */
  120. static ctkPluginContext* getPluginContext();
  121. /**
  122. * Get the Plugin Framework:
  123. *
  124. * \return The initialized Plugin Framework, or <code>null</code> if the
  125. * framework has not been initialized yet.
  126. */
  127. static QSharedPointer<ctkPluginFramework> getPluginFramework();
  128. /**
  129. * This is a utility method to append a path to the PATH environment variable
  130. * on Windows platforms.
  131. *
  132. * <p>
  133. * This method does nothing on non-Windows platforms.
  134. *
  135. * \param path The path to be appended to PATH
  136. */
  137. static void appendPathEnv(const QString& path);
  138. /**
  139. * Add a path to the list of search paths for plugins.
  140. *
  141. * When calling #install(const QString&, ctkPluginContext*), #start, or
  142. * #getPluginPath(const QString&), the plugin is searched in the
  143. * paths given as arguments to this method. The least recently added
  144. * path is searched first.
  145. *
  146. * \param searchPath The path to add.
  147. * \param addToPathEnv If <code>true</code>, add the given path to the
  148. * PATH environment variable, using #appendPathEnv(const QString&).
  149. */
  150. static void addSearchPath(const QString& searchPath, bool addToPathEnv = true);
  151. /**
  152. * Get the full path (including the file name) to the plugin with the
  153. * given symbolic name.
  154. *
  155. * <p>
  156. * The paths given by calls to #addSearchPath(const QString&, bool) are searched
  157. * for a shared library with a base name equaling <code>symbolicName</code>.
  158. *
  159. * \param symbolicName The symbolic name of the plugin to find.
  160. * \return The full path (including the file name) to the plugin (shared library)
  161. * or a null QString if the plugin was not found.
  162. */
  163. static QString getPluginPath(const QString& symbolicName);
  164. /**
  165. * Get a list of symbolic names for the plugins in <code>searchPath</code>.
  166. *
  167. * <p>
  168. * The symbolic names are deduced from the shared libraries found in
  169. * <code>searchPath</code>, which may not represent loadable CTK plugins.
  170. *
  171. * \param searchPath The path to look for plugins.
  172. * \return A list of potential plugin symbolic names.
  173. */
  174. static QStringList getPluginSymbolicNames(const QString& searchPath);
  175. private:
  176. static const QScopedPointer<ctkPluginFrameworkLauncherPrivate> d;
  177. Q_DISABLE_COPY(ctkPluginFrameworkLauncher)
  178. };
  179. #endif // CTKPLUGINFRAMEWORKLAUNCHER_H