Browse Source

Changed signal that the session times out always in one minute.
Variable for time that the session times out soon renamed.

Daniel Knorr 10 years ago
parent
commit
27ef21ebf7
1 changed files with 13 additions and 14 deletions
  1. 13 14
      Libs/XNAT/Core/ctkXnatSession.cpp

+ 13 - 14
Libs/XNAT/Core/ctkXnatSession.cpp

@@ -70,10 +70,10 @@ public:
   QTimer* timer;
   QTimer* timer;
 
 
   // The time in milliseconds untill the signal sessionAboutToBeTimedOut gets emitted
   // The time in milliseconds untill the signal sessionAboutToBeTimedOut gets emitted
-  int timeToSessionTimesOutSoon;
+  int timeToSessionTimeOutWarning;
 
 
   // The time in milliseconds untill the signal sessionTimedOut gets emitted
   // The time in milliseconds untill the signal sessionTimedOut gets emitted
-  int timeToSessionTimedOut;
+  int timeToSessionTimedOut = 60000;
 
 
   ctkXnatSessionPrivate(const ctkXnatLoginProfile& loginProfile, ctkXnatSession* q);
   ctkXnatSessionPrivate(const ctkXnatLoginProfile& loginProfile, ctkXnatSession* q);
   ~ctkXnatSessionPrivate();
   ~ctkXnatSessionPrivate();
@@ -218,11 +218,10 @@ QDateTime ctkXnatSessionPrivate::updateExpirationDate(qRestResult* restResult)
           }
           }
           QByteArray timeSpan = expirationCookie[1];
           QByteArray timeSpan = expirationCookie[1];
           timeSpan.chop(1);
           timeSpan.chop(1);
-          this->timeToSessionTimesOutSoon = timeSpan.toInt() / 15 * 14;
-          this->timeToSessionTimedOut = timeSpan.toInt() / 15;
+          this->timeToSessionTimeOutWarning = timeSpan.toLong() - this->timeToSessionTimedOut;
           expirationDate = expirationDate.addMSecs(timeSpan.toLong());
           expirationDate = expirationDate.addMSecs(timeSpan.toLong());
           sessionProperties[SESSION_EXPIRATION_DATE] = expirationDate.toString(Qt::ISODate);
           sessionProperties[SESSION_EXPIRATION_DATE] = expirationDate.toString(Qt::ISODate);
-          this->timer->start(this->timeToSessionTimesOutSoon);
+          this->timer->start(this->timeToSessionTimeOutWarning);
           emit q->sessionRenewed(expirationDate);
           emit q->sessionRenewed(expirationDate);
         }
         }
       }
       }
@@ -495,7 +494,7 @@ QUuid ctkXnatSession::httpGet(const QString& resource, const ctkXnatSession::Url
 {
 {
   Q_D(ctkXnatSession);
   Q_D(ctkXnatSession);
   d->checkSession();
   d->checkSession();
-  d->timer->start(d->timeToSessionTimesOutSoon);
+  d->timer->start(d->timeToSessionTimeOutWarning);
   return d->xnat->get(resource, parameters, rawHeaders);
   return d->xnat->get(resource, parameters, rawHeaders);
 }
 }
 
 
@@ -510,7 +509,7 @@ QList<ctkXnatObject*> ctkXnatSession::httpResults(const QUuid& uuid, const QStri
   {
   {
     d->throwXnatException("Http request failed.");
     d->throwXnatException("Http request failed.");
   }
   }
-  d->timer->start(d->timeToSessionTimesOutSoon);
+  d->timer->start(d->timeToSessionTimeOutWarning);
   return d->results(restResult.data(), schemaType);
   return d->results(restResult.data(), schemaType);
 }
 }
 
 
@@ -541,7 +540,7 @@ bool ctkXnatSession::exists(const ctkXnatObject* object)
 
 
   QString query = object->resourceUri();
   QString query = object->resourceUri();
   bool success = d->xnat->sync(d->xnat->get(query));
   bool success = d->xnat->sync(d->xnat->get(query));
