Initial stesure of the protocol parser

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