A plugin is a shared library. The application keeps the interface type. The concrete class is compiled into the library. No extra base class is required beyond that interface.
The library exports a null-terminated array of PluginId named PluginList. The export uses C linkage so the loader can resolve a stable symbol. PluginManager looks up that name through a Library.
Each entry is a Plugin that creates and destroys instances of one interface. BasicPlugin is the usual plugin. The first template argument is the concrete class. The second is the interface it implements. It constructs with new and destroys with delete.
The constructor takes a feature string that names the instance for later construction. The address of the BasicPlugin is placed in PluginList.
Several plugins may share one PluginList. A second concrete class for the same interface is another BasicPlugin in the same array.
A plugin that needs another allocator derives from Plugin and overrides create and destroy.
PluginManager loads a PluginList through a Library and creates instances by feature. The application loads and unloads plugins through the manager.
The instance is created and destroyed through the manager, not with delete. Loaded libraries unload when the manager is destroyed.
Classes | |
| class | PluginId |
| ID for plugin exports. More... | |
| class | Plugin< Iface > |
| Interface for plugins. More... | |
| class | BasicPlugin< Class, Iface > |
| A plugin implementation. More... | |
| class | PluginManager< IfaceT, PluginT > |
| Manages loaded plugins. More... | |