Plugin Coding Examples
From
Plugin coding examples
C++ using Qt
The three files shown below are the minimum requirement for compiling and using our own plugin in c++. Comments are inserted to help with readability, and explain some of the requirements
sampleplugin.h
#include "baseinterface.h" //Required, as all plugins must subclass from this
#include "ipcmessage.h" //IPC Message. Required for message parsing
class SamplePlugin : public BaseInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
public:
/*
* All independant init should happen in this function. This gets called as SOON as the
* plugin is loaded, but before it can talk to the core or any other plugins
*/
void init();
/*
* This function returns the name of the plugin, and only the name. This name must be
* unique among plugins.
*/
QString getName();
signals:
/*This signal is not used*/
void passCoreMessage(QString sender,QString message);
void passCoreMessage(QString sender,IPCMessage message);
void passCoreMessageBlocking(QString sender,IPCMessage message);
public slots:
/* This function is not used */
void passPluginMessage(QString sender,QString message);
/*
* This is the main message parser of a plugin. This is the slot that gets called whenever
* there is a message from the core or another plugin, being passed to your plugin
*/
void passPluginMessage(QString sender,IPCMessage message);
};
sampleplugin.cpp
#include "sampleplugin.h"
void SamplePlugin::init()
{
}
QString SamplePlugin::getName()
{
return "SamplePlugin";
}
void SamplePlugin::passPluginMessage(QString sender,QString message)
{
Q_UNUSED(sender)
Q_UNUSED(message)
}
void SamplePlugin::passPluginMessage(QString sender,IPCMessage message)
{
Q_UNUSED(sender)
if (message.getClass() == "event")
{
if (message.getMethod() == "initstarted")
{
passCoreMessage("SamplePlugin",IPCMessage("core","event","initstarted",QStringList()));
}
else if (message.getMethod() == "initcomplete")
{
passCoreMessage("SamplePlugin",IPCMessage("core","event","initcomplete",QStringList()));
}
else if (message.getMethod() == "initclose")
{
passCoreMessage("SamplePlugin",IPCMessage("core","event","initclose",QStringList()));
}
else if (message.getMethod() == "throw")
{
}
}
}
Q_EXPORT_PLUGIN2(SamplePluginPlugin, SamplePlugin)
sampleplugin.pro
TEMPLATE = lib TARGET = SamplePluginPlugin DEPENDPATH += . INCLUDEPATH += . ../../revfe CONFIG += plugin win32:DESTDIR = ../../revfe/debug/plugins/ unix:DESTDIR = ../../revfe/plugins/ CONFIG += embed_manifest_exe # Input HEADERS += sampleplugin.h ../../revfe/baseinterface.h SOURCES += sampleplugin.cpp ../../revfe/ipcmessage.cpp unix:target.path = /usr/share/revfe/plugins/ unix:INSTALLS += target
