diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2011-05-17 01:24:51 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2011-05-17 01:24:51 +0000 |
| commit | efcbdb7a0347b4399cbabacf3cbea432eeafb17b (patch) | |
| tree | d468a9d8e129cba0cef68a09421c0e21c720ede6 /src/gatscon | |
| parent | 02c60c6720f41bcfc367d02ae4c655b651642991 (diff) | |
| download | libgats-efcbdb7a0347b4399cbabacf3cbea432eeafb17b.tar.gz libgats-efcbdb7a0347b4399cbabacf3cbea432eeafb17b.tar.bz2 libgats-efcbdb7a0347b4399cbabacf3cbea432eeafb17b.tar.xz libgats-efcbdb7a0347b4399cbabacf3cbea432eeafb17b.zip | |
Gats::Object now has a strToGats function, it's pretty slick, it takes a string
and produces a fully formed gats tree. Also, gatscon now can interact with
a server directly.
Diffstat (limited to 'src/gatscon')
| -rw-r--r-- | src/gatscon/clientthread.cpp | 38 | ||||
| -rw-r--r-- | src/gatscon/clientthread.h | 37 | ||||
| -rw-r--r-- | src/gatscon/clientwidget.cpp | 67 | ||||
| -rw-r--r-- | src/gatscon/clientwidget.h | 13 | ||||
| -rw-r--r-- | src/gatscon/clientwidget.ui | 33 | ||||
| -rw-r--r-- | src/gatscon/gatstotree.cpp | 75 | ||||
| -rw-r--r-- | src/gatscon/gatstotree.h | 19 |
7 files changed, 265 insertions, 17 deletions
diff --git a/src/gatscon/clientthread.cpp b/src/gatscon/clientthread.cpp new file mode 100644 index 0000000..b1dc4d0 --- /dev/null +++ b/src/gatscon/clientthread.cpp | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #include "clientthread.h" | ||
| 2 | |||
| 3 | #include <bu/tcpsocket.h> | ||
| 4 | |||
| 5 | ClientThread::ClientThread( QObject *pParent, const QByteArray &baHost, | ||
| 6 | int iPort ) : | ||
| 7 | QThread( pParent ), | ||
| 8 | baHost( baHost ), | ||
| 9 | iPort( iPort ), | ||
| 10 | gsCli( ssCli ) | ||
| 11 | { | ||
| 12 | } | ||
| 13 | |||
| 14 | ClientThread::~ClientThread() | ||
| 15 | { | ||
| 16 | } | ||
| 17 | |||
| 18 | void ClientThread::send( Gats::Object *pObj ) | ||
| 19 | { | ||
| 20 | gsCli.writeObject( pObj ); | ||
| 21 | } | ||
| 22 | |||
| 23 | void ClientThread::run() | ||
| 24 | { | ||
| 25 | ssCli.setStream( | ||
| 26 | new Bu::TcpSocket( baHost.constData(), iPort ) | ||
| 27 | ); | ||
| 28 | |||
| 29 | while( !ssCli.isEos() ) | ||
| 30 | { | ||
| 31 | Gats::Object *pObj = gsCli.readObject(); | ||
| 32 | if( pObj == NULL ) | ||
| 33 | break; | ||
| 34 | |||
| 35 | emit recv( pObj ); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
diff --git a/src/gatscon/clientthread.h b/src/gatscon/clientthread.h new file mode 100644 index 0000000..3182d37 --- /dev/null +++ b/src/gatscon/clientthread.h | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | #ifndef CLIENT_THREAD_H | ||
| 2 | #define CLIENT_THREAD_H | ||
| 3 | |||
| 4 | #include <QThread> | ||
| 5 | #include <QByteArray> | ||
| 6 | |||
| 7 | #include <bu/streamstack.h> | ||
| 8 | #include <gats/gatsstream.h> | ||
| 9 | |||
| 10 | namespace Gats | ||
| 11 | { | ||
| 12 | class Object; | ||
| 13 | }; | ||
| 14 | |||
| 15 | class ClientThread : public QThread | ||
| 16 | { | ||
| 17 | Q_OBJECT; | ||
| 18 | public: | ||
| 19 | ClientThread( QObject *pParent, const QByteArray &baHost, int iPort ); | ||
| 20 | virtual ~ClientThread(); | ||
| 21 | |||
| 22 | void send( Gats::Object *pObj ); | ||
| 23 | |||
| 24 | signals: | ||
| 25 | void recv( Gats::Object *pObj ); | ||
| 26 | |||
| 27 | protected: | ||
| 28 | virtual void run(); | ||
| 29 | |||
| 30 | private: | ||
| 31 | QByteArray baHost; | ||
| 32 | int iPort; | ||
| 33 | Bu::StreamStack ssCli; | ||
| 34 | Gats::GatsStream gsCli; | ||
| 35 | }; | ||
| 36 | |||
| 37 | #endif | ||
diff --git a/src/gatscon/clientwidget.cpp b/src/gatscon/clientwidget.cpp index 4872d9d..6039035 100644 --- a/src/gatscon/clientwidget.cpp +++ b/src/gatscon/clientwidget.cpp | |||
| @@ -1,24 +1,73 @@ | |||
| 1 | #include "clientwidget.h" | 1 | #include "clientwidget.h" |
| 2 | #include "connectdlg.h" | 2 | #include "connectdlg.h" |
| 3 | #include "clientthread.h" | ||
| 4 | |||
| 5 | #include "gatstotree.h" | ||
| 6 | |||
| 7 | #include <QMessageBox> | ||
| 8 | |||
| 9 | #include <bu/tcpsocket.h> | ||
| 10 | #include <bu/sio.h> | ||
| 11 | |||
| 12 | using namespace Bu; | ||
| 3 | 13 | ||
| 4 | ClientWidget::ClientWidget( QWidget *pParent ) : | 14 | ClientWidget::ClientWidget( QWidget *pParent ) : |
| 5 | QWidget( pParent ), | 15 | QWidget( pParent ) |
| 6 | gsCli( ssCli ) | ||
| 7 | { | 16 | { |
| 8 | setupUi( this ); | 17 | setupUi( this ); |
| 9 | 18 | ||
| 10 | ConnectDlg dlg( this ); | 19 | { |
| 11 | dlg.exec(); | 20 | ConnectDlg dlg( this ); |
| 21 | dlg.exec(); | ||
| 12 | 22 | ||
| 13 | ssCli.setStream( | 23 | sio << "Connect: " << dlg.getHostname().constData() << ":" |
| 14 | new Bu::TcpSocket( dlg.getHost().constData(), dlg.getPort() ) | 24 | << dlg.getPort() << sio.nl; |
| 15 | ); | ||
| 16 | 25 | ||
| 17 | Gats::Object *pObj = gsCli.readObject(); | 26 | pCli = new ClientThread( this, dlg.getHostname(), dlg.getPort() ); |
| 18 | gatsToTree( twHistory, pObj ); | 27 | } |
| 28 | pCli->start(); | ||
| 29 | connect( pCli, SIGNAL(recv( Gats::Object *)), | ||
| 30 | this, SLOT(recv(Gats::Object *)), Qt::QueuedConnection ); | ||
| 19 | } | 31 | } |
| 20 | 32 | ||
| 21 | ClientWidget::~ClientWidget() | 33 | ClientWidget::~ClientWidget() |
| 22 | { | 34 | { |
| 23 | } | 35 | } |
| 24 | 36 | ||
| 37 | void ClientWidget::send() | ||
| 38 | { | ||
| 39 | try | ||
| 40 | { | ||
| 41 | Gats::Object *pObj = Gats::Object::strToGats( | ||
| 42 | leGats->text().toAscii().constData() | ||
| 43 | ); | ||
| 44 | sio << "Send: " << *pObj << sio.nl; | ||
| 45 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | ||
| 46 | twHistory->invisibleRootItem() | ||
| 47 | ); | ||
| 48 | pIt->setText( 0, "send" ); | ||
| 49 | gatsToTree( pIt, pObj ); | ||
| 50 | pCli->send( pObj ); | ||
| 51 | delete pObj; | ||
| 52 | |||
| 53 | leGats->setText(""); | ||
| 54 | leGats->setFocus(); | ||
| 55 | } | ||
| 56 | catch( Bu::ExceptionBase &e ) | ||
| 57 | { | ||
| 58 | QMessageBox::critical( this, "GatsCon - Error", e.what() ); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | void ClientWidget::recv( Gats::Object *pObj ) | ||
| 63 | { | ||
| 64 | sio << "Recv: " << *pObj << sio.nl; | ||
| 65 | |||
| 66 | QTreeWidgetItem *pIt = new QTreeWidgetItem( | ||
| 67 | twHistory->invisibleRootItem() | ||
| 68 | ); | ||
| 69 | pIt->setText( 0, "recv" ); | ||
| 70 | gatsToTree( pIt, pObj ); | ||
| 71 | delete pObj; | ||
| 72 | } | ||
| 73 | |||
diff --git a/src/gatscon/clientwidget.h b/src/gatscon/clientwidget.h index 3a96f07..21fb1b7 100644 --- a/src/gatscon/clientwidget.h +++ b/src/gatscon/clientwidget.h | |||
| @@ -3,8 +3,10 @@ | |||
| 3 | 3 | ||
| 4 | #include "ui_clientwidget.h" | 4 | #include "ui_clientwidget.h" |
| 5 | 5 | ||
| 6 | #include <bu/streamstack.h> | 6 | namespace Gats |
| 7 | #include <gats/gatsstream.h> | 7 | { |
| 8 | class Object; | ||
| 9 | }; | ||
| 8 | 10 | ||
| 9 | class ClientWidget : public QWidget, protected Ui::ClientWidget | 11 | class ClientWidget : public QWidget, protected Ui::ClientWidget |
| 10 | { | 12 | { |
| @@ -13,9 +15,12 @@ public: | |||
| 13 | ClientWidget( QWidget *pParent=NULL ); | 15 | ClientWidget( QWidget *pParent=NULL ); |
| 14 | virtual ~ClientWidget(); | 16 | virtual ~ClientWidget(); |
| 15 | 17 | ||
| 18 | public slots: | ||
| 19 | void send(); | ||
| 20 | void recv( Gats::Object *pObj ); | ||
| 21 | |||
| 16 | private: | 22 | private: |
| 17 | Bu::StreamStack ssCli; | 23 | class ClientThread *pCli; |
| 18 | Gats::GatsStream gsCli; | ||
| 19 | }; | 24 | }; |
| 20 | 25 | ||
| 21 | #endif | 26 | #endif |
diff --git a/src/gatscon/clientwidget.ui b/src/gatscon/clientwidget.ui index 9761401..a0cb997 100644 --- a/src/gatscon/clientwidget.ui +++ b/src/gatscon/clientwidget.ui | |||
| @@ -6,8 +6,8 @@ | |||
| 6 | <rect> | 6 | <rect> |
| 7 | <x>0</x> | 7 | <x>0</x> |
| 8 | <y>0</y> | 8 | <y>0</y> |
| 9 | <width>364</width> | 9 | <width>363</width> |
| 10 | <height>289</height> | 10 | <height>291</height> |
| 11 | </rect> | 11 | </rect> |
| 12 | </property> | 12 | </property> |
| 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
| @@ -23,6 +23,11 @@ | |||
| 23 | </column> | 23 | </column> |
| 24 | <column> | 24 | <column> |
| 25 | <property name="text"> | 25 | <property name="text"> |
| 26 | <string>Type</string> | ||
| 27 | </property> | ||
| 28 | </column> | ||
| 29 | <column> | ||
| 30 | <property name="text"> | ||
| 26 | <string>Value</string> | 31 | <string>Value</string> |
| 27 | </property> | 32 | </property> |
| 28 | </column> | 33 | </column> |
| @@ -38,7 +43,7 @@ | |||
| 38 | </widget> | 43 | </widget> |
| 39 | </item> | 44 | </item> |
| 40 | <item> | 45 | <item> |
| 41 | <widget class="QLineEdit" name="lineEdit"/> | 46 | <widget class="QLineEdit" name="leGats"/> |
| 42 | </item> | 47 | </item> |
| 43 | <item> | 48 | <item> |
| 44 | <widget class="QPushButton" name="pushButton"> | 49 | <widget class="QPushButton" name="pushButton"> |
| @@ -58,5 +63,25 @@ | |||
| 58 | </layout> | 63 | </layout> |
| 59 | </widget> | 64 | </widget> |
| 60 | <resources/> | 65 | <resources/> |
| 61 | <connections/> | 66 | <connections> |
| 67 | <connection> | ||
| 68 | <sender>pushButton</sender> | ||
| 69 | <signal>clicked()</signal> | ||
| 70 | <receiver>ClientWidget</receiver> | ||
| 71 | <slot>send()</slot> | ||
| 72 | <hints> | ||
| 73 | <hint type="sourcelabel"> | ||
| 74 | <x>332</x> | ||
| 75 | <y>276</y> | ||
| 76 | </hint> | ||
| 77 | <hint type="destinationlabel"> | ||
| 78 | <x>322</x> | ||
| 79 | <y>367</y> | ||
| 80 | </hint> | ||
| 81 | </hints> | ||
| 82 | </connection> | ||
| 83 | </connections> | ||
| 84 | <slots> | ||
| 85 | <slot>send()</slot> | ||
| 86 | </slots> | ||
| 62 | </ui> | 87 | </ui> |
diff --git a/src/gatscon/gatstotree.cpp b/src/gatscon/gatstotree.cpp index af94fa5..d01e4b8 100644 --- a/src/gatscon/gatstotree.cpp +++ b/src/gatscon/gatstotree.cpp | |||
| @@ -1,8 +1,83 @@ | |||
| 1 | #include "gatstotree.h" | ||
| 2 | |||
| 1 | #include <gats/types.h> | 3 | #include <gats/types.h> |
| 2 | 4 | ||
| 3 | #include <QTreeWidgetItem> | 5 | #include <QTreeWidgetItem> |
| 4 | 6 | ||
| 5 | void gatsToTree( QTreeWidgetItem *p, Gats::Object *pObj ) | 7 | void gatsToTree( QTreeWidgetItem *p, Gats::Object *pObj ) |
| 6 | { | 8 | { |
| 9 | switch( pObj->getType() ) | ||
| 10 | { | ||
| 11 | case Gats::typeInteger: | ||
| 12 | gatsToTree( p, dynamic_cast<Gats::Integer *>( pObj ) ); | ||
| 13 | break; | ||
| 14 | |||
| 15 | case Gats::typeString: | ||
| 16 | gatsToTree( p, dynamic_cast<Gats::String *>( pObj ) ); | ||
| 17 | break; | ||
| 18 | |||
| 19 | case Gats::typeFloat: | ||
| 20 | gatsToTree( p, dynamic_cast<Gats::Float *>( pObj ) ); | ||
| 21 | break; | ||
| 22 | |||
| 23 | case Gats::typeBoolean: | ||
| 24 | gatsToTree( p, dynamic_cast<Gats::Boolean *>( pObj ) ); | ||
| 25 | break; | ||
| 26 | |||
| 27 | case Gats::typeList: | ||
| 28 | gatsToTree( p, dynamic_cast<Gats::List *>( pObj ) ); | ||
| 29 | break; | ||
| 30 | |||
| 31 | case Gats::typeDictionary: | ||
| 32 | gatsToTree( p, dynamic_cast<Gats::Dictionary *>( pObj ) ); | ||
| 33 | break; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | void gatsToTree( QTreeWidgetItem *p, Gats::Integer *pObj ) | ||
| 38 | { | ||
| 39 | p->setText( 1, "int"); | ||
| 40 | p->setText( 2, QString("%1").arg( pObj->getValue() ) ); | ||
| 41 | } | ||
| 42 | |||
| 43 | void gatsToTree( QTreeWidgetItem *p, Gats::String *pObj ) | ||
| 44 | { | ||
| 45 | p->setText( 1, "str"); | ||
| 46 | p->setText( 2, QString("%1").arg( pObj->getStr() ) ); | ||
| 47 | } | ||
| 48 | |||
| 49 | void gatsToTree( QTreeWidgetItem *p, Gats::Float *pObj ) | ||
| 50 | { | ||
| 51 | p->setText( 1, "float"); | ||
| 52 | p->setText( 2, QString("%1").arg( pObj->getValue() ) ); | ||
| 53 | } | ||
| 54 | |||
| 55 | void gatsToTree( QTreeWidgetItem *p, Gats::Boolean *pObj ) | ||
| 56 | { | ||
| 57 | p->setText( 1, "bool"); | ||
| 58 | p->setText( 2, pObj->getValue()?"true":"false" ); | ||
| 59 | } | ||
| 60 | |||
| 61 | void gatsToTree( QTreeWidgetItem *p, Gats::List *pObj ) | ||
| 62 | { | ||
| 63 | p->setText( 1, "list"); | ||
| 64 | int j = 0; | ||
| 65 | for( Gats::List::iterator i = pObj->begin(); i; i++ ) | ||
| 66 | { | ||
| 67 | QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); | ||
| 68 | pIt->setText( 0, QString("%1").arg( j++ ) ); | ||
| 69 | gatsToTree( pIt, *i ); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | void gatsToTree( QTreeWidgetItem *p, Gats::Dictionary *pObj ) | ||
| 74 | { | ||
| 75 | p->setText( 1, "dict"); | ||
| 76 | for( Gats::Dictionary::iterator i = pObj->begin(); i; i++ ) | ||
| 77 | { | ||
| 78 | QTreeWidgetItem *pIt = new QTreeWidgetItem( p ); | ||
| 79 | pIt->setText( 0, QString( i.getKey().getStr() ) ); | ||
| 80 | gatsToTree( pIt, *i ); | ||
| 81 | } | ||
| 7 | } | 82 | } |
| 8 | 83 | ||
diff --git a/src/gatscon/gatstotree.h b/src/gatscon/gatstotree.h index cab9eee..26fb76c 100644 --- a/src/gatscon/gatstotree.h +++ b/src/gatscon/gatstotree.h | |||
| @@ -3,6 +3,25 @@ | |||
| 3 | 3 | ||
| 4 | class QTreeWidgetItem; | 4 | class QTreeWidgetItem; |
| 5 | 5 | ||
| 6 | namespace Gats | ||
| 7 | { | ||
| 8 | class Integer; | ||
| 9 | class String; | ||
| 10 | class Float; | ||
| 11 | class Boolean; | ||
| 12 | class List; | ||
| 13 | class Dictionary; | ||
| 14 | class Object; | ||
| 15 | }; | ||
| 16 | |||
| 17 | #include <gats/types.h> | ||
| 18 | |||
| 6 | void gatsToTree( QTreeWidgetItem *p, Gats::Object *pObj ); | 19 | void gatsToTree( QTreeWidgetItem *p, Gats::Object *pObj ); |
| 20 | void gatsToTree( QTreeWidgetItem *p, Gats::Integer *pObj ); | ||
| 21 | void gatsToTree( QTreeWidgetItem *p, Gats::String *pObj ); | ||
| 22 | void gatsToTree( QTreeWidgetItem *p, Gats::Float *pObj ); | ||
| 23 | void gatsToTree( QTreeWidgetItem *p, Gats::Boolean *pObj ); | ||
| 24 | void gatsToTree( QTreeWidgetItem *p, Gats::List *pObj ); | ||
| 25 | void gatsToTree( QTreeWidgetItem *p, Gats::Dictionary *pObj ); | ||
| 7 | 26 | ||
| 8 | #endif | 27 | #endif |
