Changeset 247 in flair-src for trunk/tools/FlairGCS/src/Manager.cpp


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

improve gcs disconnections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.