added SKMessage object and declared it as qmetatype for IPC

parent ecab3de6
...@@ -33,21 +33,22 @@ ...@@ -33,21 +33,22 @@
* *
*/ */
#include "pluginsinterfaces.h" #include "pluginsinterfaces.h"
#include "ipcmsg.h"
#include <iostream> #include <iostream>
#include "skauth.h" #include "skauth.h"
void SkyliveAuth::startPlugin() void SkyliveAuth::startPlugin()
{ {
std::cout << "SkyliveAuth initialized" << std::endl; std::cout << "SkyliveAuth initialized in thread " << thread() << std::endl;
} }
void SkyliveAuth::receiveMessage(std::string msg) void SkyliveAuth::receiveMessage(SKMessage::SKMessage msg)
{ {
std::cout << "SkyliveAuth receive" << msg << std::endl; std::cout << "SkyliveAuth receive" << msg.handle << std::endl;
} }
void SkyliveAuth::sendMessage(std::string msg) void SkyliveAuth::sendMessage(SKMessage::SKMessage msg)
{ {
emit putMessage(msg); emit putMessage(msg);
} }
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <QObject> #include <QObject>
#include <QtPlugin> #include <QtPlugin>
#include "pluginsinterfaces.h" #include "pluginsinterfaces.h"
#include "ipcmsg.h"
class SkyliveAuth : public QObject, SkylivexPluginInterface class SkyliveAuth : public QObject, SkylivexPluginInterface
{ {
...@@ -44,11 +45,11 @@ class SkyliveAuth : public QObject, SkylivexPluginInterface ...@@ -44,11 +45,11 @@ class SkyliveAuth : public QObject, SkylivexPluginInterface
public: public:
void startPlugin(); void startPlugin();
void sendMessage(std::string msg); void sendMessage(SKMessage::SKMessage msg);
public slots: public slots:
void receiveMessage(std::string msg); void receiveMessage(SKMessage::SKMessage msg);
signals: signals:
void putMessage(std::string msg); void putMessage(SKMessage::SKMessage msg);
}; };
TEMPLATE = lib TEMPLATE = lib
SOURCES = skauth.cpp SOURCES = skauth.cpp ../src/ipcmsg.cpp
CONFIG += plugin CONFIG += plugin
HEADERS = skauth.h HEADERS = skauth.h ../src/ipcmsg.h
INCLUDEPATH = ../src INCLUDEPATH = ../src
QT += core network widgets QT += core network widgets
DESTDIR = ../build/plugins DESTDIR = ../build/plugins
...@@ -33,22 +33,23 @@ ...@@ -33,22 +33,23 @@
* *
*/ */
#include "pluginsinterfaces.h" #include "pluginsinterfaces.h"
#include "ipcmsg.h"
#include <iostream> #include <iostream>
#include "skproto.h" #include "skproto.h"
void SkyliveProtocol::startPlugin() void SkyliveProtocol::startPlugin()
{ {
std::cout << "SkyliveProtocol initialized" << std::endl; std::cout << "SkyliveProtocol initialized in thread " << thread() << std::endl;
std::string prova("ANTANI STA PROVA!!"); std::string prova("ANTANI STA PROVA!!");
sendMessage(prova); sendMessage(prova);
} }
void SkyliveProtocol::receiveMessage(std::string msg) void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg)
{ {
std::cout << "SkyliveProtocol receive" << msg << std::endl; std::cout << "SkyliveProtocol receive" << msg.handle << std::endl;
} }
void SkyliveProtocol::sendMessage(std::string msg) void SkyliveProtocol::sendMessage(SKMessage::SKMessage msg)
{ {
emit putMessage(msg); emit putMessage(msg);
} }
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <QObject> #include <QObject>
#include <QtPlugin> #include <QtPlugin>
#include "pluginsinterfaces.h" #include "pluginsinterfaces.h"
#include "ipcmsg.h"
class SkyliveProtocol : public QObject, SkylivexPluginInterface class SkyliveProtocol : public QObject, SkylivexPluginInterface
{ {
...@@ -44,10 +45,10 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface ...@@ -44,10 +45,10 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
public: public:
void startPlugin(); void startPlugin();
void sendMessage(std::string msg); void sendMessage(SKMessage::SKMessage msg);
public slots: public slots:
void receiveMessage(std::string msg); void receiveMessage(SKMessage::SKMessage msg);
signals: signals:
void putMessage(std::string msg); void putMessage(SKMessage::SKMessage msg);
}; };
TEMPLATE = lib TEMPLATE = lib
SOURCES = skproto.cpp SOURCES = skproto.cpp ../src/ipcmsg.cpp
CONFIG += plugin CONFIG += plugin
HEADERS = skproto.h HEADERS = skproto.h ../src/ipcmsg.h
INCLUDEPATH = ../src INCLUDEPATH = ../src
QT += core network widgets QT += core network widgets
DESTDIR = ../build/plugins DESTDIR = ../build/plugins
/* ____ _ _ _ __ __
* / ___|| | ___ _| (_)_ _____\ \/ /
* \___ \| |/ / | | | | \ \ / / _ \\ /
* ___) | <| |_| | | |\ V / __// \ Remote Telescopes
* |____/|_|\_\\__, |_|_| \_/ \___/_/\_\ For the masses
* |___/
*
* Copyright (C) 2013 Franco (nextime) Lanza <nextime@nexlab.it>
* Copyright (C) 2013 Ivan Bellia <skylive@skylive.it>
*
* All rights reserved.
*
* This file is part of SkyliveX.
*
* SkyliveX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Foobar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*
********************************************************************
*
* File:
*
* Purpose:
*
*/
#include <QTime>
#include <QHash>
#include <iostream>
#include "ipcmsg.h"
SKMessage::SKMessage(std::string s, std::string h, QHash<std::string, std::string > p)
{
handle=h;
sender=s;
parameters=p;
time = QTime::currentTime();
std::cout << "SKMessage initialized " << handle << std::endl;
}
SKMessage::SKMessage(std::string h, QHash<std::string, std::string > p)
{
sender= std::string("unknown");
time = QTime::currentTime();
parameters = p;
handle = h;
}
SKMessage::SKMessage(std::string h)
{
sender= std::string("unknown");
handle = h;
time = QTime::currentTime();
}
SKMessage::SKMessage()
{
sender= std::string("unknown");
handle = std::string("none");
time = QTime::currentTime();
}
SKMessage::~SKMessage()
{
}
SKMessage::SKMessage(const SKMessage &other)
{
handle=other.handle;
sender=other.sender;
parameters=other.parameters;
time=other.time;
}
/* ____ _ _ _ __ __
* / ___|| | ___ _| (_)_ _____\ \/ /
* \___ \| |/ / | | | | \ \ / / _ \\ /
* ___) | <| |_| | | |\ V / __// \ Remote Telescopes
* |____/|_|\_\\__, |_|_| \_/ \___/_/\_\ For the masses
* |___/
*
* Copyright (C) 2013 Franco (nextime) Lanza <nextime@nexlab.it>
* Copyright (C) 2013 Ivan Bellia <skylive@skylive.it>
*
* All rights reserved.
*
* This file is part of SkyliveX.
*
* SkyliveX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Foobar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*
********************************************************************
*
* File:
*
* Purpose:
*
*/
#ifndef IPCMSG_H
#define IPCMSG_H
#include <QTime>
#include <QHash>
#include <iostream>
/*
* SKMessage
* An object representing an IPC message
* between threads
*/
class SKMessage
{
public:
SKMessage();
SKMessage(const SKMessage &other);
~SKMessage();
QTime time;
std::string sender;
std::string handle;
QHash<std::string, std::string > parameters;
SKMessage(std::string s, std::string h, QHash<std::string, std::string > p);
SKMessage(std::string h, QHash<std::string, std::string > p);
SKMessage(std::string h);
};
#endif
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <QTimer> #include <QTimer>
#include "mainwin.h" #include "mainwin.h"
#include "skylivex.h" #include "skylivex.h"
#include "ipcmsg.h"
/* /*
...@@ -78,7 +79,7 @@ int main(int argc, char *argv[]) ...@@ -78,7 +79,7 @@ int main(int argc, char *argv[])
// connect core with the mainwin // connect core with the mainwin
//QObject::connect(skx, SIGNAL(msgForMainWin(std::string&)), &mainw, SLOT(msgFromCore(std::string&)), Qt::QueuedConnection); //QObject::connect(skx, SIGNAL(msgForMainWin(std::string&)), &mainw, SLOT(msgFromCore(std::string&)), Qt::QueuedConnection);
QObject::connect(skx, SIGNAL(msgForMainWin(std::string&)), &mainw, SLOT(msgFromCore(std::string&))); QObject::connect(skx, SIGNAL(msgForMainWin(SKMessage::SKMessage&)), &mainw, SLOT(msgFromCore(SKMessage::SKMessage&)));
// and then.. go! // and then.. go!
return skylivexapp.exec(); return skylivexapp.exec();
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <QDir> #include <QDir>
#include <QPalette> #include <QPalette>
#include <iostream> #include <iostream>
#include "ipcmsg.h"
MainWin::MainWin(QFile &htmlfile) MainWin::MainWin(QFile &htmlfile)
: QWebView(0) : QWebView(0)
...@@ -65,7 +66,7 @@ MainWin::~MainWin() ...@@ -65,7 +66,7 @@ MainWin::~MainWin()
} }
void MainWin::msgFromCore(std::string &msg) void MainWin::msgFromCore(SKMessage::SKMessage &msg)
{ {
std::cout << "Message from core: " << msg << std::endl; std::cout << "Message from core: " << msg.handle << std::endl;
} }
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <QFile> #include <QFile>
#include <QString> #include <QString>
#include <QObject> #include <QObject>
#include <ipcmsg.h>
/* /*
* class MainWin * class MainWin
...@@ -60,7 +61,7 @@ class MainWin : public QWebView ...@@ -60,7 +61,7 @@ class MainWin : public QWebView
~MainWin(); ~MainWin();
public slots: public slots:
void msgFromCore(std::string &msg); void msgFromCore(SKMessage::SKMessage &msg);
}; };
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#define PLUGINSINTERFACES_H #define PLUGINSINTERFACES_H
#include <QtPlugin> #include <QtPlugin>
#include <iostream> #include <iostream>
#include "ipcmsg.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QStringList; class QStringList;
...@@ -47,13 +48,13 @@ class SkylivexPluginInterface ...@@ -47,13 +48,13 @@ class SkylivexPluginInterface
public: public:
virtual ~SkylivexPluginInterface() {} virtual ~SkylivexPluginInterface() {}
virtual void startPlugin() = 0; virtual void startPlugin() = 0;
virtual void sendMessage(std::string) {} virtual void sendMessage(SKMessage) {}
public slots: public slots:
virtual void receiveMessage(std::string) {} virtual void receiveMessage(SKMessage) {}
signals: signals:
virtual void putMessage(std::string) {} virtual void putMessage(SKMessage) {}
}; };
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
......
...@@ -42,15 +42,15 @@ ...@@ -42,15 +42,15 @@
#include "skylivex.h" #include "skylivex.h"
#include "pluginsinterfaces.h" #include "pluginsinterfaces.h"
#include <iostream> #include <iostream>
#include "ipcmsg.h"
Q_DECLARE_METATYPE(std::string) Q_DECLARE_METATYPE(SKMessage::SKMessage)
// Load and initialize plugins and shared memory communication // Load and initialize plugins and shared memory communication
void SkyliveX::initialize() void SkyliveX::initialize()
{ {
std::cout << "antani" << std::endl; qRegisterMetaType<SKMessage::SKMessage>("SKMessage::SKMessage");
qRegisterMetaType<std::string>("std::string");
loadPlugins(); loadPlugins();
} }
...@@ -58,8 +58,7 @@ void SkyliveX::initialize() ...@@ -58,8 +58,7 @@ void SkyliveX::initialize()
// read messages from plugins and dispatch to others // read messages from plugins and dispatch to others
void SkyliveX::process() void SkyliveX::process()
{ {
//std::cout << "process" << std::endl; SKMessage::SKMessage sarca("ANTANI!");
std::string sarca("ANTANI!");
sendMessage(sarca); sendMessage(sarca);
} }
...@@ -93,8 +92,8 @@ void SkyliveX::initializePlugin(QObject *plugin, QString filename) ...@@ -93,8 +92,8 @@ void SkyliveX::initializePlugin(QObject *plugin, QString filename)
{ {
// connect signals/slots // connect signals/slots
connect(plugin, SIGNAL(putMessage(std::string)), this, SLOT(receiveFromPlugins(std::string))); connect(plugin, SIGNAL(putMessage(SKMessage::SKMessage)), this, SLOT(receiveFromPlugins(SKMessage::SKMessage)));
connect(this, SIGNAL(msgForPlugins(std::string)), plugin, SLOT(receiveMessage(std::string))); connect(this, SIGNAL(msgForPlugins(SKMessage::SKMessage)), plugin, SLOT(receiveMessage(SKMessage::SKMessage)));
// Move the plugin in it's own thread // Move the plugin in it's own thread
QThread* consumer = new QThread(); QThread* consumer = new QThread();
...@@ -114,7 +113,7 @@ void SkyliveX::initializePlugin(QObject *plugin, QString filename) ...@@ -114,7 +113,7 @@ void SkyliveX::initializePlugin(QObject *plugin, QString filename)
} }
} }
void SkyliveX::sendMessage(std::string &msg) void SkyliveX::sendMessage(SKMessage::SKMessage &msg)
{ {
//std::cout << "Send To MainWin: " << msg << std::endl; //std::cout << "Send To MainWin: " << msg << std::endl;
emit msgForMainWin(msg); emit msgForMainWin(msg);
...@@ -122,12 +121,12 @@ void SkyliveX::sendMessage(std::string &msg) ...@@ -122,12 +121,12 @@ void SkyliveX::sendMessage(std::string &msg)
} }
void SkyliveX::receiveFromMainWin(std::string &msg) void SkyliveX::receiveFromMainWin(SKMessage::SKMessage &msg)
{ {
emit msgForPlugins(msg); emit msgForPlugins(msg);
} }
void SkyliveX::receiveFromPlugins(std::string msg) void SkyliveX::receiveFromPlugins(SKMessage::SKMessage msg)
{ {
sendMessage(msg); sendMessage(msg);
} }
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "pluginsinterfaces.h" #include "pluginsinterfaces.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "ipcmsg.h"
/* /*
* class SkyliveX * class SkyliveX
...@@ -61,18 +62,18 @@ class SkyliveX : public QObject ...@@ -61,18 +62,18 @@ class SkyliveX : public QObject
~SkyliveX() {} ~SkyliveX() {}
void loadPlugins(); void loadPlugins();
void initializePlugin(QObject*, QString); void initializePlugin(QObject*, QString);
void sendMessage(std::string &msg); void sendMessage(SKMessage::SKMessage &msg);
public slots: public slots:
void initialize(); void initialize();
void process(); void process();
void receiveFromMainWin(std::string &msg); void receiveFromMainWin(SKMessage::SKMessage &msg);
void receiveFromPlugins(std::string msg); void receiveFromPlugins(SKMessage::SKMessage msg);
signals: signals:
void finished(); void finished();
void msgForMainWin(std::string &msg); void msgForMainWin(SKMessage::SKMessage &msg);
void msgForPlugins(std::string msg); void msgForPlugins(SKMessage::SKMessage msg);
}; };
#endif #endif
SOURCES = main.cpp \ SOURCES = main.cpp \
mainwin.cpp \ mainwin.cpp \
skylivex.cpp skylivex.cpp \
ipcmsg.cpp
HEADERS = skylivex.h \ HEADERS = skylivex.h \
mainwin.h \ mainwin.h \
pluginsinterfaces.h pluginsinterfaces.h \
ipcmsg.h
QT += core network webkitwidgets widgets QT += core network webkitwidgets widgets
......
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