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

Last change on this file since 259 was 258, checked in by Sanahuja Guillaume, 6 years ago

avoid trying to send xml message of size=0

add debug in case of gcs crash when clicking on apply

File size: 3.4 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
[15]11ConnectionLayout::ConnectionLayout(UdtSocket *socket, QString name)
12 : Layout(NULL, name, "root") {
13 this->socket = socket;
[234]14 this->name = name;
[9]15}
16
[30]17ConnectionLayout::~ConnectionLayout() {
18}
[9]19
[15]20void ConnectionLayout::receive(char *buf, int size) {
[247]21 //fprintf(stderr,"trame %x\n",buf[0]);
[244]22 // for(int i=0; i<size;i++) fprintf(stderr,"%x ",buf[i]);
23 // fprintf(stderr,"\n");
[15]24 switch ((unsigned char)buf[0]) {
25 case XML_HEADER: {
26 QString xml;
27 QDomDocument doc;
28 xml = QString((char *)buf);
29 xml.resize(size);
[9]30
[244]31 // fprintf(stderr,"recu %i\n%s\n",size,xml.toLocal8Bit().constData());
[15]32 if (!doc.setContent(xml)) {
[244]33 fprintf(stderr,"prob setContent fichier\n");
[15]34 }
[9]35
[15]36 ParseXml(doc.firstChildElement("root").firstChildElement());
37 break;
38 }
[253]39 case DATA_BIG_ENDIAN: {
[244]40 // for(int i=0;i<size;i++) fprintf(stderr,"%x ",buf[i]);
41 // fprintf(stderr,"\n");
[15]42 uint16_t period;
43 memcpy(&period, &buf[1], sizeof(uint16_t));
44 period = qFromBigEndian(period);
45 drawDatas(&buf[3], size - 3, period, true);
46 break;
47 }
[253]48 case DATA_LITTLE_ENDIAN: {
[244]49 // for(int i=0;i<size;i++) fprintf(stderr,"%x ",buf[i]);
50 // fprintf(stderr,"\n");
[15]51 uint16_t period;
52 memcpy(&period, &buf[1], sizeof(uint16_t));
[244]53 // fprintf(stderr,"recu %i period %i\n",size,period);
[15]54 drawDatas(&buf[3], size - 3, period);
55 break;
56 }
[247]57 case CLOSING_CONNECTION: {
58 deleteLater();
59 break;
60 }
[15]61 default:
[244]62 fprintf(stderr,"trame non supportée %x\n", buf[0]);
[15]63 }
[9]64}
65
[234]66void ConnectionLayout::XmlToSend(QDomDocument doc) {
[258]67 //fprintf(stderr,"xml to send\n%s\n",doc.toString().toLocal8Bit().constData());
[234]68
69 // xml to send a mettre dans le manager
[258]70 if(doc.toString().toLocal8Bit().length()!=0) {
71 socket->write(doc.toString().toLocal8Bit().constData(),doc.toString().toLocal8Bit().length());
72 }
73 /*
[234]74 QMetaObject::invokeMethod(
75 socket, "write", Qt::BlockingQueuedConnection,
76 Q_ARG(const char *, doc.toString().toLocal8Bit().constData()),
77 Q_ARG(qint64, doc.toString().toLocal8Bit().length()));*/
78}
79
80void ConnectionLayout::LoadXml(QDomDocument to_parse) {
81 QDomElement tmp = to_parse.firstChildElement("root");
82 while (tmp.attribute("name") != name && !tmp.isNull())
83 tmp = to_parse.nextSiblingElement("root");
84
85 if (!tmp.isNull()) {
86 XmlWidget::LoadXml(tmp);
87 } else {
[244]88 fprintf(stderr,"%s not found in xml file \n", name.toLocal8Bit().constData());
[234]89 }
90}
91
[15]92void ConnectionLayout::removeDataRemote(DataRemote *data) {
93 dataremotes.removeOne(data);
[9]94}
95
[15]96void ConnectionLayout::addDataRemote(DataRemote *data) {
97 dataremotes.append(data);
[9]98}
99
[234]100QString ConnectionLayout::getName() { return name; }
[222]101
[15]102void ConnectionLayout::drawDatas(char *buf, int buf_size, uint16_t period,
103 bool big_endian) {
104 for (int i = 0; i < dataremotes.count(); i++) {
105 dataremotes.at(i)->BufEvent(&buf, &buf_size, period, big_endian);
106 }
[9]107}
108
[234]109QString ConnectionLayout::getDocRootName(char* buf, int size) {
110 QString xml;
111 QDomDocument doc;
112 xml = QString((char *)buf);
113 xml.resize(size);
[9]114
[234]115 if (!doc.setContent(xml)) {
[244]116 fprintf(stderr,"prob setContent fichier\n");
[15]117 }
[234]118
119 return doc.firstChildElement("root").attribute("name");
120}
Note: See TracBrowser for help on using the repository browser.