Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
skylivex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
astronomy
skylivex
Commits
856c910b
Commit
856c910b
authored
Feb 18, 2013
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Starting to write networking
parent
c29db5c4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
14 deletions
+63
-14
skproto.cpp
plugins/skproto.cpp
+48
-10
skproto.h
plugins/skproto.h
+10
-1
main.cpp
src/main.cpp
+1
-1
mainwin.h
src/mainwin.h
+1
-1
skylivex.cpp
src/skylivex.cpp
+3
-1
No files found.
plugins/skproto.cpp
View file @
856c910b
...
...
@@ -36,7 +36,8 @@
#include "ipcmsg.h"
#include <iostream>
#include "skproto.h"
#include <QTcpSocket>
#include <QtNetwork>
void
SkyliveProtocol
::
startPlugin
()
...
...
@@ -46,14 +47,44 @@ void SkyliveProtocol::startPlugin()
}
void
SkyliveProtocol
::
readFromNetwork
()
{
std
::
cout
<<
"Received From Skylive Serve"
;
QDataStream
in
(
tcpSocket
);
in
.
setVersion
(
QDataStream
::
Qt_4_0
);
if
(
blockSize
==
0
)
{
if
(
tcpSocket
->
bytesAvailable
()
<
(
int
)
sizeof
(
quint16
))
return
;
in
>>
blockSize
;
}
if
(
tcpSocket
->
bytesAvailable
()
<
blockSize
)
return
;
QString
receivedTCP
;
in
>>
receivedTCP
;
std
::
cout
<<
"Received From Skylive Server"
<<
receivedTCP
.
toStdString
()
<<
std
::
endl
;
}
void
SkyliveProtocol
::
handle_connect
(
SKMessage
::
SKMessage
msg
)
{
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
)));
blockSize
=
0
;
tcpSocket
->
abort
();
tcpSocket
->
connectToHost
(
"localhost"
,
8081
);
}
void
SkyliveProtocol
::
receiveMessage
(
SKMessage
::
SKMessage
msg
)
{
std
::
cout
<<
"SkyliveProtocol msg received: "
<<
msg
.
handle
.
toStdString
()
<<
std
::
endl
;
if
(
_handlers
.
contains
(
msg
.
handle
))
{
SKHandlerFunction
mf
=
_handlers
[
msg
.
handle
];
(
this
->*
mf
)(
msg
);
}
}
void
SkyliveProtocol
::
sendMessage
(
SKMessage
::
SKMessage
msg
)
...
...
@@ -62,18 +93,25 @@ void SkyliveProtocol::sendMessage(SKMessage::SKMessage 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
;
}
void
SkyliveProtocol
::
displayError
(
QAbstractSocket
::
SocketError
socketError
)
{
switch
(
socketError
)
{
case
QAbstractSocket
:
:
RemoteHostClosedError
:
break
;
case
QAbstractSocket
:
:
HostNotFoundError
:
std
::
cout
<<
"Host not found"
<<
std
::
endl
;
break
;
case
QAbstractSocket
:
:
ConnectionRefusedError
:
std
::
cout
<<
"connection refused"
<<
std
::
endl
;
break
;
default
:
std
::
cout
<<
"networ error: "
<<
std
::
endl
;
}
}
plugins/skproto.h
View file @
856c910b
...
...
@@ -35,9 +35,12 @@
#include <QObject>
#include <QtPlugin>
#include <QHash>
#include <QTcpSocket>
#include <QNetworkSession>
#include "pluginsinterfaces.h"
#include "ipcmsg.h"
class
SkyliveProtocol
;
typedef
void
(
SkyliveProtocol
::*
SKHandlerFunction
)(
SKMessage
::
SKMessage
);
...
...
@@ -49,13 +52,19 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
private
:
QHash
<
QString
,
SKHandlerFunction
>
_handlers
;
QTcpSocket
*
tcpSocket
;
QNetworkSession
*
networkSession
;
quint16
blockSize
;
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
);
private
slots
:
void
sessionOpened
();
void
readFromNetwork
();
void
displayError
(
QAbstractSocket
::
SocketError
);
public
slots
:
void
receiveMessage
(
SKMessage
::
SKMessage
msg
);
...
...
src/main.cpp
View file @
856c910b
...
...
@@ -78,8 +78,8 @@ int main(int argc, char *argv[])
skxprocess
->
start
();
// connect core with the mainwin
//QObject::connect(skx, SIGNAL(msgForMainWin(std::string&)), &mainw, SLOT(msgFromCore(std::string&)), Qt::QueuedConnection);
QObject
::
connect
(
skx
,
SIGNAL
(
msgForMainWin
(
SKMessage
::
SKMessage
&
)),
&
mainw
,
SLOT
(
msgFromCore
(
SKMessage
::
SKMessage
&
)));
QObject
::
connect
(
&
mainw
,
SIGNAL
(
putMessage
(
SKMessage
::
SKMessage
&
)),
skx
,
SLOT
(
receiveFromMainWin
(
SKMessage
::
SKMessage
&
)));
// and then.. go!
return
skylivexapp
.
exec
();
...
...
src/mainwin.h
View file @
856c910b
...
...
@@ -76,7 +76,7 @@ class MainWin : public QWebView
void
msgFromCore
(
SKMessage
::
SKMessage
&
msg
);
signals
:
void
putMessage
(
SKMessage
::
SKMessage
msg
);
void
putMessage
(
SKMessage
::
SKMessage
&
msg
);
};
...
...
src/skylivex.cpp
View file @
856c910b
...
...
@@ -122,10 +122,12 @@ void SkyliveX::sendMessage(SKMessage::SKMessage &msg)
void
SkyliveX
::
receiveFromMainWin
(
SKMessage
::
SKMessage
&
msg
)
{
emit
msgForPlugins
(
msg
);
std
::
cout
<<
"received from MainWin "
<<
msg
.
handle
.
toStdString
()
<<
std
::
endl
;
//emit msgForPlugins(msg);
}
void
SkyliveX
::
receiveFromPlugins
(
SKMessage
::
SKMessage
msg
)
{
std
::
cout
<<
"received from plugins "
<<
msg
.
handle
.
toStdString
()
<<
std
::
endl
;
sendMessage
(
msg
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment