Connect plugins with signals

parent a6f18bf4
......@@ -41,3 +41,14 @@ void SkyliveAuth::startPlugin()
std::cout << "SkyliveAuth initialized" << std::endl;
}
void SkyliveAuth::receiveMessage(std::string &msg)
{
std::cout << "SkyliveAuth receive" << msg << std::endl;
}
void SkyliveAuth::sendMessage(std::string &msg)
{
emit putMessage(msg);
}
......@@ -42,7 +42,13 @@ class SkyliveAuth : public QObject, SkylivexPluginInterface
Q_PLUGIN_METADATA(IID "com.skylivex.SkylivexPlugin/1.0" FILE "skauth.json")
Q_INTERFACES(SkylivexPluginInterface)
public:
void startPlugin();
public:
void startPlugin();
void sendMessage(std::string &msg);
public slots:
void receiveMessage(std::string &msg);
signals:
void putMessage(std::string &msg);
};
......@@ -39,5 +39,17 @@
void SkyliveProtocol::startPlugin()
{
std::cout << "SkyliveProtocol initialized" << std::endl;
std::string prova("ANTANI STA PROVA!!");
sendMessage(prova);
}
void SkyliveProtocol::receiveMessage(std::string &msg)
{
std::cout << "SkyliveProtocol receive" << msg << std::endl;
}
void SkyliveProtocol::sendMessage(std::string &msg)
{
emit putMessage(msg);
}
......@@ -42,7 +42,12 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
Q_PLUGIN_METADATA(IID "com.skylivex.SkylivexPlugin/1.0" FILE "skproto.json")
Q_INTERFACES(SkylivexPluginInterface)
public:
void startPlugin();
public:
void startPlugin();
void sendMessage(std::string &msg);
public slots:
void receiveMessage(std::string &msg);
signals:
void putMessage(std::string &msg);
};
......@@ -35,6 +35,7 @@
#ifndef PLUGINSINTERFACES_H
#define PLUGINSINTERFACES_H
#include <QtPlugin>
#include <iostream>
QT_BEGIN_NAMESPACE
class QStringList;
......@@ -46,6 +47,13 @@ class SkylivexPluginInterface
public:
virtual ~SkylivexPluginInterface() {}
virtual void startPlugin() = 0;
virtual void sendMessage(std::string) {}
public slots:
virtual void receiveMessage(std::string) {}
signals:
virtual void putMessage(std::string) {}
};
QT_BEGIN_NAMESPACE
......
......@@ -58,7 +58,7 @@ void SkyliveX::process()
{
//std::cout << "process" << std::endl;
std::string sarca("ANTANI!");
sendMsgToMainWin(sarca);
sendMessage(sarca);
}
......@@ -89,24 +89,43 @@ void SkyliveX::loadPlugins()
void SkyliveX::initializePlugin(QObject *plugin, QString filename)
{
// connect signals/slots
connect(plugin, SIGNAL(putMessage(std::string)), this, SLOT(receiveFromPlugins(std::string)));
connect(this, SIGNAL(msgForPlugins(std::string)), plugin, SLOT(receiveMessage(std::string)));
// Move the plugin in it's own thread
QThread* consumer = new QThread();
plugin->moveToThread(consumer);
consumer->start();
// Save plugin in the plugin list hash
skylivexPluginList.insert(filename, plugin);
// Cast the plugin skylivex interface
skylivexPluginInterface = qobject_cast<SkylivexPluginInterface *>(plugin);
if (skylivexPluginInterface)
{
std::cout << "Plugin file " << filename.toStdString() << " is valid." << std::endl;
// Create a new thread for the plugin
QThread* consumer = new QThread();
plugin->moveToThread(consumer);
consumer->start();
// Save plugin in the plugin list hash
skylivexPluginList.insert(filename, plugin);
// now the plugin can be initialized and used
// now the plugin can be initialized
skylivexPluginInterface->startPlugin();
}
}
void SkyliveX::sendMsgToMainWin(std::string &msg)
void SkyliveX::sendMessage(std::string &msg)
{
//std::cout << "Send To MainWin: " << msg << std::endl;
emit msgForMainWin(msg);
emit msgForPlugins(msg);
}
void SkyliveX::receiveFromMainWin(std::string &msg)
{
emit msgForPlugins(msg);
}
void SkyliveX::receiveFromPlugins(std::string &msg)
{
sendMessage(msg);
}
......@@ -61,15 +61,18 @@ class SkyliveX : public QObject
~SkyliveX() {}
void loadPlugins();
void initializePlugin(QObject*, QString);
void sendMessage(std::string &msg);
public slots:
void initialize();
void process();
void sendMsgToMainWin(std::string &msg);
void receiveFromMainWin(std::string &msg);
void receiveFromPlugins(std::string &msg);
signals:
void finished();
void msgForMainWin(std::string &msg);
void msgForPlugins(std::string &msg);
};
#endif
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