Changeset 247 in flair-src for trunk/tools/FlairGCS


Ignore:
Timestamp:
May 28, 2018, 6:23:35 PM (6 years ago)
Author:
Sanahuja Guillaume
Message:

improve gcs disconnections

Location:
trunk/tools/FlairGCS/src
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/FlairGCS/src/ConnectionLayout.cpp

    r244 r247  
    1818}
    1919
    20 QString ConnectionLayout::getUDTStats() {
    21   return socket->getUDTStats();
    22 }
    23 
    2420void ConnectionLayout::receive(char *buf, int size) {
    25   // fprintf(stderr,"trame %x\n",buf[0]);
     21   //fprintf(stderr,"trame %x\n",buf[0]);
    2622  // for(int i=0; i<size;i++) fprintf(stderr,"%x ",buf[i]);
    2723  // fprintf(stderr,"\n");
     
    5753    // fprintf(stderr,"recu %i period %i\n",size,period);
    5854    drawDatas(&buf[3], size - 3, period);
     55    break;
     56  }
     57  case CLOSING_CONNECTION: {
     58    deleteLater();
    5959    break;
    6060  }
  • trunk/tools/FlairGCS/src/ConnectionLayout.h

    r234 r247  
    2222  void LoadXml(QDomDocument to_parse);
    2323  QString getName();
    24   QString getUDTStats();
    2524  static QString getDocRootName(char* buf, int size);
    2625
  • trunk/tools/FlairGCS/src/Manager.cpp

    r244 r247  
    4646  // tab bar for multiple connections
    4747  tabBar = new QTabBar();
     48  //tabBar->setTabsClosable(true);
    4849  managerLayout->addWidget(tabBar);
    4950  connect(tabBar, SIGNAL(currentChanged(int)), this,
     
    9596  }
    9697
     98 
     99  icon_ok = QIcon(":green.png");
     100  icon_ko = QIcon(":red.png");
     101 
     102 
    97103  QTimer *timer = new QTimer(this);
    98104  connect(timer, SIGNAL(timeout()), this, SLOT(acceptConnections()));
     
    101107
    102108Manager::~Manager() {
    103   for (int i = 0; i < udtSockets.count(); i++) {
    104     udtSockets.at(i)->kill();
    105     udtSockets.at(i)->thread()->wait();
     109  for (int i = 0; i < connections.count(); i++) {
     110    connections.at(i).socket->kill();
     111    connections.at(i).socket->thread()->wait();
    106112  }
    107113
     
    127133    UdtSocket *udtSocket = new UdtSocket(socket,name);
    128134    udtSocket->moveToThread(thread);
    129     udtSockets.append(udtSocket);
    130 
     135   
    131136    connect(udtSocket, SIGNAL(newFileUI(UDTSOCKET)), this, SLOT(newFileUI(UDTSOCKET)));
    132137    connect(udtSocket, SIGNAL(newConnectionLayout(QString)), this, SLOT(newConnectionLayout(QString)),Qt::BlockingQueuedConnection);
     
    141146 
    142147  ConnectionLayout *newLayout = new ConnectionLayout(udtSocket, name);
    143   connectionsLayout.append(newLayout);
    144148  connect(udtSocket, SIGNAL(UDTStats(QString)), newLayout, SIGNAL(UDTStats(QString)));//connection in 2 steps to get udtsocket as sender
    145149  connect(newLayout, SIGNAL(UDTStats(QString)), this, SLOT(printUDTStats(QString)));
     
    147151  connect(newLayout, SIGNAL(destroyed(QObject *)), this, SLOT(layoutDestroyed(QObject *)));
    148152  connect(udtSocket, SIGNAL(destroyed(QObject *)), this, SLOT(udtSocketDestroyed(QObject *)));
    149   connect(udtSocket, SIGNAL(destroyed()), newLayout, SLOT(deleteLater()));
    150  
    151    // widget
     153 
     154  // widget
    152155  QWidget *newWidget = new QWidget();
    153   connectionsWidget.append(newWidget);
    154156  newWidget->setLayout(newLayout->getQGridLayout());
    155157  managerLayout->insertWidget(1, newWidget);
    156158  newWidget->hide();
    157159 
     160  connections_t connection;
     161  connection.layout=newLayout;
     162  connection.widget=newWidget;
     163  connection.socket=udtSocket;
     164  connections.append(connection);
     165 
    158166  //tab: avoid having only 1 tab (0, 2 or more)
    159   if (connectionsLayout.count() == 1) { // first connection
    160     connectionsWidget.at(0)->show();
     167  if (connections.count() == 1) { // first connection
     168    newWidget->show();
    161169    hiddenTabName = name;
    162170  }
    163   if (connectionsLayout.count() == 2) {
    164     tabBar->addTab(hiddenTabName);
     171  if (connections.count() == 2) {
     172    tabBar->addTab(icon_ok,hiddenTabName);
    165173    currentTab = 0;
    166174  }
    167   if (connectionsLayout.count() > 1) {
    168     tabBar->addTab(name);
     175  if (connections.count() > 1) {
     176    tabBar->addTab(icon_ok,name);
    169177  }
    170178}
    171179
    172180void Manager::udtSocketDestroyed(QObject *obj) {
    173   udtSockets.removeOne((UdtSocket *)obj);
     181  fprintf(stderr,"sockets -1\n");
     182  //mark socket as not valid, it can be a connection lost
     183  //in this case we keep the layout for reading, and mark it as problematic
     184  fprintf(stderr,"change icon\n");
     185  for(int i=0;i<connections.count();i++) {
     186    if(connections.at(i).socket==(UdtSocket *)obj) {
     187      connections[i].socket=NULL;
     188      break;
     189    }
     190  }
    174191}
    175192
    176193void Manager::layoutDestroyed(QObject *obj) {
    177   int index = connectionsLayout.indexOf((ConnectionLayout *)obj);
    178 
    179   delete connectionsWidget.at(index);
    180   connectionsWidget.removeAt(index);
    181   connectionsLayout.removeOne((ConnectionLayout *)obj);
    182  
    183   //tab: avoid having only 1 tab (0, 2 or more)
     194  fprintf(stderr,"layout -1\n");
     195  //remove the connection, it comes from a proper close
     196  int index=-1;
     197  for(int i=0;i<connections.count();i++) {
     198    if(connections.at(i).layout==(ConnectionLayout *)obj) {
     199      delete connections.at(i).widget;
     200      //connections[i].widget=NULL;
     201      //connections[i].layout=NULL;
     202      connections.removeAt(i);
     203      index=i;
     204      break;
     205    }
     206  }
     207 
     208  if(index==-1) {
     209    fprintf(stderr,"layoutDestroyed: error, layout not found!\n");
     210    return;
     211  }
     212 
     213  //tab: avoid having only 1 tab (only 0, 2 or more)
    184214  if (tabBar->count() > 1) {
    185215    tabBar->removeTab(index);
    186216  }
    187217
    188   if (connectionsLayout.count() == 1) {
     218  if (connections.count() == 1) {
    189219    hiddenTabName = tabBar->tabText(0);
    190220    tabBar->removeTab(0);
    191221  }
    192222
    193   if (connectionsLayout.count() == 0) {
     223  if (connections.count() == 0) {
    194224    status->showMessage("");
    195225  }
    196  
    197  
    198226}
    199227
    200228void Manager::newFileUI(UDTSOCKET socket) {
    201   //remove udtsocket as it will be automatically destroyed
    202   udtSockets.removeOne((UdtSocket *)sender());
    203  
    204229  QThread *thread = new QThread(this);
    205230  file_ui* fileUi = new file_ui(socket,name);
     
    216241
    217242void Manager::printUDTStats(QString stats) {
    218   int index = connectionsLayout.indexOf((ConnectionLayout *)sender());
     243  int index = -1;
     244  for(int i=0;i<connections.count();i++) {
     245    if(connections.at(i).layout==(ConnectionLayout *)sender()) {
     246      index=i;
     247      break;
     248    }
     249  }
     250 
    219251  if(index==-1) return;
    220252 
     
    230262  if (index >= 0) {
    231263    //if we are coming from layout destroyed
    232     if(currentTab<connectionsLayout.count()) connectionsWidget.at(currentTab)->hide();
    233     connectionsWidget.at(index)->show();
     264    if(currentTab<connections.count()) connections.at(currentTab).widget->hide();
     265    connections.at(index).widget->show();
    234266    currentTab = index;
    235267  } else {
    236268    currentTab = 0;
    237     connectionsWidget.at(0)->show();
    238   }
     269    connections.at(0).widget->show();
     270  }
     271  QString msg="not connected";
    239272  if (tabBar->count() == 0) {
    240     status->showMessage(connectionsLayout.at(0)->getUDTStats());
     273    if(connections.at(0).socket!=NULL) msg=connections.at(0).socket->getUDTStats();
     274   
    241275  } else {
    242     status->showMessage(QString("%1: %2").arg(tabBar->tabText(index)).arg(connectionsLayout.at(index)->getUDTStats()));
    243   }
     276    if(connections.at(index).socket!=NULL) msg=QString("%1: %2").arg(tabBar->tabText(index)).arg(connections.at(index).socket->getUDTStats());
     277  }
     278  status->showMessage(msg);
    244279}
    245280
     
    249284
    250285  if (dir_name != "") {
    251     for (int i = 0; i < connectionsLayout.count(); i++) {
     286    for (int i = 0; i < connections.count(); i++) {
    252287      QFile *file;
    253288      file = new QFile(dir_name + "/" +
    254                        connectionsLayout.at(i)->getName() + ".xml");
     289                       connections.at(i).layout->getName() + ".xml");
    255290      if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) {
    256291        QMessageBox::warning(this, "Warning",
    257292                             "Enable to load " +
    258                                  connectionsLayout.at(i)->getName() +
     293                                 connections.at(i).layout->getName() +
    259294                                 ".xml");
    260295        continue;
     
    268303        QMessageBox::critical(
    269304            this, "Error",
    270             "unable to read " + connectionsLayout.at(i)->getName() +
     305            "unable to read " + connections.at(i).layout->getName() +
    271306                ".xml" + " (" + errorMsg + " at " + QString::number(errorLine) +
    272307                "," + QString::number(errorColumn) + ")");
    273308      } else {
    274         connectionsLayout.at(i)->LoadXml(doc);
     309        connections.at(i).layout->LoadXml(doc);
    275310      }
    276311      delete file;
     
    282317  bool isUptodate = true;
    283318
    284   for (int i = 0; i < connectionsLayout.count(); i++) {
    285     if (!connectionsLayout.at(i)->IsUptodate()) {
     319  for (int i = 0; i < connections.count(); i++) {
     320    if (!connections.at(i).layout->IsUptodate()) {
    286321      isUptodate = false;
    287322      break;
     
    319354  QDir().mkdir(dir_name);
    320355
    321   for (int i = 0; i < connectionsLayout.count(); i++) {
     356  for (int i = 0; i < connections.count(); i++) {
    322357    QDomDocument *xml = new QDomDocument("remote_ui_xml");
    323358
    324     connectionsLayout.at(i)->GetFullXml((QDomElement *)xml);
    325 
    326     QFile fichier(dir_name + "/" + connectionsLayout.at(i)->getName() +
     359    connections.at(i).layout->GetFullXml((QDomElement *)xml);
     360
     361    QFile fichier(dir_name + "/" + connections.at(i).layout->getName() +
    327362                  ".xml");
    328363    QString write_doc = (xml->ownerDocument()).toString();
     
    344379
    345380void Manager::send(void) {
    346   for (int i = 0; i < connectionsLayout.count(); i++) {
     381  for (int i = 0; i < connections.count(); i++) {
    347382    QDomDocument doc("remote_ui_xml");
    348     connectionsLayout.at(i)->GetUpdateXml((QDomElement *)&doc);
     383    connections.at(i).layout->GetUpdateXml((QDomElement *)&doc);
    349384    // fprintf(stderr,"merge\n%s\n",doc.toString().toLocal8Bit().constData());
    350385
    351     connectionsLayout.at(i)->XmlToSend(doc);
     386    connections.at(i).layout->XmlToSend(doc);
    352387  }
    353388}
    354389
    355390void Manager::reset() {
    356   for (int i = 0; i < connectionsLayout.count(); i++)
    357     connectionsLayout.at(i)->ResetAllChilds();
    358 }
     391  for (int i = 0; i < connections.count(); i++)
     392    connections.at(i).layout->ResetAllChilds();
     393}
  • trunk/tools/FlairGCS/src/Manager.h

    r244 r247  
    77
    88#include <QWidget>
     9#include <QIcon>
    910#include <udt.h>
    1011#include <qdom.h>
     
    2829  UDTSOCKET serv;
    2930  QVBoxLayout *managerLayout;
    30   QList<ConnectionLayout *> connectionsLayout;
    31   QList<QWidget *> connectionsWidget;
    32   QList<UdtSocket *> udtSockets;
     31  typedef struct {
     32    ConnectionLayout *layout;
     33    QWidget *widget;
     34    UdtSocket *socket;
     35  } connections_t;
     36  QList<connections_t> connections;
     37  //QList<ConnectionLayout *> connectionsLayout;
     38  //QList<UdtSocket *> udtSockets;
    3339  QTabBar *tabBar;
    3440  QString name, hiddenTabName;
     
    4147  QGridLayout *button_layout;
    4248  QStatusBar *status;
     49  QIcon icon_ok,icon_ko;
    4350
    4451private slots:
  • trunk/tools/FlairGCS/src/UdtSocket.cpp

    r244 r247  
    5353  heartbeat_timer->stop();
    5454  udtstats_timer->stop();
    55   if(destroySocket) UDT::close(socket);         
     55  if(destroySocket) UDT::close(socket);
     56fprintf(stderr,"fin udt\n");
    5657}
    5758
     
    151152    int num = 1;
    152153    UDTSOCKET readfds;
     154 
    153155    int rv = UDT::epoll_wait2(eid, &readfds, &num,NULL, NULL,100);
    154  
    155156    if (rv == -1) {
    156157      if (UDT::getlasterror().getErrorCode() != 6003)
     
    158159    } else if(readfds==socket && num==1 && rv==1) {
    159160       
    160       int size=UDT::recvmsg(socket, buf, buf_size);
    161       if (size > 0) {
    162         total_received+=size;
    163        
    164         switch ((unsigned char)buf[0]) {
    165           case ZLIB_HEADER: {
    166             ssize_t out_size;
    167             uncompressBuffer(buf, size, uncompressbuf, &out_size);
    168             if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) {
    169               socketType=gui;
    170               QString remoteName=ConnectionLayout::getDocRootName(uncompressbuf, out_size);
    171               setName(remoteName);
    172               emit newConnectionLayout(remoteName);//connection is Qt::BlockingQueuedConnection
     161      int size;
     162      do {
     163        size=UDT::recvmsg(socket, buf, buf_size);
     164     
     165        //fprintf(stderr,"recu %i\n",size);
     166        if (size > 0) {
     167          total_received+=size;
     168         
     169          switch ((unsigned char)buf[0]) {
     170            case ZLIB_HEADER: {
     171              ssize_t out_size;
     172              uncompressBuffer(buf, size, uncompressbuf, &out_size);
     173              if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) {
     174                socketType=gui;
     175                QString remoteName=ConnectionLayout::getDocRootName(uncompressbuf, out_size);
     176                setName(remoteName);
     177                emit newConnectionLayout(remoteName);//connection is Qt::BlockingQueuedConnection
     178              }
     179              emit dataReady(uncompressbuf, out_size);//connection is Qt::BlockingQueuedConnection, as we have only one buffer
     180              break;
    173181            }
    174             emit dataReady(uncompressbuf, out_size);//connection is Qt::BlockingQueuedConnection, as we have only one buffer
    175             break;
     182            case START_SENDING_FILES: {
     183              if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) {
     184                socketType=log;
     185              }
     186              setName("log files");
     187              heartbeat_timer->stop();
     188              emit newFileUI(socket);
     189              deleteLater();
     190              stop=true;
     191              destroySocket=false;
     192              break;
     193            }
     194            case XML_HEADER:
     195              if(socketType==unknown) {
     196                socketType=gui;
     197                QString remoteName=ConnectionLayout::getDocRootName(buf, size );
     198                setName(remoteName);
     199                emit newConnectionLayout(remoteName);
     200              }
     201            case DATAS_BIG_ENDIAN:
     202            case DATAS_LITTLE_ENDIAN:
     203              emit dataReady(buf, size );
     204              break;
     205            case CLOSING_CONNECTION:
     206              fprintf(stderr,"%s, connection closed\n",name.toLocal8Bit().constData());
     207              emit dataReady(buf, size );
     208              stop = true;
     209              heartbeat_timer->stop();
     210              deleteLater();
     211              break;
     212            default:
     213              fprintf(stderr,"trame non supportée %x\n", buf[0]);
    176214          }
    177           case START_SENDING_FILES: {
    178             if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) {
    179               socketType=log;
    180             }
    181             setName("log files");
    182             heartbeat_timer->stop();
    183             emit newFileUI(socket);
    184             deleteLater();
    185             stop=true;
    186             destroySocket=false;
    187             break;
    188           }
    189           case XML_HEADER:
    190             if(socketType==unknown) {
    191               socketType=gui;
    192               QString remoteName=ConnectionLayout::getDocRootName(buf, size );
    193               setName(remoteName);
    194               emit newConnectionLayout(remoteName);
    195             }
    196           case DATAS_BIG_ENDIAN:
    197           case DATAS_LITTLE_ENDIAN:
    198             emit dataReady(buf, size );
    199             break;
     215        } else {
     216          //not necessary to check, watchdog (heartbeat_timer) can do it
     217          //if(UDT::getlasterror().getErrorCode()!=6002 && !stop)
     218            //fprintf(stderr,"udt socket: %s\n",UDT::getlasterror().getErrorMessage());
     219          //UDT::close(socket);//si deconnecté
     220          //free(buf);
     221          //break;
    200222        }
    201       } else {
    202         if(UDT::getlasterror().getErrorCode()!=6002)
    203           fprintf(stderr,"udt socket: %s %i\n",UDT::getlasterror().getErrorMessage(),size);
    204         //UDT::close(socket);//si deconnecté
    205         //free(buf);
    206         //break;
    207       }
     223      } while(size>0);
    208224    } else {
    209       fprintf(stderr,"udt socket: %s\n",UDT::getlasterror().getErrorMessage());
     225      //not necessary to check, watchdog (heartbeat_timer) can do it
     226      //fprintf(stderr,"udt socket: %s\n",UDT::getlasterror().getErrorMessage());
    210227    }
    211228    UDT::epoll_remove_usock(eid, socket);
    212229    UDT::epoll_release(eid);
    213230  }
     231 
    214232  free(uncompressbuf);
    215233  free(buf);
  • trunk/tools/FlairGCS/src/ressources.qrc

    r9 r247  
    55  <file>landmark.png</file>
    66  <file>cross.png</file>
     7  <file>green.png</file>
     8  <file>red.png</file>
    79</qresource>
    810</RCC>
Note: See TracChangeset for help on using the changeset viewer.