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

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

gcs:sync graphs

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