Wow, it seems to work now!

parent 0500997e
......@@ -38,12 +38,13 @@
#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);
registerHandler((QString)"connectTelescopes", &SkyliveProtocol::handle_connect);
}
......@@ -62,3 +63,19 @@ void SkyliveProtocol::sendMessage(SKMessage::SKMessage msg)
emit putMessage(msg);
}
void SkyliveProtocol::execute(SKMessage::SKMessage &msg)
{
if(_handlers.contains(msg.handle))
{
SKHandlerFunction mf =_handlers[msg.handle];
(this->*mf)(msg);
}
}
void SkyliveProtocol::registerHandler(QString type, SKHandlerFunction handler)
{
_handlers[type] = handler;
}
......@@ -34,9 +34,12 @@
*/
#include <QObject>
#include <QtPlugin>
#include <QHash>
#include "pluginsinterfaces.h"
#include "ipcmsg.h"
class SkyliveProtocol;
typedef void (SkyliveProtocol::*SKHandlerFunction)(SKMessage::SKMessage);
class SkyliveProtocol : public QObject, SkylivexPluginInterface
{
......@@ -45,13 +48,18 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
Q_INTERFACES(SkylivexPluginInterface)
private:
SKHandlers::SKHandlers handlers;
QHash<QString, SKHandlerFunction> _handlers;
public:
void startPlugin();
void sendMessage(SKMessage::SKMessage msg);
void registerHandler(QString type, SKHandlerFunction handler);
void execute(SKMessage::SKMessage &msg);
void handle_connect(SKMessage::SKMessage msg);
public slots:
void receiveMessage(SKMessage::SKMessage msg);
signals:
void putMessage(SKMessage::SKMessage msg);
};
......
......@@ -84,23 +84,3 @@ SKMessage::SKMessage(const SKMessage &other)
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,20 +64,4 @@ 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