ctkPluginFrameworkLauncher.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 in the Plugin
  50. * Framework.
  51. *
  52. * <p>
  53. * This method instantiates and initializes an instance of a
  54. * ctkPluginFramework object, if there is no framework already
  55. * 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. * \return <code>true</code> if the plugin was found and successfully
  64. * installed, <code>false</code> otherwise.
  65. */
  66. static bool install(const QString& symbolicName);
  67. /**
  68. * Start the CTK Plugin Framework and/or the plugin with the given
  69. * symbolic name.
  70. *
  71. * <p>
  72. * This method creates and initializes the CTK Plugin Framework if it
  73. * has not been previously initialized and starts it. It then optionally
  74. * starts the plugin with the given symbolic name and start options.
  75. *
  76. * <p>
  77. * If a symbolic name is given, the plugin is searched in the paths previously given by calls
  78. * to #addSearchPath(const QString&, bool) and in the default
  79. * CTK plugin installation path.
  80. *
  81. * \param symbolicName The symbolic name of the plugin to install.
  82. * \param options The options used to start the plugin.
  83. * \return <code>true</code> if the plugin was found and successfully
  84. * installed, <code>false</code> otherwise.
  85. *
  86. * \see ctkPlugin::StartOption
  87. */
  88. static bool start(const QString& symbolicName = QString(), ctkPlugin::StartOptions options = ctkPlugin::START_ACTIVATION_POLICY);
  89. /**
  90. * Get the plugin context for the Plugin Framework.
  91. *
  92. * \return The context associated to the Plugin Framework, or <code>null</code>
  93. * if the framework has not been initialized yet.
  94. */
  95. static ctkPluginContext* getPluginContext();
  96. /**
  97. * Get the Plugin Framework:
  98. *
  99. * \return The initialized Plugin Framework, or <code>null</code> if the
  100. * framework has not been initialized yet.
  101. */
  102. static QSharedPointer<ctkPluginFramework> getPluginFramework();
  103. /**
  104. * Append a path to the PATH environment variable.
  105. *
  106. * <p>
  107. * This method appends the given path to the PATH environment variable.
  108. * It does nothing on non-Windows platforms.
  109. *
  110. * \param path The path to be appended to PATH
  111. */
  112. static void appendPathEnv(const QString& path);
  113. /**
  114. * Add a path to the list of search paths for plugins.
  115. *
  116. * When calling #install(const QString&), #start, or
  117. * #getPluginPath(const QString&), the plugin is searched in the
  118. * paths given as arguments to this method. The least recently added
  119. * path is searched first.
  120. *
  121. * \param searchPath The path to add.
  122. * \param addToPathEnv If <code>true</code>, add the given path to the
  123. * PATH environment variable, using #appendPathEnv(const QString&).
  124. */
  125. static void addSearchPath(const QString& searchPath, bool addToPathEnv = true);
  126. /**
  127. * Get the full path (including the file name) to the plugin with the
  128. * given symbolic name.
  129. *
  130. * <p>
  131. * The paths given by calls to #addSearchPath(const QString&, bool) are searched
  132. * for a shared library with a base name equaling <code>symbolicName</code>.
  133. *
  134. * \param symbolicName The symbolic name of the plugin to find.
  135. * \return The full path (including the file name) to the plugin (shared library)
  136. * or a null QString if the plugin was not found.
  137. */
  138. static QString getPluginPath(const QString& symbolicName);
  139. private:
  140. static const QScopedPointer<ctkPluginFrameworkLauncherPrivate> d;
  141. Q_DISABLE_COPY(ctkPluginFrameworkLauncher)
  142. };
  143. #endif // CTKPLUGINFRAMEWORKLAUNCHER_H