ctkPluginActivator.h 4.3 KB

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