Plugin loader ready

parent 934c7aa8
...@@ -3,7 +3,8 @@ SOURCES = src/main.cpp \ ...@@ -3,7 +3,8 @@ SOURCES = src/main.cpp \
src/skylivex.cpp # src/plugins.cpp src/skylivex.cpp # src/plugins.cpp
HEADERS = src/skylivex.h\ 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 QT += network webkitwidgets widgets
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
* Purpose: * Purpose:
* *
*/ */
#ifndef PLUGINSINTERFACES_H
#define PLUGINSINTERFACES_H
#include <QtPlugin> #include <QtPlugin>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
...@@ -51,3 +53,4 @@ QT_BEGIN_NAMESPACE ...@@ -51,3 +53,4 @@ QT_BEGIN_NAMESPACE
Q_DECLARE_INTERFACE(SkylivexPluginInterface, Q_DECLARE_INTERFACE(SkylivexPluginInterface,
"com.skylivex.SkylivexPlugin/1.0") "com.skylivex.SkylivexPlugin/1.0")
QT_END_NAMESPACE QT_END_NAMESPACE
#endif
...@@ -33,16 +33,63 @@ ...@@ -33,16 +33,63 @@
* *
*/ */
#include <QPluginLoader>
#include <QApplication>
#include <QDir>
#include <QObject>
#include <QString>
#include "skylivex.h" #include "skylivex.h"
#include "pluginsinterfaces.h"
#include <iostream> #include <iostream>
// Load and initialize plugins and shared memory communication
void SkyliveX::initialize() void SkyliveX::initialize()
{ {
std::cout << "antani" << std::endl; std::cout << "antani" << std::endl;
loadPlugins();
} }
// read messages from plugins and dispatch to others
void SkyliveX::process() 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 @@ ...@@ -36,7 +36,8 @@
#define SKYLIVEX_H #define SKYLIVEX_H
#include <QObject> #include <QObject>
#include <QString>
#include "pluginsinterfaces.h"
/* /*
* class SkyliveX * class SkyliveX
...@@ -48,14 +49,20 @@ class SkyliveX : public QObject ...@@ -48,14 +49,20 @@ class SkyliveX : public QObject
{ {
Q_OBJECT Q_OBJECT
private:
SkylivexPluginInterface *skylivexPluginInterface;
public: public:
SkyliveX(QObject *parent=0) : QObject(parent) {} SkyliveX(QObject *parent=0) : QObject(parent) {}
~SkyliveX() {} ~SkyliveX() {}
void loadPlugins();
void initializePlugin(QObject*, QString);
public slots: public slots:
void initialize(); void initialize();
void process(); void process();
signals: signals:
void finished(); 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