Plugin loader ready

parent 934c7aa8
......@@ -3,7 +3,8 @@ SOURCES = src/main.cpp \
src/skylivex.cpp # src/plugins.cpp
HEADERS = src/skylivex.h\
src/mainwin.h # src/plugins.h src/pluginsinterfaces.h
src/mainwin.h \ # src/plugins.h src/pluginsinterfaces.h
src/pluginsinterfaces.h
QT += network webkitwidgets widgets
......
......@@ -32,6 +32,8 @@
* Purpose:
*
*/
#ifndef PLUGINSINTERFACES_H
#define PLUGINSINTERFACES_H
#include <QtPlugin>
QT_BEGIN_NAMESPACE
......@@ -51,3 +53,4 @@ QT_BEGIN_NAMESPACE
Q_DECLARE_INTERFACE(SkylivexPluginInterface,
"com.skylivex.SkylivexPlugin/1.0")
QT_END_NAMESPACE
#endif
......@@ -33,16 +33,63 @@
*
*/
#include <QPluginLoader>
#include <QApplication>
#include <QDir>
#include <QObject>
#include <QString>
#include "skylivex.h"
#include "pluginsinterfaces.h"
#include <iostream>
// Load and initialize plugins and shared memory communication
void SkyliveX::initialize()
{
std::cout << "antani" << std::endl;
loadPlugins();
}
// read messages from plugins and dispatch to others
void SkyliveX::process()
{
std::cout << "process" << std::endl;
//std::cout << "process" << std::endl;
}
void SkyliveX::loadPlugins()
{
QDir pluginsDir = QDir(qApp->applicationDirPath());
pluginsDir.cd("plugins");
std::cout << "Try to load plugins in folder " << pluginsDir.path().toStdString() << std::endl;
foreach(QString fileName, pluginsDir.entryList(QDir::Files))
{
std::cout << "Testing " << pluginsDir.absoluteFilePath(fileName).toStdString() << std::endl;
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
QObject *plugin = loader.instance();
if (plugin)
{
std::cout << "Loading " << fileName.toStdString() << std::endl;
initializePlugin(plugin, fileName);
//pluginFileNames += fileName;SkylivexPluginInterface
}
else
{
std::cout << loader.errorString().toStdString() << std::endl;
std::cout << plugin << std::endl;
}
}
}
void SkyliveX::initializePlugin(QObject *plugin, QString filename)
{
skylivexPluginInterface = qobject_cast<SkylivexPluginInterface *>(plugin);
if (skylivexPluginInterface)
{
std::cout << "Plugin file " << filename.toStdString() << " is valid." << std::endl;
// now the plugin can be initialized and used
}
}
......@@ -36,7 +36,8 @@
#define SKYLIVEX_H
#include <QObject>
#include <QString>
#include "pluginsinterfaces.h"
/*
* class SkyliveX
......@@ -48,14 +49,20 @@ class SkyliveX : public QObject
{
Q_OBJECT
private:
SkylivexPluginInterface *skylivexPluginInterface;
public:
SkyliveX(QObject *parent=0) : QObject(parent) {}
~SkyliveX() {}
void loadPlugins();
void initializePlugin(QObject*, QString);
public slots:
void initialize();
void process();
signals:
void finished();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment