Trying to make the generic message handler to work

parent ec70a4d2
......@@ -37,11 +37,19 @@
#include <iostream>
#include "skproto.h"
void SkyliveProtocol::startPlugin()
{
std::cout << "SkyliveProtocol initialized in thread " << thread() << std::endl;
SKMessage::SKMessage prova("ANTANI STA PROVA!!");
sendMessage(prova);
handlers.registerHandler((QString)"connectTelescopes", &SkyliveProtocol::handle_connect);
}
void SkyliveProtocol::handle_connect(SKMessage::SKMessage msg)
{
std::cout << "SkyliveProtocol connect : " << msg.handle.toStdString() << std::endl;
}
void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg)
......
......@@ -37,15 +37,19 @@
#include "pluginsinterfaces.h"
#include "ipcmsg.h"
class SkyliveProtocol : public QObject, SkylivexPluginInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.skylivex.SkylivexPlugin/1.0" FILE "skproto.json")
Q_INTERFACES(SkylivexPluginInterface)
private:
SKHandlers::SKHandlers handlers;
public:
void startPlugin();
void sendMessage(SKMessage::SKMessage msg);
void handle_connect(SKMessage::SKMessage msg);
public slots:
void receiveMessage(SKMessage::SKMessage msg);
signals:
......
......@@ -38,7 +38,7 @@
#include <QString>
#include <iostream>
#include "ipcmsg.h"
#include "pluginsinterfaces.h"
SKMessage::SKMessage(QString s, QString h, QHash<QString, QString > p)
{
......@@ -74,7 +74,6 @@ SKMessage::SKMessage()
SKMessage::~SKMessage()
{
}
SKMessage::SKMessage(const SKMessage &other)
......@@ -84,3 +83,24 @@ SKMessage::SKMessage(const SKMessage &other)
parameters=other.parameters;
time=other.time;
}
SKHandlers::SKHandlers()
{
}
void SKHandlers::execute(SKMessage::SKMessage &msg)
{
//if(_handlers.contains(msg.handle))
// _handlers[msg.handle](msg);
}
void SKHandlers::registerHandler(QString type, SKHandlerFunction handler)
{
_handlers[type] = handler;
}
SKHandlers::~SKHandlers()
{
}
......@@ -64,4 +64,20 @@ class SKMessage
};
typedef void (*SKHandlerFunction)(SKMessage::SKMessage);
class SKHandlers
{
public:
SKHandlers();
~SKHandlers();
void registerHandler(QString type, SKHandlerFunction handler);
void execute(SKMessage::SKMessage &msg);
private:
QHash<QString, SKHandlerFunction> _handlers;
};
#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