-  d->timer->start(d->timeToSessionTimesOutSoon);
+  d->timer->start(d->timeToSessionTimeOutWarning);
   return success;
   return success;
 }
 }
 
 
@@ -550,7 +549,7 @@ const QMap<QByteArray, QByteArray> ctkXnatSession::httpHeadSync(const QUuid &uui
 {
 {
   Q_D(ctkXnatSession);
   Q_D(ctkXnatSession);
   QScopedPointer<qRestResult> result (d->xnat->takeResult(uuid));
   QScopedPointer<qRestResult> result (d->xnat->takeResult(uuid));
-  d->timer->start(d->timeToSessionTimesOutSoon);
+  d->timer->start(d->timeToSessionTimeOutWarning);
   if (result == NULL)
   if (result == NULL)
   {
   {
     d->throwXnatException("Sending HEAD request failed.");
     d->throwXnatException("Sending HEAD request failed.");
@@ -563,7 +562,7 @@ QUuid ctkXnatSession::httpHead(const QString& resourceUri)
 {
 {
   Q_D(ctkXnatSession);
   Q_D(ctkXnatSession);
   QUuid queryId = d->xnat->head(resourceUri);
   QUuid queryId = d->xnat->head(resourceUri);
-  d->timer->start(d->timeToSessionTimesOutSoon);
+  d->timer->start(d->timeToSessionTimeOutWarning);
   return queryId;
   return queryId;
 }
 }
 
 
@@ -585,7 +584,7 @@ void ctkXnatSession::save(ctkXnatObject* object)
   qDebug() << "ctkXnatSession::save() query:" << query;
   qDebug() << "ctkXnatSession::save() query:" << query;
   QUuid queryId = d->xnat->put(query);
   QUuid queryId = d->xnat->put(query);
   qRestResult* result = d->xnat->takeResult(queryId);
   qRestResult* result = d->xnat->takeResult(queryId);
-  d->timer->start(d->timeToSessionTimesOutSoon);
+  d->timer->start(d->timeToSessionTimeOutWarning);
 
 
   if (!result || !result->error().isNull())
   if (!result || !result->error().isNull())
   {
   {
@@ -610,7 +609,7 @@ void ctkXnatSession::remove(ctkXnatObject* object)
 
 
   QString query = object->resourceUri();
   QString query = object->resourceUri();
   bool success = d->xnat->sync(d->xnat->del(query));
   bool success = d->xnat->sync(d->xnat->del(query));
-  d->timer->start(d->timeToSessionTimesOutSoon);
+  d->timer->start(d->timeToSessionTimeOutWarning);
 
 
   if (!success)
   if (!success)
   {
   {
@@ -628,7 +627,7 @@ void ctkXnatSession::download(const QString& fileName,
 
 
   QUuid queryId = d->xnat->download(fileName, resource, parameters, rawHeaders);
   QUuid queryId = d->xnat->download(fileName, resource, parameters, rawHeaders);
   d->xnat->sync(queryId);
   d->xnat->sync(queryId);
-  d->timer->start(d->timeToSessionTimesOutSoon);
+  d->timer->start(d->timeToSessionTimeOutWarning);
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
@@ -643,7 +642,7 @@ void ctkXnatSession::emitSessionTimeOut()
 {
 {
   Q_D(ctkXnatSession);
   Q_D(ctkXnatSession);
 
 
-  if (d->timer->interval() == d->timeToSessionTimesOutSoon)
+  if (d->timer->interval() == d->timeToSessionTimeOutWarning)
   {
   {
     d->timer->start(d->timeToSessionTimedOut);
     d->timer->start(d->timeToSessionTimedOut);
     emit sessionAboutToBeTimedOut();
     emit sessionAboutToBeTimedOut();