Changeset 234 in flair-src for trunk/tools/FlairGCS/src/ConnectionLayout.cpp
- Timestamp:
- 04/10/18 17:05:27 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/FlairGCS/src/ConnectionLayout.cpp
r222 r234 8 8 #include <qendian.h> 9 9 #include "communication.h" 10 #include <zlib.h>11 #include <assert.h>12 13 #define COMPRESS_CHUNK 102414 #define RX_TIME 500015 10 16 11 ConnectionLayout::ConnectionLayout(UdtSocket *socket, QString name) 17 12 : Layout(NULL, name, "root") { 18 isRemoteNameDefined = false;19 13 this->socket = socket; 20 21 total_received=0; 22 receive_timer = new QTimer(this); 23 connect(receive_timer, SIGNAL(timeout()), this, SLOT(computeRxRate())); 24 receive_timer->start(RX_TIME); 14 this->name = name; 25 15 } 26 16 27 17 ConnectionLayout::~ConnectionLayout() { 28 receive_timer->stop();29 18 } 30 19 31 void ConnectionLayout::computeRxRate(void) { 32 float receive_rate=((float)total_received/(RX_TIME/1000))/1000;//in Ko/s 33 total_received=0; 34 computedRxRate(receive_rate); 20 QString ConnectionLayout::getUDTStats() { 21 return socket->getUDTStats(); 35 22 } 36 23 37 24 void ConnectionLayout::receive(char *buf, int size) { 38 total_received+=size-1;39 25 // printf("trame %x\n",buf[0]); 40 26 // for(int i=0; i<size;i++) printf("%x ",buf[i]); 41 27 // printf("\n"); 42 switch (buf[0]) {43 case ZLIB_HEADER: {44 ssize_t out_size;45 char *uncompressbuf;46 uncompressBuffer(buf, size, &uncompressbuf, &out_size);47 handleUncompressedFrame(uncompressbuf, out_size);48 free(uncompressbuf);49 break;50 }51 default:52 handleUncompressedFrame(buf, size);53 }54 free(buf);55 }56 57 void ConnectionLayout::XmlToSend(QDomDocument doc) {58 // printf("xml to send\n%s\n",doc.toString().toLocal8Bit().constData());59 // xml to send a mettre dans le manager60 QMetaObject::invokeMethod(61 socket, "write", Qt::BlockingQueuedConnection,62 Q_ARG(const char *, doc.toString().toLocal8Bit().constData()),63 Q_ARG(qint64, doc.toString().toLocal8Bit().length()));64 }65 66 void ConnectionLayout::LoadXml(QDomDocument to_parse) {67 if (!isRemoteNameDefined) {68 printf("load xml: name not defined!\n");69 return;70 }71 72 QDomElement tmp = to_parse.firstChildElement("root");73 while (tmp.attribute("name") != remoteName && !tmp.isNull())74 tmp = to_parse.nextSiblingElement("root");75 76 if (!tmp.isNull()) {77 XmlWidget::LoadXml(tmp);78 } else {79 printf("%s not found in xml file \n", remoteName.toLocal8Bit().constData());80 }81 }82 83 void ConnectionLayout::handleUncompressedFrame(char *buf, ssize_t size) {84 28 switch ((unsigned char)buf[0]) { 85 29 case XML_HEADER: { … … 92 36 if (!doc.setContent(xml)) { 93 37 printf("prob setContent fichier\n"); 94 }95 96 if (!isRemoteNameDefined) {97 isRemoteNameDefined = true;98 remoteName = doc.firstChildElement("root").attribute("name");99 setRemoteName(remoteName);100 SetAttribute("name", remoteName);101 38 } 102 39 … … 127 64 } 128 65 66 void ConnectionLayout::XmlToSend(QDomDocument doc) { 67 // printf("xml to send\n%s\n",doc.toString().toLocal8Bit().constData()); 68 69 // xml to send a mettre dans le manager 70 socket->write(doc.toString().toLocal8Bit().constData(),doc.toString().toLocal8Bit().length());/* 71 QMetaObject::invokeMethod( 72 socket, "write", Qt::BlockingQueuedConnection, 73 Q_ARG(const char *, doc.toString().toLocal8Bit().constData()), 74 Q_ARG(qint64, doc.toString().toLocal8Bit().length()));*/ 75 } 76 77 void ConnectionLayout::LoadXml(QDomDocument to_parse) { 78 QDomElement tmp = to_parse.firstChildElement("root"); 79 while (tmp.attribute("name") != name && !tmp.isNull()) 80 tmp = to_parse.nextSiblingElement("root"); 81 82 if (!tmp.isNull()) { 83 XmlWidget::LoadXml(tmp); 84 } else { 85 printf("%s not found in xml file \n", name.toLocal8Bit().constData()); 86 } 87 } 88 129 89 void ConnectionLayout::removeDataRemote(DataRemote *data) { 130 90 dataremotes.removeOne(data); … … 135 95 } 136 96 137 QString ConnectionLayout::get RemoteName() { return remoteName; }97 QString ConnectionLayout::getName() { return name; } 138 98 139 99 void ConnectionLayout::drawDatas(char *buf, int buf_size, uint16_t period, … … 144 104 } 145 105 146 int ConnectionLayout::uncompressBuffer(char *in, ssize_t in_size, char **out, 147 ssize_t *out_size) {148 int ret;149 unsigned have;150 z_stream strm;106 QString ConnectionLayout::getDocRootName(char* buf, int size) { 107 QString xml; 108 QDomDocument doc; 109 xml = QString((char *)buf); 110 xml.resize(size); 151 111 152 // allocate inflate state 153 strm.zalloc = Z_NULL; 154 strm.zfree = Z_NULL; 155 strm.opaque = Z_NULL; 156 strm.avail_in = 0; 157 strm.next_in = Z_NULL; 158 ret = inflateInit(&strm); 159 if (ret != Z_OK) 160 return ret; 161 162 *out = (char *)malloc(COMPRESS_CHUNK); 163 if (!(*out)) 164 return Z_BUF_ERROR; 165 166 strm.avail_in = in_size; 167 strm.next_in = (unsigned char *)in; 168 strm.avail_out = COMPRESS_CHUNK; 169 strm.next_out = (unsigned char *)*out; 170 171 ret = inflate(&strm, Z_NO_FLUSH); 172 assert(ret != Z_STREAM_ERROR); // state not clobbered 173 switch (ret) { 174 case Z_NEED_DICT: 175 ret = Z_DATA_ERROR; // and fall through 176 case Z_DATA_ERROR: 177 case Z_MEM_ERROR: 178 (void)inflateEnd(&strm); 179 return ret; 112 if (!doc.setContent(xml)) { 113 printf("prob setContent fichier\n"); 180 114 } 181 have = COMPRESS_CHUNK - strm.avail_out; 182 *out_size = have; 183 184 // printf("%i -> %i\n",in_size,have); 185 // printf("%s\n",*out); 186 // clean up and return 187 (void)inflateEnd(&strm); 188 return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; 115 116 return doc.firstChildElement("root").attribute("name"); 189 117 }
Note:
See TracChangeset
for help on using the changeset viewer.