Changeset 10928


Ignore:
Timestamp:
06/08/11 14:59:22 (14 years ago)
Author:
ogrimm
Message:
Improved responsiveness of GUI at start-up
Location:
fact
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • fact/Evidence/GUI.cc

    r10280 r10928  
    8181  setFrame(false);
    8282  setAttribute(Qt::WA_DeleteOnClose);
     83  setText("connecting...");
    8384 
    8485  // Connect to DIM handler
    85   if (connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString))) == false) {
     86  if (connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString)), Qt::QueuedConnection) == false) {
    8687    printf("Failed connection for %s\n", Name.toAscii().data());
    8788  }
     
    242243 
    243244  // Connect to DIM handler
    244   if (connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString))) == false) {
     245  if (connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString)), Qt::QueuedConnection) == false) {
    245246    printf("Failed connection for %s\n", Service.toAscii().data());
    246247  }
     
    795796  setAttribute(Qt::WA_DeleteOnClose);
    796797  setAutoFillBackground(true);
     798  setText("connecting...");
    797799  document()->setMaximumBlockCount(1000);
    798800  Accumulate = true;
    799801 
    800802  // Connect to DIM handler
    801   if (connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString))) == false) {
     803  if (connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString)), Qt::QueuedConnection) == false) {
    802804    printf("Failed connection for %s\n", Name.toAscii().data());
    803805  }
     
    839841    Pal.setColor(QPalette::Base, Qt::lightGray);
    840842        setPalette(Pal);
     843    setText("n/a");
    841844        return;
    842845  }
     
    875878    printf("Failed connection in EddDim()\n");
    876879  }
     880
     881  // To ensure responsiveness of GUI, subscriptions handled only when no GUI events (timeout 0)
     882  Timer = new QTimer(this);
     883  connect(Timer, SIGNAL(timeout()), SLOT(MakeSubscriptions()));
     884  Timer->start();
    877885}
    878886
     
    886894}
    887895
    888 // Subscribe to DIM service
     896// Subscribe to DIM service (actual subscription handled in worker thread below)
    889897void EddDim::Subscribe(QString Name) {
    890898
    891899  // Lock before accessing list
    892900  QMutexLocker Locker(Mutex);
    893 
    894   // If already subscribed to service, increase usage count and reemit data for new subscriber
     901  WaitingList.append(Name);
     902}
     903
     904// Subscriptions handled only when no GUI events waiting (launched by timer, see constructor)
     905void EddDim::MakeSubscriptions() {
     906
     907  if (WaitingList.isEmpty()) return;
     908
     909  // Lock before accessing list
     910  QMutexLocker Locker(Mutex);
     911
     912  QString Name = WaitingList.first();
     913  WaitingList.removeFirst();
     914
     915  // If already subscribed to service, increase usage count
    895916  if (ServiceList.contains(Name)) {
    896917        ServiceList[Name].Count++;
    897         YEP(Name, ServiceList[Name].TimeStamp, ServiceList[Name].ByteArray, ServiceList[Name].Format, ServiceList[Name].Text);
     918        //YEP(Name, ServiceList[Name].TimeStamp, ServiceList[Name].ByteArray, ServiceList[Name].Format, ServiceList[Name].Text);
    898919        return;
    899920  }
     
    904925  ServiceList[Name].Count = 1;
    905926  ServiceList[Name].DIMService = new DimStampedInfo(Name.toAscii().data(), INT_MAX, NO_LINK, this);
    906   return;
    907 }
     927}
     928
    908929
    909930// Unsubsribe from DIM service
     
    973994}
    974995
     996// Force reemit of all buffered DIM data (work around for widget update problem)
     997void EddDim::ForceEmit() {
     998
     999  // Lock before accessing list
     1000  QMutexLocker Locker(Mutex);
     1001
     1002  QMap<QString, struct Item>::const_iterator i = ServiceList.constBegin();
     1003
     1004  while (i != ServiceList.constEnd()) {
     1005        YEP(i.key(), i.value().TimeStamp, i.value().ByteArray, i.value().Format, i.value().Text);
     1006     ++i;
     1007  }
     1008}
     1009
    9751010// Store service information for usage by Subscribe(), update statistics and emit signal to widgets
    9761011void EddDim::Update(QString Name, int Time, QByteArray Data, QString Format, QString Text) {
     
    10271062
    10281063  if (M->isVisible()) M->hide();
    1029   else M->show();
     1064  else {
     1065        M->show();
     1066        M->raise();
     1067  }
    10301068}
    10311069
  • fact/Evidence/GUI.h

    r10280 r10928  
    33
    44#include <QtGui>
    5  
     5#include <QtConcurrentRun>
     6
    67#include <qwt_plot.h>
    78#include <qwt_plot_curve.h>
     
    224225    QMap<QString, struct Item> ServiceList;
    225226    QMutex *Mutex;
     227        QList<QString> WaitingList;
    226228
    227229        struct HistItem {
     
    239241        void Update(QString, int, QByteArray, QString, QString);
    240242        void UpdateStatistics();
     243        void MakeSubscriptions();
    241244
    242245  public:
     
    248251        class EvidenceHistory *GetHistory(QString);
    249252        void DropHistory(QString);
     253        void ForceEmit();
    250254
    251255  signals:
  • fact/tools/Edd/Edd.cc

    r10912 r10928  
    732732  Scope->SetActive(!State);
    733733  StartStopButton->setText(State ? "Start" : "Stop");
    734   //if (!State) connect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), Scope, SLOT(Update(QString, int, QByteArray, QString, QString)));
    735   //else disconnect(Handler, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), Scope, SLOT(Update(QString, int, QByteArray, QString, QString)));
    736734}
    737735
     
    828826
    829827  Button = new QPushButton();
    830   Button->setText("Start DIM browser");
     828  Button->setText("DIM browser");
    831829  connect(Button, SIGNAL(released()), SLOT(StartDIMBrowser()));
    832830  Layout->addWidget(Button, 7, 1, 1, 1);
     
    904902  connect(Timer, SIGNAL(timeout()), this, SLOT(CheckAlarm()));
    905903  Timer->start(5000);
     904
     905  // Force update of all widgets constructed (in thread for GUI responsiveness)
     906  QtConcurrent::run(Handler, &EddDim::ForceEmit);
    906907
    907908   
Note: See TracChangeset for help on using the changeset viewer.