ctkPluginFrameworkLauncher.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. class QRunnable;
  25. /**
  26. * \ingroup PluginFramework
  27. *
  28. * Sets up and starts the CTK Plugin Framework.
  29. *
  30. * This is a convenience class to start an instance of the CTK Plugin
  31. * Framework and to install and start plugins.
  32. */
  33. class CTK_PLUGINFW_EXPORT ctkPluginFrameworkLauncher
  34. {
  35. public:
  36. // System properties
  37. static const QString PROP_USER_HOME; // = "user.home";
  38. static const QString PROP_USER_DIR; // = "user.dir";
  39. // Framework properties
  40. static const QString PROP_PLUGINS; // = "ctk.plugins";
  41. static const QString PROP_DEBUG; // = "ctk.debug";
  42. static const QString PROP_DEV; // = "ctk.dev";
  43. static const QString PROP_CONSOLE; // = "ctk.console";
  44. static const QString PROP_OS; // = "ctk.os";
  45. static const QString PROP_ARCH; // = "ctk.arch";
  46. static const QString PROP_NOSHUTDOWN; // = "ctk.noShutdown";
  47. static const QString PROP_IGNOREAPP; // = "ctk.ignoreApp";
  48. static const QString PROP_INSTALL_AREA; // = "ctk.install.area";
  49. static const QString PROP_CONFIG_AREA; // = "ctk.configuration.area";
  50. static const QString PROP_SHARED_CONFIG_AREA; // = "ctk.sharedConfiguration.area";
  51. static const QString PROP_INSTANCE_AREA; // = "ctk.instance.area";
  52. static const QString PROP_USER_AREA; // = "ctk.user.area";
  53. static const QString PROP_HOME_LOCATION_AREA; // = "ctk.home.location";
  54. static const QString PROP_CONFIG_AREA_DEFAULT; // = "ctk.configuration.area.default";
  55. static const QString PROP_INSTANCE_AREA_DEFAULT; // = "ctk.instance.area.default";
  56. static const QString PROP_USER_AREA_DEFAULT; // = "ctk.user.area.default";
  57. static const QString PROP_EXITCODE; // = "ctk.exitcode";
  58. static const QString PROP_EXITDATA; // = "ctk.exitdata";
  59. static const QString PROP_CONSOLE_LOG; // = "ctk.consoleLog";
  60. static const QString PROP_ALLOW_APPRELAUNCH; // = "ctk.allowAppRelaunch";
  61. static const QString PROP_APPLICATION_LAUNCHDEFAULT; // = "ctk.application.launchDefault";
  62. static const QString PROP_OSGI_RELAUNCH; // = "ctk.pluginfw.relaunch";
  63. /**
  64. * Specify the set of framework properties to be used when
  65. * initializing the Plugin Framework.
  66. *
  67. * <p>
  68. * If the framework has already been initialized by a call
  69. * to #install or #start, the
  70. * new properties do not have any effect until the framework
  71. * is restarted.
  72. *
  73. * \param props The initial Plugin Framework properties.
  74. */
  75. static void setFrameworkProperties(const ctkProperties& props);
  76. /**
  77. * Launches the platform and runs a single application. The application is either identified
  78. * in the given arguments (e.g., -application &lt;app id&gt;) or in the <code>eclipse.application</code>
  79. * System property. This convenience method starts
  80. * up the platform, runs the indicated application, and then shuts down the
  81. * platform. The platform must not be running already.
  82. *
  83. * @param endSplashHandler the block of code to run to tear down the splash
  84. * screen or <code>null</code> if no tear down is required
  85. * @return the result of running the application
  86. * @throws Exception if anything goes wrong
  87. */
  88. static QVariant run(QRunnable* endSplashHandler = NULL);
  89. /**
  90. * Runs the application for which the platform was started. The platform
  91. * must be running.
  92. * <p>
  93. * The given argument is passed to the application being run. If it is <code>null</code>
  94. * then the command line arguments used in starting the platform, and not consumed
  95. * by the platform code, are passed to the application as a <code>String[]</code>.
  96. * </p>
  97. * @param argument the argument passed to the application. May be <code>null</code>
  98. * @return the result of running the application
  99. * @throws std::exception if anything goes wrong
  100. */
  101. static QVariant run(const QVariant& argument);
  102. /**
  103. * Starts the platform and sets it up to run a single application. The application is either identified
  104. * in the given arguments (e.g., -application &lt;app id&gt;) or in the <code>eclipse.application</code>
  105. * System property. The platform must not be running already.
  106. * <p>
  107. * The given runnable (if not <code>null</code>) is used to tear down the splash screen if required.
  108. * </p>
  109. * @param args the arguments passed to the application
  110. * @return BundleContext the context of the system bundle
  111. * @throws Exception if anything goes wrong
  112. */
  113. static ctkPluginContext* startup(QRunnable* endSplashHandler);
  114. /**
  115. * Shuts down the Platform. The state of the Platform is not automatically
  116. * saved before shutting down.
  117. * <p>
  118. * On return, the Platform will no longer be running (but could be re-launched
  119. * with another call to startup). If relaunching, care must be taken to reinitialize
  120. * any System properties which the platform uses (e.g., osgi.instance.area) as
  121. * some policies in the platform do not allow resetting of such properties on
  122. * subsequent runs.
  123. * </p><p>
  124. * Any objects handed out by running Platform,
  125. * including Platform runnables obtained via getRunnable, will be
  126. * permanently invalid. The effects of attempting to invoke methods
  127. * on invalid objects is undefined.
  128. * </p>
  129. * @throws std::exception if anything goes wrong
  130. */
  131. static void shutdown();
  132. /**
  133. * Install the plugin with the given symbolic name using the provided
  134. * <code>ctkPluginContext</code>.
  135. *
  136. * <p>
  137. * This method instantiates and initializes an instance of a
  138. * ctkPluginFramework object, if no plugin context is provided and
  139. * if there is no framework already initialized.
  140. *
  141. * <p>
  142. * The plugin is searched in the paths previously given by calls
  143. * to #addSearchPath(const QString&, bool) and in the default
  144. * CTK plugin installation path.
  145. *
  146. * \param symbolicName The symbolic name of the plugin to install.
  147. * \param context The plugin context used for installing the plugin.
  148. * \return The plugin id if the plugin was found and successfully
  149. * installed, <code>-1</code> otherwise.
  150. */
  151. static long install(const QString& symbolicName, ctkPluginContext* context = 0);
  152. /**
  153. * This method instantiates, initializes, and starts an instance of a
  154. * ctkPluginFramework object, if no plugin context is provided and
  155. * if there is no framework already running. It then installs and
  156. * starts the plugin with the given symbolic name (if not empty).
  157. *
  158. * <p>
  159. * If a symbolic name is given, the plugin is searched in the paths previously given by calls
  160. * to #addSearchPath(const QString&, bool) and in the default
  161. * CTK plugin installation path and is started using the given <code>options</code>.
  162. *
  163. * <p>
  164. * If a plugin context is provided, this context is used to install the plugin,
  165. * otherwise the Plugin Framework context is used.
  166. *
  167. * \param symbolicName The symbolic name of the plugin to install.
  168. * \param options The options used to start the plugin.
  169. * \param context The plugin context to use for installing the plugin.
  170. * \return <code>true</code> if the plugin was found and successfully
  171. * installed, <code>false</code> otherwise.
  172. *
  173. * \see ctkPlugin::StartOptions
  174. */
  175. static bool start(const QString& symbolicName = QString(),
  176. ctkPlugin::StartOptions options = ctkPlugin::START_ACTIVATION_POLICY,
  177. ctkPluginContext* context = 0);
  178. /**
  179. * This method either stops the plug-in with the given <code>symbolicName</code> using
  180. * the supplied stop options <code>options</code>
  181. * or the complete framework (if <code>symbolicName</code> is empty).
  182. *
  183. * <p>
  184. * If a plugin context is provided, this context is used to find the plug-in,
  185. * otherwise the Plugin Framework context is used.
  186. *
  187. * \param symbolicName The symbolic name of the plugin to stop.
  188. * \param options The options used to stop the plugin.
  189. * \param context The plugin context to use for finding the plugin.
  190. * \return <code>true</code> if the plugin was found and successfully
  191. * stopped or the complete framework was successfully stopped,
  192. * <code>false</code> otherwise.
  193. *
  194. * \see ctkPlugin::StopOptions
  195. */
  196. static bool stop(const QString& symbolicName = QString(),
  197. ctkPlugin::StopOptions options = 0, ctkPluginContext* context = 0);
  198. /**
  199. * Get the plugin context for the Plugin Framework.
  200. *
  201. * \return The context associated to the Plugin Framework, or <code>null</code>
  202. * if the framework has not been initialized yet.
  203. */
  204. static ctkPluginContext* getPluginContext();
  205. /**
  206. * Get the Plugin Framework:
  207. *
  208. * \return The initialized Plugin Framework, or <code>null</code> if the
  209. * framework has not been initialized yet.
  210. */
  211. static QSharedPointer<ctkPluginFramework> getPluginFramework();
  212. /**
  213. * This is a utility method to append a path to the PATH environment variable
  214. * on Windows platforms.
  215. *
  216. * <p>
  217. * This method does nothing on non-Windows platforms.
  218. *
  219. * \param path The path to be appended to PATH
  220. */
  221. static void appendPathEnv(const QString& path);
  222. /**
  223. * Add a path to the list of search paths for plugins.
  224. *
  225. * When calling #install(const QString&, ctkPluginContext*), #start, or
  226. * #getPluginPath(const QString&), the plugin is searched in the
  227. * paths given as arguments to this method. The least recently added
  228. * path is searched first.
  229. *
  230. * \param searchPath The path to add.
  231. * \param addToPathEnv If <code>true</code>, add the given path to the
  232. * PATH environment variable, using #appendPathEnv(const QString&).
  233. */
  234. static void addSearchPath(const QString& searchPath, bool addToPathEnv = true);
  235. /**
  236. * Get the full path (including the file name) to the plugin with the
  237. * given symbolic name.
  238. *
  239. * <p>
  240. * The paths given by calls to #addSearchPath(const QString&, bool) are searched
  241. * for a shared library with a base name equaling <code>symbolicName</code>.
  242. *
  243. * \param symbolicName The symbolic name of the plugin to find.
  244. * \return The full path (including the file name) to the plugin (shared library)
  245. * or a null QString if the plugin was not found.
  246. */
  247. static QString getPluginPath(const QString& symbolicName);
  248. /**
  249. * Get a list of symbolic names for the plugins in <code>searchPath</code>.
  250. *
  251. * <p>
  252. * The symbolic names are deduced from the shared libraries found in
  253. * <code>searchPath</code>, which may not represent loadable CTK plugins.
  254. *
  255. * \param searchPath The path to look for plugins.
  256. * \return A list of potential plugin symbolic names.
  257. */
  258. static QStringList getPluginSymbolicNames(const QString& searchPath);
  259. private:
  260. static const QScopedPointer<ctkPluginFrameworkLauncherPrivate> d;
  261. Q_DISABLE_COPY(ctkPluginFrameworkLauncher)
  262. };
  263. #endif // CTKPLUGINFRAMEWORKLAUNCHER_H