ctkPluginActivator.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 CTKPLUGINACTIVATOR_H_
  16. #define CTKPLUGINACTIVATOR_H_
  17. #include "ctkPluginContext.h"
  18. namespace ctk {
  19. /**
  20. * Customizes the starting and stopping of a plugin.
  21. * <p>
  22. * <code>%PluginActivator</code> is an interface that must be implemented by
  23. * every plugin in the Framework. The Framework can create instances of a
  24. * plugin's <code>%PluginActivator</code> as required. If an instance's
  25. * <code>PluginActivator::start</code> method executes successfully, it is
  26. * guaranteed that the same instance's <code>PluginActivator::stop</code>
  27. * method will be called when the plugin is to be stopped. The Framework must
  28. * not concurrently call a <code>%PluginActivator</code> object.
  29. *
  30. * <p>
  31. * <code>%PluginActivator</code> is a Qt interface which must be implemented
  32. * using the standard Qt %Plugin facilities:
  33. *
  34. * <p>
  35. * <pre>
  36. * class MyPlugin : public QObject, public %ctk::PluginActivator
  37. * {
  38. * Q_OBJECT
  39. * Q_INTERFACES(ctk::PluginActivator)
  40. *
  41. * public:
  42. * void %start(%ctk::PluginContext* context);
  43. * void %stop(%ctk::PluginContext* context);
  44. * };
  45. * </pre>
  46. * And in your implementation file:
  47. * <pre>
  48. * Q_EXPORT_PLUGIN2(mypluginlib, MyPlugin)
  49. * </pre>
  50. * where <code>mypluginlib</code> is the basename of your shared plugin library.
  51. *
  52. * <p>
  53. * See the Qt Documentation about <a href="http://doc.trolltech.com/4.6/plugins-howto.html">
  54. * How to Create Qt Plugins</a> for details.
  55. *
  56. * The class implementing the <code>%PluginActivator</code> interface must have a public
  57. * constructor that takes no parameters so that a <code>%PluginActivator</code>
  58. * object can be created by <code>QPluginLoader::instance</code>.
  59. *
  60. */
  61. class PluginActivator
  62. {
  63. public:
  64. virtual ~PluginActivator() {}
  65. /**
  66. * Called when this plugin is started so the Framework can perform the
  67. * plugin-specific activities necessary to start this plugin. This method
  68. * can be used to register services or to allocate any resources that this
  69. * plugin needs.
  70. *
  71. * <p>
  72. * This method must complete and return to its caller in a timely manner.
  73. *
  74. * @param context The execution context of the plugin being started.
  75. * @throws std::exception If this method throws an exception, this
  76. * plugin is marked as stopped and the Framework will remove this
  77. * plugin's listeners, unregister all services registered by this
  78. * plugin, and release all services used by this plugin.
  79. */
  80. virtual void start(PluginContext* context) = 0;
  81. /**
  82. * Called when this plugin is stopped so the Framework can perform the
  83. * plugin-specific activities necessary to stop the plugin. In general, this
  84. * method should undo the work that the <code>PluginActivator::start</code>
  85. * method started. There should be no active threads that were started by
  86. * this plugin when this plugin returns. A stopped plugin must not call any
  87. * Framework objects.
  88. *
  89. * <p>
  90. * This method must complete and return to its caller in a timely manner.
  91. *
  92. * @param context The execution context of the plugin being stopped.
  93. * @throws std::exception If this method throws an exception, the
  94. * plugin is still marked as stopped, and the Framework will remove
  95. * the plugin's listeners, unregister all services registered by the
  96. * plugin, and release all services used by the plugin.
  97. */
  98. virtual void stop(PluginContext* context) = 0;
  99. };
  100. }
  101. Q_DECLARE_INTERFACE(ctk::PluginActivator, "org.commontk.pluginfw.pluginactivator")
  102. #endif /* CTKPLUGINACTIVATOR_H_ */