|
Using PluginsCreating complex Disko applications or to share code between several different application is a difficult task. To make it a bit easiear Disko makes use of plugins which are added dynamically at runtime. This tutorial shows how plugins work and interact. To download the code for this tutorial, fetch it from the git-repository by issuing: git clone git://www.diskohq.org/disko-tutorials.git Then you can follow this part by having a look at the tutorials firststeps/06 folder. PrerequisitesDisko stores it plugin informations within an sqlite database. This database contains the filename and location of a plugin as well as plugin specific parameters. (see firststeps/05/scripts/createdb.sql What is a plugin?Pluigns are basically just shared libraries that implement a specific interface. There are four types of plugins that are used for different purposes:
How to create a plugin?Plugins are created by implementing one of the plugin interface classes: IMMSCentralPlugin, IMMSOSDPlugin, IMMSBackendPlugin, IMMSImportPlugin. The most simple backend plugin defintion looks as follows: class MyBackend : public IMMSBackend { public: bool initialize(MMSPluginData data, IMMSSwitcher *switcher); bool onEvent(IMMSEvent event); bool shutdown(); MyBackend(); ~MyBackend(); }; There are 3 methods that are essential for the backend plugin operation:
The Central and OSD Plugins have 2 additional methods that are ivoked for showing their contents. These will be discussed in a later tutorial. Plugin loadingThere is a special method that needs to be defined so that the plugin load procedure can be found by the plugin manager. For conveinience purposes we added some macros (MMS_EXPORT_BACKEND_PLUGIN, MMS_EXPORT_CENTRAL_PLUGIN, MMS_EXPORT_OSD_PLUGIN, MMS_EXPORT_IMPORT_PLUGIN) to do that. In our example this would be: MMS_EXPORT_BACKEND_PLUGIN(MyBackend); To enable the plugin within the disko application, some registration needs to be done in the configuration database: INSERT OR IGNORE INTO Plugins (PluginName, PluginTitle, PluginDescription, Filename, PluginPath, Active, Icon SelectedIcon, SmallIcon, SmallSelectedIcon, PluginTypeID, CategoryID, Orderpos) VALUES ("MyBackend", "", "my first backend plugin", "./plugins/mybackend/libmybackendplugin.so", "./plugins/mybackend/", "Y", "", "", "", "", (SELECT ID FROM PluginTypes WHERE (PluginTypeName = 'BACKEND_PLUGIN')), (SELECT ID FROM Category WHERE (CategoryName = 'NA')),-1); To register one ore more parameters for the plugin, some additional SQL is needed: -- optional plugin parameters INSERT OR IGNORE INTO PluginProperties (PluginID, Parameter, Value, TYPE, VALLIST, SEPARATOR) VALUES((select ID from Plugins WHERE PluginName = 'MyBackend'), "message", "hello world!", "string", "", ""); This defines a parameter named message for the freshly inserted backend plugin. |