ctkPluginFrameworkLauncher.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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(const QString&) 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::StartOption
  90. */
  91. static bool start(const QString& symbolicName = QString(),
  92. ctkPlugin::StartOptions options = ctkPlugin::START_ACTIVATION_POLICY,
  93. ctkPluginContext* context = 0);
  94. /**
  95. * Get the plugin context for the Plugin Framework.
  96. *
  97. * \return The context associated to the Plugin Framework, or <code>null</code>
  98. * if the framework has not been initialized yet.
  99. */
  100. static ctkPluginContext* getPluginContext();
  101. /**
  102. * Get the Plugin Framework:
  103. *
  104. * \return The initialized Plugin Framework, or <code>null</code> if the
  105. * framework has not been initialized yet.
  106. */
  107. static QSharedPointer<ctkPluginFramework> getPluginFramework();
  108. /**
  109. * This is a utility method to append a path to the PATH environment variable
  110. * on Windows platforms.
  111. *
  112. * <p>
  113. * This method does nothing on non-Windows platforms.
  114. *
  115. * \param path The path to be appended to PATH
  116. */
  117. static void appendPathEnv(const QString& path);
  118. /**
  119. * Add a path to the list of search paths for plugins.
  120. *
  121. * When calling #install(const QString&), #start, or
  122. * #getPluginPath(const QString&), the plugin is searched in the
  123. * paths given as arguments to this method. The least recently added
  124. * path is searched first.
  125. *
  126. * \param searchPath The path to add.
  127. * \param addToPathEnv If <code>true</code>, add the given path to the
  128. * PATH environment variable, using #appendPathEnv(const QString&).
  129. */
  130. static void addSearchPath(const QString& searchPath, bool addToPathEnv = true);
  131. /**
  132. * Get the full path (including the file name) to the plugin with the
  133. * given symbolic name.
  134. *
  135. * <p>
  136. * The paths given by calls to #addSearchPath(const QString&, bool) are searched
  137. * for a shared library with a base name equaling <code>symbolicName</code>.
  138. *
  139. * \param symbolicName The symbolic name of the plugin to find.
  140. * \return The full path (including the file name) to the plugin (shared library)
  141. * or a null QString if the plugin was not found.
  142. */
  143. static QString getPluginPath(const QString& symbolicName);
  144. /**
  145. * Get a list of symbolic names for the plugins in <code>searchPath</code>.
  146. *
  147. * <p>
  148. * The symbolic names are deduced from the shared libraries found in
  149. * <code>searchPath</code>, which may not represent loadable CTK plugins.
  150. *
  151. * \param searchPath The path to look for plugins.
  152. * \return A list of potential plugin symbolic names.
  153. */
  154. static QStringList getPluginSymbolicNames(const QString& searchPath);
  155. private:
  156. static const QScopedPointer<ctkPluginFrameworkLauncherPrivate> d;
  157. Q_DISABLE_COPY(ctkPluginFrameworkLauncher)
  158. };
  159. #endif // CTKPLUGINFRAMEWORKLAUNCHER_H