ctkDefaultApplicationLauncher_p.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 CTKDEFAULTAPPLICATIONLAUNCHER_H
  16. #define CTKDEFAULTAPPLICATIONLAUNCHER_H
  17. #include <service/application/ctkApplicationLauncher.h>
  18. #include <QSemaphore>
  19. #include <QVariant>
  20. class ctkPluginContext;
  21. /**
  22. * A ctkApplicationLauncher is used to launch ctkApplicationRunnable objects using
  23. * the main thread.
  24. * <p>
  25. * This class is for use by platform-related plug-ins which implement application containers.
  26. * Clients outside of the base platform should not reference or subclass this class.
  27. * </p>
  28. */
  29. class ctkDefaultApplicationLauncher : public QObject, public ctkApplicationLauncher
  30. {
  31. Q_OBJECT
  32. Q_INTERFACES(ctkApplicationLauncher)
  33. private:
  34. ctkApplicationRunnable* runnable;
  35. QVariant appContext;
  36. QSemaphore runningLock;
  37. QSemaphore waitForAppLock;
  38. ctkPluginContext* context;
  39. bool relaunch;
  40. bool failOnNoDefault;
  41. // FrameworkLog log;
  42. public:
  43. ctkDefaultApplicationLauncher(ctkPluginContext* context, bool relaunch, bool failOnNoDefault);
  44. /**
  45. * Starts this application launcher on the current thread. This method
  46. * should be called by the main thread to ensure that applications are
  47. * launched in the main thread.
  48. */
  49. QVariant start(const QVariant& defaultContext);
  50. /**
  51. * Launches the specified runnable using the main thread.
  52. * @param runnable a ParameterizedRunnalbe to run on the main thread.
  53. * @param context the context to launch the runnable with
  54. */
  55. void launch(ctkApplicationRunnable* app, const QVariant& applicationContext);
  56. /**
  57. * Forces the current runnable which is running to be stopped.
  58. * This method will return after the currently running ctkApplicationRunnable
  59. * has completely stopped.
  60. * <p>
  61. * After this method returns this ctkApplicationLauncher will no longer allow
  62. * applications to be launched.
  63. */
  64. void shutdown();
  65. /**
  66. * Similar to the start method this method will restart the default method on the current thread.
  67. * This method assumes that the default application was launched at least once and that a ctkApplicationDescriptor
  68. * exists that can be used to relaunch the default application.
  69. * @param argument the new context to re-start the default application with
  70. */
  71. QVariant reStart(const QVariant& argument);
  72. private:
  73. /*
  74. * Waits for an application to be launched and the runs the application on the
  75. * current thread (main).
  76. */
  77. QVariant runApplication(const QVariant& defaultContext);
  78. friend struct FreeResources;
  79. };
  80. #endif // CTKDEFAULTAPPLICATIONLAUNCHER_H