ctkPluginActivator.h 4.3 KB

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