Add message dispatcher to mainWin and setup connectTelescpes message

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