Add message dispatcher to mainWin and setup connectTelescpes message

parent 79e46b4d
...@@ -42,8 +42,6 @@ ...@@ -42,8 +42,6 @@
void SkyliveProtocol::startPlugin() void SkyliveProtocol::startPlugin()
{ {
std::cout << "SkyliveProtocol initialized in thread " << thread() << std::endl; std::cout << "SkyliveProtocol initialized in thread " << thread() << std::endl;
SKMessage::SKMessage prova("ANTANI STA PROVA!!");
sendMessage(prova);
registerHandler((QString)"connectTelescopes", &SkyliveProtocol::handle_connect); registerHandler((QString)"connectTelescopes", &SkyliveProtocol::handle_connect);
} }
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <QWebView> #include <QWebView>
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QString>
#include <QPalette> #include <QPalette>
#include <iostream> #include <iostream>
#include "ipcmsg.h" #include "ipcmsg.h"
...@@ -58,7 +59,7 @@ MainWin::MainWin(QFile &htmlfile) ...@@ -58,7 +59,7 @@ MainWin::MainWin(QFile &htmlfile)
setHtml(htmlFileName, baseUrl); setHtml(htmlFileName, baseUrl);
resize(250,200); resize(250,200);
registerHandler((QString)"coreStarted", &MainWin::handle_corestarted);
} }
MainWin::~MainWin() MainWin::~MainWin()
...@@ -69,4 +70,29 @@ MainWin::~MainWin() ...@@ -69,4 +70,29 @@ MainWin::~MainWin()
void MainWin::msgFromCore(SKMessage::SKMessage &msg) void MainWin::msgFromCore(SKMessage::SKMessage &msg)
{ {
std::cout << "MainWindow msg reveived: " << msg.handle.toStdString() << std::endl; std::cout << "MainWindow msg reveived: " << msg.handle.toStdString() << std::endl;
if(_handlers.contains(msg.handle))
{
SKHandlerFunction mf =_handlers[msg.handle];
(this->*mf)(msg);
}
}
void MainWin::sendMessage(SKMessage::SKMessage &msg)
{
emit putMessage(msg);
}
void MainWin::registerHandler(QString type, SKHandlerFunction handler)
{
_handlers[type] = handler;
}
void MainWin::handle_corestarted(SKMessage::SKMessage &msg)
{
msg.handle = "connectTelescopes";
sendMessage(msg);
} }
...@@ -38,10 +38,16 @@ ...@@ -38,10 +38,16 @@
#include <QWebView> #include <QWebView>
#include <QUrl> #include <QUrl>
#include <QFile> #include <QFile>
#include <QHash>
#include <QString> #include <QString>
#include <QObject> #include <QObject>
#include <ipcmsg.h> #include <ipcmsg.h>
class MainWin; // forward declaration for typedef
// This is for member pointers to map messages
typedef void (MainWin::*SKHandlerFunction)(SKMessage::SKMessage&);
/* /*
* class MainWin * class MainWin
* This is just a little webkit transparent window * This is just a little webkit transparent window
...@@ -56,13 +62,22 @@ class MainWin : public QWebView ...@@ -56,13 +62,22 @@ class MainWin : public QWebView
QFile htmlfile; QFile htmlfile;
QString htmlFileName; QString htmlFileName;
private:
QHash<QString, SKHandlerFunction> _handlers;
public: public:
MainWin(QFile &htmlfile); MainWin(QFile &htmlfile);
~MainWin(); ~MainWin();
void sendMessage(SKMessage::SKMessage &msg);
void registerHandler(QString type, SKHandlerFunction handler);
void handle_corestarted(SKMessage::SKMessage &msg);
public slots: public slots:
void msgFromCore(SKMessage::SKMessage &msg); void msgFromCore(SKMessage::SKMessage &msg);
signals:
void putMessage(SKMessage::SKMessage msg);
}; };
......
...@@ -57,8 +57,6 @@ void SkyliveX::initialize() ...@@ -57,8 +57,6 @@ void SkyliveX::initialize()
void SkyliveX::process() void SkyliveX::process()
{ {
//SKMessage::SKMessage sarca("ANTANI!");
//sendMessage(sarca);
} }
...@@ -85,6 +83,8 @@ void SkyliveX::loadPlugins() ...@@ -85,6 +83,8 @@ void SkyliveX::loadPlugins()
std::cout << plugin << std::endl; std::cout << plugin << std::endl;
} }
} }
SKMessage::SKMessage msg("coreStarted");
sendMessage(msg);
} }
void SkyliveX::initializePlugin(QObject *plugin, QString filename) void SkyliveX::initializePlugin(QObject *plugin, QString filename)
......
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