Superviseur - Afficheur 1.0
Ce logiciel correspond à l'afficheur de la suite des trois logiciels composant le superviseur
collecteursocket.cpp
Aller à la documentation de ce fichier.
00001 #include "collecteursocket.h"
00002 
00003 
00005 
00008 CollecteurSocket::CollecteurSocket() :
00009     QTcpSocket()
00010 {
00011     this->tailleDonnees = 0;
00012 
00013     connect(this, SIGNAL(readyRead()), this, SLOT(recevoirDonnees()));
00014 }
00015 
00016 
00018 
00023 void CollecteurSocket::connexion(QString host, quint16 port){    
00024     this->abort();
00025     this->tailleDonnees = 0;
00026     this->connectToHost(host, port);
00027 }
00028 
00029 
00031 
00037 bool CollecteurSocket::envoyerCommande(QString commande){
00038     if(this->state() != QAbstractSocket::ConnectedState) return false;
00039 
00040     quint8  reserv = 0;
00041     quint32 number = commande.size();
00042     QByteArray ba;
00043     QDataStream out(&ba, QIODevice::ReadWrite);
00044     out.setByteOrder(QDataStream::BigEndian);
00045     out << number;
00046     out << reserv;
00047     bool ok1 = (this->write(ba) == ba.size());
00048     bool ok2 = (this->write(commande.toAscii()) == commande.size());
00049 
00050     return (ok1 && ok2);
00051 }
00052 
00053 
00055 
00060 void CollecteurSocket::recevoirDonnees(){
00061     //QDataStream in(this);
00062 
00063     if(this->tailleDonnees == 0){
00064         if(this->bytesAvailable() < ((int)sizeof(quint32)+(int)sizeof(quint8)) ) return;
00065         QByteArray ba = this->read((int)sizeof(quint32));
00066         this->tailleDonnees = ba.toHex().toUInt(0, 16);
00067         this->read((int)sizeof(quint8));
00068     }
00069     if(this->bytesAvailable() < this->tailleDonnees) return;
00070 
00071     QByteArray ba = this->read(this->tailleDonnees);
00072 
00073     //qDebug() << "Données recues: " << QString(ba);
00074 
00075     emit nouvellesDonnees(QString(ba));
00076 
00077     this->tailleDonnees = 0;
00078 
00079     //qDebug() << QThread::currentThreadId() << ": " << this->peerAddress().toString();
00080 }
00081 
00082 
00083 
 Tout Classes Espaces de nommage Fichiers Fonctions Variables