From 52bac339b6267aa9aaa3e2e0d02c2a62e47f83e4 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 6 Apr 2012 06:57:51 +0000 Subject: 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. --- c++-qt/src/gatsstream.cpp | 3 +++ c++-qt/src/gatsstream.h | 7 +++++++ c++-qt/tests/echo/echo.pro | 15 +++++++++++++++ c++-qt/tests/echo/main.cpp | 14 ++++++++++++++ c++-qt/tests/echo/mainwnd.cpp | 30 ++++++++++++++++++++++++++++++ c++-qt/tests/echo/mainwnd.h | 23 +++++++++++++++++++++++ src/tests/clone.cpp | 22 ++++++++++++++++++++++ 7 files changed, 114 insertions(+) create mode 100644 c++-qt/tests/echo/echo.pro create mode 100644 c++-qt/tests/echo/main.cpp create mode 100644 c++-qt/tests/echo/mainwnd.cpp create mode 100644 c++-qt/tests/echo/mainwnd.h create mode 100644 src/tests/clone.cpp 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() rTmp.open( QIODevice::ReadOnly ); rTmp.seek( 5 ); Gats::Object *pObj = Gats::Object::read( rTmp ); + qbRead.clear(); + + emit objectRead( pObj ); return pObj; } 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 GatsStream( QIODevice &rStream ); virtual ~GatsStream(); + public slots: /** * Read an object packet from the assosiated stream. This will make * every effort to only read exactly enough data to describe one packet, @@ -32,6 +33,7 @@ namespace Gats */ Gats::Object *readObject(); + public: /** * Write an object */ @@ -45,6 +47,11 @@ namespace Gats bool hasReadBuffer() { return qbRead.size() > 0; } int getReadBufferSize() { return qbRead.size(); } + QIODevice &getIODevice() { return rStream; } + + signals: + void objectRead( Gats::Object *pObj ); + private: bool skipReadNulls(); 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 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Fri Apr 6 00:45:00 2012 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . ../.. +QT += network + +LIBS += -L../.. -lgats-qt + +# Input +SOURCES += main.cpp mainwnd.cpp +HEADERS += 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 @@ +#include + +#include "mainwnd.h" + +int main( int argc, char *argv[] ) +{ + QApplication app( argc, argv ); + + MainWnd wnd; + wnd.show(); + + return app.exec(); +} + 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 @@ +#include "mainwnd.h" + +MainWnd::MainWnd() +{ + pSrv = new QTcpServer( this ); + connect( pSrv, SIGNAL(newConnection()), this, SLOT(newConnection())); + pSrv->listen( QHostAddress::Any, 7317 ); +} + +MainWnd::~MainWnd() +{ +} + +void MainWnd::newConnection() +{ + while( pSrv->hasPendingConnections() ) + { + QTcpSocket *pSock = pSrv->nextPendingConnection(); + Gats::GatsStream *pGats = new Gats::GatsStream( *pSock ); + connect( pSock, SIGNAL(readyRead()), pGats, SLOT(readObject()) ); + connect( pGats, SIGNAL(objectRead( Gats::Object * )), + this, SLOT(objectRead( Gats::Object * ))); + } +} + +void MainWnd::objectRead( Gats::Object *pObj ) +{ + ((Gats::GatsStream *)sender())->writeObject( pObj ); + delete pObj; +} 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 @@ + +#include +#include +#include + +#include "gats-qt/gatsstream.h" +#include "gats-qt/types.h" + +class MainWnd : public QMainWindow +{ + Q_OBJECT; +public: + QTcpServer *pSrv; + + MainWnd(); + virtual ~MainWnd(); + +public slots: + void newConnection(); + void objectRead( Gats::Object *pObj ); + +signals: +}; 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 @@ +#include "gats/types.h" + +#include + +using namespace Bu; + +int main( int argc, char *argv[] ) +{ + Gats::Object *pBase = Gats::Object::strToGats("{\"Thing\": 3.14159, \"bool\": true, \"list\":[\"string\",44,{\"Stuff\":{\"list\":[],\"what?\":false}}]}"); + + sio << *pBase << sio.nl; + + Gats::Object *pNew = pBase->clone(); + delete pBase; + + sio << *pNew << sio.nl; + + delete pNew; + + return 0; +} + -- cgit v1.2.3