Initial stesure of the protocol parser

parent 0cb02de2
function changeContent(id, content) function changeContent(id, content)
{ {
document.getElementById(id).innerHTML=content; var n=document.getElementById(id);
if(typeof(n)!="undefined")
n.innerHTML=content;
}
function notify(content)
{
if(typeof(notifycb)=="function")
notifycb(content);
} }
SkyliveX.changeContent.connect(changeContent); SkyliveX.changeContent.connect(changeContent);
SkyliveX.notify.connect(notify);
<html> <html>
<head> <head>
<title>SkyliveX</title> <title>SkyliveX</title>
<script type="text/javascript">
function notifycb(content)
{
document.getElementById("loadstring").innerHTML=content;
}
</script>
<script type="text/javascript" src="SkyliveX.js"></script> <script type="text/javascript" src="SkyliveX.js"></script>
<style> <style>
#loading { #loading {
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
void SkyliveProtocol::startPlugin() void SkyliveProtocol::startPlugin()
{ {
SM_TCPCLIENT = HOME;
std::cout << "SkyliveProtocol initialized in thread " << thread() << std::endl; std::cout << "SkyliveProtocol initialized in thread " << thread() << std::endl;
registerHandler((QString)"connectTelescopes", &SkyliveProtocol::handle_connect); registerHandler((QString)"connectTelescopes", &SkyliveProtocol::handle_connect);
} }
...@@ -49,22 +50,25 @@ void SkyliveProtocol::startPlugin() ...@@ -49,22 +50,25 @@ void SkyliveProtocol::startPlugin()
void SkyliveProtocol::readFromNetwork() void SkyliveProtocol::readFromNetwork()
{ {
char buffer[50]; char buffer[1024];
int ba = tcpSocket->bytesAvailable();
std::cout << "Bytes: " << ba << std::endl;
while(tcpSocket->bytesAvailable()) while(tcpSocket->bytesAvailable())
{ {
tcpSocket->read(buffer, 50); tcpSocket->read(buffer, 1024);
std::cout << "Received From Skylive Server: " << buffer << std::endl; std::cout << "Received From Skylive Server: " << buffer << std::endl;
} }
} }
void SkyliveProtocol::handle_connect(SKMessage::SKMessage msg) void SkyliveProtocol::handle_connect(SKMessage::SKMessage msg)
{ {
std::cout << "SkyliveProtocol connect : " << msg.handle.toStdString() << std::endl; authenticated=false;
std::cout << "SkyliveProtocol connect: " << msg.handle.toStdString() << std::endl;
tcpSocket = new QTcpSocket(this); tcpSocket = new QTcpSocket(this);
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFromNetwork())); connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFromNetwork()));
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError))); connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError)));
tcpSocket->abort(); tcpSocket->abort();
tcpSocket->connectToHost("www.skylive.name", 8080); tcpSocket->connectToHost(SERVERHOST, SERVERPORT);
} }
void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg) void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg)
......
...@@ -32,14 +32,46 @@ ...@@ -32,14 +32,46 @@
* Purpose: * Purpose:
* *
*/ */
#ifndef SKPROTO_H
#define SKPROTO_H
#include <QObject> #include <QObject>
#include <QtPlugin> #include <QtPlugin>
#include <QHash> #include <QHash>
#include <QTcpSocket> #include <QTcpSocket>
#include <QNetworkSession> //#include <QNetworkSession>
#include <QByteArray>
#include "pluginsinterfaces.h" #include "pluginsinterfaces.h"
#include "ipcmsg.h" #include "ipcmsg.h"
#define SERVERHOST "www.skylive.name"
#define SERVERPORT 8080
struct SKProtoMsg
{
QByteArray cmd;
QByteArray params;
QByteArray crc;
};
enum _SM_TCPCLIENT
{
HOME = 0,
CONNECTED,
COMMAND,
PARAMS,
CRC
}; //SM_TCPCLIENT = HOME;
#define PROTO_START "["
#define PROTO_END "]"
#define CMD_END ">"
#define PARAM_SEPARATOR "|"
#define PARAM_END ":"
class SkyliveProtocol; class SkyliveProtocol;
typedef void (SkyliveProtocol::*SKHandlerFunction)(SKMessage::SKMessage); typedef void (SkyliveProtocol::*SKHandlerFunction)(SKMessage::SKMessage);
...@@ -53,7 +85,9 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface ...@@ -53,7 +85,9 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
private: private:
QHash<QString, SKHandlerFunction> _handlers; QHash<QString, SKHandlerFunction> _handlers;
QTcpSocket *tcpSocket; QTcpSocket *tcpSocket;
QNetworkSession *networkSession; //QNetworkSession *networkSession;
bool authenticated;
_SM_TCPCLIENT SM_TCPCLIENT;
public: public:
...@@ -72,4 +106,4 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface ...@@ -72,4 +106,4 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
signals: signals:
void putMessage(SKMessage::SKMessage msg); void putMessage(SKMessage::SKMessage msg);
}; };
#endif
...@@ -98,7 +98,7 @@ void MainWin::handle_corestarted(SKMessage::SKMessage &msg) ...@@ -98,7 +98,7 @@ void MainWin::handle_corestarted(SKMessage::SKMessage &msg)
{ {
msg.handle = "connectTelescopes"; msg.handle = "connectTelescopes";
sendMessage(msg); sendMessage(msg);
jsbridge.changePageContent("loadstring", "Connecting..."); jsbridge.notify("Connecting...");
} }
...@@ -106,3 +106,4 @@ void JSBridge::changePageContent(QString elementid, QString content) ...@@ -106,3 +106,4 @@ void JSBridge::changePageContent(QString elementid, QString content)
{ {
emit changeContent(elementid, content); emit changeContent(elementid, content);
} }
...@@ -63,6 +63,7 @@ class JSBridge : public QObject ...@@ -63,6 +63,7 @@ class JSBridge : public QObject
signals: signals:
void changeContent(QString elementid, QString content); void changeContent(QString elementid, QString content);
void notify(QString content);
}; };
......
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