The following sections describe the steps that are required to create a plugin. For simplicity, a separate project is created and the generated binary will to be copied to the plugin directory of the given cube installation.
To create a cube plugins, a makefile and source files have to be generated. The makefile can be generated automatically from a Qt project file
First we specify the path to the "cube-config" script of the cube installation. This script delivers correct flags for compiling and linking.
qmake && make will build the first plugin example libExamplePluginSimple.so. The plugin will be copied to the plugin directory, e.g. /opt/cube/lib64/plugins.
The example describes a minimal cube plugin, which is inserted as an additional tab next to the SystemTree. It shows the text of the recently selected tree item. The complete source of the example can be found in
Every cube plugin has to derive from CubePlugin. To use Qt's signal and slot mechanism it also has to derive from QObject. If the plugin should be added as a tab next to a tree widget, it has to derive from TabInterface.
The class header is followed by the following macro definitions:
Q_OBJECT is required to handle signals and slots.
Q_INTERFACES( CubePlugin ) tells Qt that the class implements the CubePlugin interface and generates the method
qt_metacast(char*) to cast the plugin object to CubePlugin using the class name given as as character array.
Q_PLUGIN_METADATA()macro. The unique plugin name "SimpleExamplePlugin" is assigned. For Qt versions < 5.0,
Q_EXPORT_PLUGIN2has be be used (see Section 'SimpleExample.cpp' ).
The class SimpleExample has to implement all pure virtual methods from CubePlugin and TabInterface.
For Qt versions < 5.0,
Q_EXPORT_PLUGIN2 is used to export the plugin. The first argument is a unique name for the plugin, the second the name of the class.
cubeOpened(PluginServices* service) is the starting point of our plugin. Here we create the main widget, which should be added as a system tab. As our plugin derives from TabInterface, this is done by
If the user selects a tree item, service will emit a corresponding signal. To react on this event, the signal has to be connected to the slot
treeItemIsSelected() of our plugin class.
The function returns true, if the plugin should be started. It it returns false, the plugin is closed and deleted.
cubeClosed() is called if the cube file is closed or if the plugin is unloaded by the user. All resources which have been allocated in
cubeOpened have to be deleted here.
Each plugin has to set a version number. If several plugins with the same identifier (see function
name()) exist, the one with the highest version number will be loaded.
This function returns the unique plugin name. Only one plugin with this name will be loaded.
The following function returns a text to describe the plugin. It will be used by help menu of the cube GUI.
The following two functions contain the implementation of TabInterface.
widget() returns the QWidget that will be placed into the tab, which has been created with
label() returns the label of the new tab.
This method is a slot, which is called if a tree item is selected. The first arguments shows whether the selected item is part of a metric tree, call tree, flat view or system tree. The second argument provides information about the selected item.
|Copyright © 1998–2015 Forschungszentrum Jülich, Jülich Supercomputing Centre|