ctkPluginFramework_p.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 CTKPLUGINFRAMEWORKPRIVATE_P_H
  16. #define CTKPLUGINFRAMEWORKPRIVATE_P_H
  17. #include <QMutex>
  18. #include "ctkPlugin_p.h"
  19. #include "ctkPluginFramework.h"
  20. #include "ctkServiceRegistration.h"
  21. class ctkPluginFrameworkContext;
  22. /**
  23. * \ingroup PluginFramework
  24. */
  25. class ctkPluginFrameworkPrivate : public ctkPluginPrivate
  26. {
  27. public:
  28. /**
  29. * Holds all information for constructing a ctkPluginFrameworkEvent instance,
  30. * except for holding a QSharedPointer to the framework plug-in. This avoids
  31. * cyclic references in ctkPluginFramework.
  32. */
  33. struct FWEventWrapper
  34. {
  35. FWEventWrapper() : isNull(true) {}
  36. bool isNull;
  37. ctkPluginFrameworkEvent::Type type;
  38. };
  39. /**
  40. * The event to return to callers waiting in ctkPluginFramework::waitForStop()
  41. * when the framework has been stopped.
  42. */
  43. FWEventWrapper stopEvent;
  44. /**
  45. * The flag indicating that the thread that performs shutdown of this
  46. * framework instance is running.
  47. */
  48. QAtomicInt shuttingDown;
  49. /**
  50. * Lock object
  51. */
  52. LockObject lock;
  53. ctkPluginFrameworkPrivate(QWeakPointer<ctkPlugin> qq, ctkPluginFrameworkContext* fw);
  54. void init();
  55. void initSystemPlugin();
  56. void activate(ctkPluginContext* context);
  57. void deactivate(ctkPluginContext* context);
  58. void uninitSystemPlugin();
  59. /**
  60. * This method starts a thread that stops this Framework,
  61. * stopping all started plug-ins.
  62. *
  63. * <p>If the framework is not started, this method does nothing.
  64. * If the framework is started, this method will:
  65. * <ol>
  66. * <li>Set the state of the ctkPluginFrameworkContext to <i>inactive</i>.</li>
  67. * <li>Suspended all started plug-ins as described in the
  68. * {@link ctkPlugin#stop()} method except that the persistent
  69. * state of the plug-in will continue to be started.
  70. * Reports any exceptions that occur during stopping using
  71. * <code>ctkPluginFramework</code>s.</li>
  72. * <li>Disable event handling.</li>
  73. * </ol></p>
  74. *
  75. */
  76. void shutdown(bool restart);
  77. QHash<QString, QString> systemHeaders;
  78. private:
  79. QList<ctkServiceRegistration> registrations;
  80. /**
  81. * Stop this FrameworkContext, suspending all started contexts.
  82. * This method suspends all started contexts so that they can be
  83. * automatically restarted when this FrameworkContext is next launched.
  84. *
  85. * <p>If the framework is not started, this method does nothing.
  86. * If the framework is started, this method will:
  87. * <ol>
  88. * <li>Set the state of the FrameworkContext to <i>inactive</i>.</li>
  89. * <li>Stop all started bundles as described in the
  90. * {@link Bundle#stop(int)} method except that the persistent
  91. * state of the bundle will continue to be started.
  92. * Reports any exceptions that occur during stopping using
  93. * <code>FrameworkErrorEvents</code>.</li>
  94. * <li>Disable event handling.</li>
  95. * </ol>
  96. * </p>
  97. *
  98. */
  99. void shutdown0(bool restart, bool wasActive);
  100. /**
  101. * Tell system plugin shutdown finished.
  102. */
  103. void shutdownDone_unlocked(bool restart);
  104. /**
  105. * Stop and unresolve all plug-ins.
  106. */
  107. void stopAllPlugins();
  108. /**
  109. * Shutting down is done.
  110. */
  111. void systemShuttingdownDone(const ctkPluginFrameworkEvent& fe);
  112. void systemShuttingdownDone_unlocked(const ctkPluginFrameworkEvent& fe);
  113. };
  114. #endif // CTKPLUGINFRAMEWORKPRIVATE_P_H