Trying to make the generic message handler to work

parent ec70a4d2
...@@ -37,11 +37,19 @@ ...@@ -37,11 +37,19 @@
#include <iostream> #include <iostream>
#include "skproto.h" #include "skproto.h"
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!!"); SKMessage::SKMessage prova("ANTANI STA PROVA!!");
sendMessage(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) void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg)
......
...@@ -37,15 +37,19 @@ ...@@ -37,15 +37,19 @@
#include "pluginsinterfaces.h" #include "pluginsinterfaces.h"
#include "ipcmsg.h" #include "ipcmsg.h"
class SkyliveProtocol : public QObject, SkylivexPluginInterface class SkyliveProtocol : public QObject, SkylivexPluginInterface
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "com.skylivex.SkylivexPlugin/1.0" FILE "skproto.json") Q_PLUGIN_METADATA(IID "com.skylivex.SkylivexPlugin/1.0" FILE "skproto.json")
Q_INTERFACES(SkylivexPluginInterface) Q_INTERFACES(SkylivexPluginInterface)
private:
SKHandlers::SKHandlers handlers;
public: public:
void startPlugin(); void startPlugin();
void sendMessage(SKMessage::SKMessage msg); void sendMessage(SKMessage::SKMessage msg);
void handle_connect(SKMessage::SKMessage msg);
public slots: public slots:
void receiveMessage(SKMessage::SKMessage msg); void receiveMessage(SKMessage::SKMessage msg);
signals: signals:
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include <QString> #include <QString>
#include <iostream> #include <iostream>
#include "ipcmsg.h" #include "ipcmsg.h"
#include "pluginsinterfaces.h"
SKMessage::SKMessage(QString s, QString h, QHash<QString, QString > p) SKMessage::SKMessage(QString s, QString h, QHash<QString, QString > p)
{ {
...@@ -74,7 +74,6 @@ SKMessage::SKMessage() ...@@ -74,7 +74,6 @@ SKMessage::SKMessage()
SKMessage::~SKMessage() SKMessage::~SKMessage()
{ {
} }
SKMessage::SKMessage(const SKMessage &other) SKMessage::SKMessage(const SKMessage &other)
...@@ -84,3 +83,24 @@ SKMessage::SKMessage(const SKMessage &other) ...@@ -84,3 +83,24 @@ SKMessage::SKMessage(const SKMessage &other)
parameters=other.parameters; parameters=other.parameters;
time=other.time; 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 ...@@ -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 #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