aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-04-06 06:57:51 +0000
committerMike Buland <eichlan@xagasoft.com>2012-04-06 06:57:51 +0000
commit52bac339b6267aa9aaa3e2e0d02c2a62e47f83e4 (patch)
treeb5e9f366a86d679495dd50790e150933da892d7a
parentfe9f6c6bbc9e682af709fe08757c31ba17a298d1 (diff)
downloadlibgats-52bac339b6267aa9aaa3e2e0d02c2a62e47f83e4.tar.gz
libgats-52bac339b6267aa9aaa3e2e0d02c2a62e47f83e4.tar.bz2
libgats-52bac339b6267aa9aaa3e2e0d02c2a62e47f83e4.tar.xz
libgats-52bac339b6267aa9aaa3e2e0d02c2a62e47f83e4.zip
Qt is tested more thoroughly, some read bugs are fixed. It also works better
with qt principles. You can hook up the readyRead signal to the readObject slot on GatsStream, and connect the GatsStream objectRead signal to your own functions, and you'll be notified whenever a new gats object is read. Cool.
-rw-r--r--c++-qt/src/gatsstream.cpp3
-rw-r--r--c++-qt/src/gatsstream.h7
-rw-r--r--c++-qt/tests/echo/echo.pro15
-rw-r--r--c++-qt/tests/echo/main.cpp14
-rw-r--r--c++-qt/tests/echo/mainwnd.cpp30
-rw-r--r--c++-qt/tests/echo/mainwnd.h23
-rw-r--r--src/tests/clone.cpp22
7 files changed, 114 insertions, 0 deletions
diff --git a/c++-qt/src/gatsstream.cpp b/c++-qt/src/gatsstream.cpp
index ae53d0d..3874de2 100644
--- a/c++-qt/src/gatsstream.cpp
+++ b/c++-qt/src/gatsstream.cpp
@@ -62,6 +62,9 @@ Gats::Object *Gats::GatsStream::readObject()
62 rTmp.open( QIODevice::ReadOnly ); 62 rTmp.open( QIODevice::ReadOnly );
63 rTmp.seek( 5 ); 63 rTmp.seek( 5 );
64 Gats::Object *pObj = Gats::Object::read( rTmp ); 64 Gats::Object *pObj = Gats::Object::read( rTmp );
65 qbRead.clear();
66
67 emit objectRead( pObj );
65 68
66 return pObj; 69 return pObj;
67} 70}
diff --git a/c++-qt/src/gatsstream.h b/c++-qt/src/gatsstream.h
index 3cf1081..f1c0625 100644
--- a/c++-qt/src/gatsstream.h
+++ b/c++-qt/src/gatsstream.h
@@ -15,6 +15,7 @@ namespace Gats
15 GatsStream( QIODevice &rStream ); 15 GatsStream( QIODevice &rStream );
16 virtual ~GatsStream(); 16 virtual ~GatsStream();
17 17
18 public slots:
18 /** 19 /**
19 * Read an object packet from the assosiated stream. This will make 20 * Read an object packet from the assosiated stream. This will make
20 * every effort to only read exactly enough data to describe one packet, 21 * every effort to only read exactly enough data to describe one packet,
@@ -32,6 +33,7 @@ namespace Gats
32 */ 33 */
33 Gats::Object *readObject(); 34 Gats::Object *readObject();
34 35
36 public:
35 /** 37 /**
36 * Write an object 38 * Write an object
37 */ 39 */
@@ -45,6 +47,11 @@ namespace Gats
45 bool hasReadBuffer() { return qbRead.size() > 0; } 47 bool hasReadBuffer() { return qbRead.size() > 0; }
46 int getReadBufferSize() { return qbRead.size(); } 48 int getReadBufferSize() { return qbRead.size(); }
47 49
50 QIODevice &getIODevice() { return rStream; }
51
52 signals:
53 void objectRead( Gats::Object *pObj );
54
48 private: 55 private:
49 bool skipReadNulls(); 56 bool skipReadNulls();
50 57
diff --git a/c++-qt/tests/echo/echo.pro b/c++-qt/tests/echo/echo.pro
new file mode 100644
index 0000000..63c741a
--- /dev/null
+++ b/c++-qt/tests/echo/echo.pro
@@ -0,0 +1,15 @@
1######################################################################
2# Automatically generated by qmake (2.01a) Fri Apr 6 00:45:00 2012
3######################################################################
4
5TEMPLATE = app
6TARGET =
7DEPENDPATH += .
8INCLUDEPATH += . ../..
9QT += network
10
11LIBS += -L../.. -lgats-qt
12
13# Input
14SOURCES += main.cpp mainwnd.cpp
15HEADERS += mainwnd.h
diff --git a/c++-qt/tests/echo/main.cpp b/c++-qt/tests/echo/main.cpp
new file mode 100644
index 0000000..43ceae4
--- /dev/null
+++ b/c++-qt/tests/echo/main.cpp
@@ -0,0 +1,14 @@
1#include <QApplication>
2
3#include "mainwnd.h"
4
5int main( int argc, char *argv[] )
6{
7 QApplication app( argc, argv );
8
9 MainWnd wnd;
10 wnd.show();
11
12 return app.exec();
13}
14
diff --git a/c++-qt/tests/echo/mainwnd.cpp b/c++-qt/tests/echo/mainwnd.cpp
new file mode 100644
index 0000000..4b90421
--- /dev/null
+++ b/c++-qt/tests/echo/mainwnd.cpp
@@ -0,0 +1,30 @@
1#include "mainwnd.h"
2
3MainWnd::MainWnd()
4{
5 pSrv = new QTcpServer( this );
6 connect( pSrv, SIGNAL(newConnection()), this, SLOT(newConnection()));
7 pSrv->listen( QHostAddress::Any, 7317 );
8}
9
10MainWnd::~MainWnd()
11{
12}
13
14void MainWnd::newConnection()
15{
16 while( pSrv->hasPendingConnections() )
17 {
18 QTcpSocket *pSock = pSrv->nextPendingConnection();
19 Gats::GatsStream *pGats = new Gats::GatsStream( *pSock );
20 connect( pSock, SIGNAL(readyRead()), pGats, SLOT(readObject()) );
21 connect( pGats, SIGNAL(objectRead( Gats::Object * )),
22 this, SLOT(objectRead( Gats::Object * )));
23 }
24}
25
26void MainWnd::objectRead( Gats::Object *pObj )
27{
28 ((Gats::GatsStream *)sender())->writeObject( pObj );
29 delete pObj;
30}
diff --git a/c++-qt/tests/echo/mainwnd.h b/c++-qt/tests/echo/mainwnd.h
new file mode 100644
index 0000000..0afbd6a
--- /dev/null
+++ b/c++-qt/tests/echo/mainwnd.h
@@ -0,0 +1,23 @@
1
2#include <QTcpServer>
3#include <QTcpSocket>
4#include <QMainWindow>
5
6#include "gats-qt/gatsstream.h"
7#include "gats-qt/types.h"
8
9class MainWnd : public QMainWindow
10{
11 Q_OBJECT;
12public:
13 QTcpServer *pSrv;
14
15 MainWnd();
16 virtual ~MainWnd();
17
18public slots:
19 void newConnection();
20 void objectRead( Gats::Object *pObj );
21
22signals:
23};
diff --git a/src/tests/clone.cpp b/src/tests/clone.cpp
new file mode 100644
index 0000000..8533376
--- /dev/null
+++ b/src/tests/clone.cpp
@@ -0,0 +1,22 @@
1#include "gats/types.h"
2
3#include <bu/sio.h>
4
5using namespace Bu;
6
7int main( int argc, char *argv[] )
8{
9 Gats::Object *pBase = Gats::Object::strToGats("{\"Thing\": 3.14159, \"bool\": true, \"list\":[\"string\",44,{\"Stuff\":{\"list\":[],\"what?\":false}}]}");
10
11 sio << *pBase << sio.nl;
12
13 Gats::Object *pNew = pBase->clone();
14 delete pBase;
15
16 sio << *pNew << sio.nl;
17
18 delete pNew;
19
20 return 0;
21}
22