Wow, it seems to work now!

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