source: flair-src/trunk/tools/FlairGCS/src/ConnectionLayout.cpp@ 447

Last change on this file since 447 was 444, checked in by Sanahuja Guillaume, 3 years ago

update buffering (gcs part)
seems to work!

File size: 4.5 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[9]5#include "ConnectionLayout.h"
6#include "UdtSocket.h"
7#include "DataRemote.h"
8#include <qendian.h>
9#include "communication.h"
10
[436]11ConnectionLayout::ConnectionLayout(UdtSocket *socket, QString name, QTime startTime)
[15]12 : Layout(NULL, name, "root") {
13 this->socket = socket;
[234]14 this->name = name;
[436]15 this->startTime = startTime;
[9]16}
17
[30]18ConnectionLayout::~ConnectionLayout() {
19}
[9]20
[436]21QTime ConnectionLayout::GetStartTime(void) {
22 return startTime;
23}
24
[260]25void ConnectionLayout::udtSocketDestroyed(QObject *obj){
26 socket=NULL;
27}
28
[15]29void ConnectionLayout::receive(char *buf, int size) {
[247]30 //fprintf(stderr,"trame %x\n",buf[0]);
[244]31 // for(int i=0; i<size;i++) fprintf(stderr,"%x ",buf[i]);
32 // fprintf(stderr,"\n");
[15]33 switch ((unsigned char)buf[0]) {
34 case XML_HEADER: {
35 QString xml;
36 QDomDocument doc;
37 xml = QString((char *)buf);
38 xml.resize(size);
[9]39
[244]40 // fprintf(stderr,"recu %i\n%s\n",size,xml.toLocal8Bit().constData());
[15]41 if (!doc.setContent(xml)) {
[244]42 fprintf(stderr,"prob setContent fichier\n");
[15]43 }
[9]44
[269]45 QDomElement dom=doc.firstChildElement("root").firstChildElement();
46 ParseXml(&dom);
[15]47 break;
48 }
[253]49 case DATA_BIG_ENDIAN: {
[15]50 uint16_t period;
51 memcpy(&period, &buf[1], sizeof(uint16_t));
52 period = qFromBigEndian(period);
[443]53 drawDatas(&buf[3], size - 3, period, 1,true);
[15]54 break;
55 }
[253]56 case DATA_LITTLE_ENDIAN: {
[15]57 uint16_t period;
58 memcpy(&period, &buf[1], sizeof(uint16_t));
[443]59 drawDatas(&buf[3], size - 3, period,1);
[15]60 break;
61 }
[444]62 case MULTIPLE_DATA_BIG_ENDIAN: {
63 uint16_t period;
64 uint16_t nb_buffering;
65 memcpy(&period, buf+sizeof(char), sizeof(uint16_t));
66 period = qFromBigEndian(period);
67 memcpy(&nb_buffering,buf+sizeof(char)+sizeof(uint16_t), sizeof(uint16_t));
68 nb_buffering = qFromBigEndian(nb_buffering);
69 //fprintf(stderr,"recu %i, period %i, nb_buff %i\n",size,period,nb_buffering);
70 drawDatas(buf+sizeof(char)+sizeof(uint16_t)+sizeof(uint16_t), size - sizeof(char)+sizeof(uint16_t)+sizeof(uint16_t), period, nb_buffering,true);
71 break;
72 }
[443]73 case MULTIPLE_DATA_LITTLE_ENDIAN: {
74 uint16_t period;
75 uint16_t nb_buffering;
76 memcpy(&period, buf+sizeof(char), sizeof(uint16_t));
77 memcpy(&nb_buffering,buf+sizeof(char)+sizeof(uint16_t), sizeof(uint16_t));
[444]78 //fprintf(stderr,"recu %i, period %i, nb_buff %i\n",size,period,nb_buffering);
[443]79 drawDatas(buf+sizeof(char)+sizeof(uint16_t)+sizeof(uint16_t), size - sizeof(char)+sizeof(uint16_t)+sizeof(uint16_t), period, nb_buffering);
80 break;
81 }
[247]82 case CLOSING_CONNECTION: {
83 deleteLater();
84 break;
85 }
[15]86 default:
[244]87 fprintf(stderr,"trame non supportée %x\n", buf[0]);
[15]88 }
[9]89}
90
[234]91void ConnectionLayout::XmlToSend(QDomDocument doc) {
[258]92 //fprintf(stderr,"xml to send\n%s\n",doc.toString().toLocal8Bit().constData());
[260]93 if(!socket) return;
[234]94
95 // xml to send a mettre dans le manager
[258]96 if(doc.toString().toLocal8Bit().length()!=0) {
97 socket->write(doc.toString().toLocal8Bit().constData(),doc.toString().toLocal8Bit().length());
98 }
99 /*
[234]100 QMetaObject::invokeMethod(
101 socket, "write", Qt::BlockingQueuedConnection,
102 Q_ARG(const char *, doc.toString().toLocal8Bit().constData()),
103 Q_ARG(qint64, doc.toString().toLocal8Bit().length()));*/
104}
105
[269]106void ConnectionLayout::LoadXml(QDomDocument *to_parse) {
107 QDomElement tmp = to_parse->firstChildElement("root");
[234]108 while (tmp.attribute("name") != name && !tmp.isNull())
[269]109 tmp = to_parse->nextSiblingElement("root");
[234]110
111 if (!tmp.isNull()) {
[269]112 XmlWidget::LoadXml(&tmp);
[234]113 } else {
[244]114 fprintf(stderr,"%s not found in xml file \n", name.toLocal8Bit().constData());
[234]115 }
116}
117
[15]118void ConnectionLayout::removeDataRemote(DataRemote *data) {
119 dataremotes.removeOne(data);
[9]120}
121
[15]122void ConnectionLayout::addDataRemote(DataRemote *data) {
123 dataremotes.append(data);
[9]124}
125
[234]126QString ConnectionLayout::getName() { return name; }
[222]127
[443]128void ConnectionLayout::drawDatas(char *buf, int buf_size, uint16_t period,uint16_t nb_buffering, bool big_endian) {
129 for (int i = 0; i < nb_buffering; i++) {
130 for (int j = 0; j < dataremotes.count(); j++) {
[444]131 dataremotes.at(j)->BufEvent(&buf, &buf_size, period, nb_buffering,big_endian);
[443]132 }
133 }
[9]134}
135
[234]136QString ConnectionLayout::getDocRootName(char* buf, int size) {
137 QString xml;
138 QDomDocument doc;
139 xml = QString((char *)buf);
140 xml.resize(size);
[9]141
[234]142 if (!doc.setContent(xml)) {
[244]143 fprintf(stderr,"prob setContent fichier\n");
[15]144 }
[234]145
146 return doc.firstChildElement("root").attribute("name");
147}
Note: See TracBrowser for help on using the repository browser.