Просмотр исходного кода

Added timeOutForXmlRetrieval to the module backend class.

Sascha Zelzer лет назад: 11
Родитель
Сommit
60336025bc

+ 1 - 1
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerGeneralModuleSettings.cpp

@@ -43,5 +43,5 @@ void ctkCmdLineModuleExplorerGeneralModuleSettings::applySettings()
   QThreadPool::globalInstance()->setMaxThreadCount(maxParallelModules);
 
   int timeout = this->propertyValue(ctkCmdLineModuleExplorerConstants::KEY_XML_TIMEOUT_SECONDS).toInt();
-  this->CmdLineModuleManager->setXmlTimeout(timeout*1000);
+  this->CmdLineModuleManager->setTimeOutForXMLRetrieval(timeout*1000);
 }

+ 3 - 1
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerMainWindow.cpp

@@ -83,7 +83,9 @@ ctkCLModuleExplorerMainWindow::ctkCLModuleExplorerMainWindow(QWidget *parent) :
   {
     settings.setValue(ctkCmdLineModuleExplorerConstants::KEY_XML_TIMEOUT_SECONDS, QVariant(30));
   }
-  moduleManager.setXmlTimeout(settings.value(ctkCmdLineModuleExplorerConstants::KEY_XML_TIMEOUT_SECONDS, QVariant(30)).toInt() * 1000);
+  moduleManager.setTimeOutForXMLRetrieval(
+        settings.value(ctkCmdLineModuleExplorerConstants::KEY_XML_TIMEOUT_SECONDS, QVariant(30)
+                       ).toInt() * 1000);
 
   // Frontends
   moduleFrontendFactories << new ctkCmdLineModuleFrontendFactoryQtGui;

+ 13 - 11
Libs/CommandLineModules/Backend/LocalProcess/ctkCmdLineModuleBackendLocalProcess.cpp

@@ -43,20 +43,10 @@ struct ctkCmdLineModuleBackendLocalProcessPrivate
   int m_TimeoutForXMLRetrieval;
 
   ctkCmdLineModuleBackendLocalProcessPrivate()
-    : m_TimeoutForXMLRetrieval(30000) /* 30000 = default of QProcess */
+    : m_TimeoutForXMLRetrieval(0) // use the value from the module manager
   {
   }
 
-  void setTimeOutForXMLRetrieval(const int& timeOut)
-  {
-    m_TimeoutForXMLRetrieval = timeOut;
-  }
-
-  int timeOutForXMLRetrieval()
-  {
-    return m_TimeoutForXMLRetrieval;
-  }
-
   QString normalizeFlag(const QString& flag) const
   {
     return flag.trimmed().remove(QRegExp("^-*"));
@@ -217,3 +207,15 @@ ctkCmdLineModuleFuture ctkCmdLineModuleBackendLocalProcess::run(ctkCmdLineModule
       new ctkCmdLineModuleProcessTask(frontend->location().toLocalFile(), args);
   return moduleProcess->start();
 }
+
+//----------------------------------------------------------------------------
+void ctkCmdLineModuleBackendLocalProcess::setTimeOutForXMLRetrieval(int timeOut)
+{
+  d->m_TimeoutForXMLRetrieval = timeOut;
+}
+
+//----------------------------------------------------------------------------
+int ctkCmdLineModuleBackendLocalProcess::timeOutForXMLRetrieval() const
+{
+  return d->m_TimeoutForXMLRetrieval;
+}

+ 4 - 4
Libs/CommandLineModules/Backend/LocalProcess/ctkCmdLineModuleBackendLocalProcess.h

@@ -94,13 +94,13 @@ public:
    * @brief Setter for the number of milliseconds to wait when retrieving xml.
    * @param timeOut in milliseconds.
    */
-  void setTimeOutForXMLRetrieval(const int& timeOut);
+  void setTimeOutForXMLRetrieval(int timeOut);
 
   /**
-   * @brief returns the number of milliseconds to wait when retrieving xml.
-   * @return int in milliseconds
+   * @brief Returns the number of milliseconds to wait when retrieving xml.
+   * @return Time-out in milliseconds.
    */
-  int timeOutForXMLRetrieval();
+  virtual int timeOutForXMLRetrieval() const;
 
 private:
 

+ 6 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleBackend.cpp

@@ -33,3 +33,9 @@ QByteArray ctkCmdLineModuleBackend::rawXmlDescription(const QUrl& location)
 {
   return this->rawXmlDescription(location, 30000);
 }
+
+//----------------------------------------------------------------------------
+int ctkCmdLineModuleBackend::timeOutForXmlRetrieval() const
+{
+  return 0;
+}

+ 11 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleBackend.h

@@ -99,6 +99,17 @@ struct CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleBackend
   
   QByteArray rawXmlDescription(const QUrl& location);
 
+  /**
+   * @brief returns the number of milliseconds to wait when retrieving xml.
+   *
+   * The default implementation returns 0, which signals that the global
+   * timeout value from the ctkCmdLineModuleManager object with which this
+   * backend was registered should be used.
+   *
+   * @return int Time-out in milliseconds.
+   */
+  virtual int timeOutForXmlRetrieval() const;
+
 protected:
 
   friend class ctkCmdLineModuleManager;

+ 17 - 10
Libs/CommandLineModules/Core/ctkCmdLineModuleManager.cpp

@@ -1,22 +1,22 @@
 /*=============================================================================
-  
+
   Library: CTK
-  
+
   Copyright (c) German Cancer Research Center,
     Division of Medical and Biological Informatics
-    
+
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
-  
+
     http://www.apache.org/licenses/LICENSE-2.0
-    
+
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-  
+
 =============================================================================*/
 
 #include "ctkCmdLineModuleManager.h"
@@ -120,16 +120,17 @@ void ctkCmdLineModuleManager::setValidationMode(const ValidationMode& mode)
 
 
 //----------------------------------------------------------------------------
-void ctkCmdLineModuleManager::setXmlTimeout(int xmlTimeout)
+void ctkCmdLineModuleManager::setTimeOutForXMLRetrieval(int xmlTimeout)
 {
   d->XmlTimeOut = xmlTimeout;
 }
 
 //----------------------------------------------------------------------------
-int ctkCmdLineModuleManager::xmlTimeout() const
+int ctkCmdLineModuleManager::timeOutForXMLRetrieval() const
 {
   return d->XmlTimeOut;
 }
+
 //----------------------------------------------------------------------------
 void ctkCmdLineModuleManager::registerBackend(ctkCmdLineModuleBackend *backend)
 {
@@ -213,6 +214,12 @@ ctkCmdLineModuleManager::registerModule(const QUrl &location)
   bool fromCache = false;
   qint64 newTimeStamp = 0;
   qint64 cacheTimeStamp = 0;
+  int timeout = backend->timeOutForXmlRetrieval();
+  if (timeout == 0)
+  {
+    timeout = d->XmlTimeOut;
+  }
+
   if (d->ModuleCache)
   {
     newTimeStamp = backend->timeStamp(location);
@@ -223,7 +230,7 @@ ctkCmdLineModuleManager::registerModule(const QUrl &location)
       // newly fetch the XML description
       try
       {
-        xml = backend->rawXmlDescription(location, d->XmlTimeOut);
+        xml = backend->rawXmlDescription(location, timeout);
       }
       catch (const ctkCmdLineModuleTimeoutException&)
       {
@@ -249,7 +256,7 @@ ctkCmdLineModuleManager::registerModule(const QUrl &location)
   {
     try
     {
-      xml = backend->rawXmlDescription(location);
+      xml = backend->rawXmlDescription(location, timeout);
     }
     catch (const ctkCmdLineModuleRunException& e)
     {

+ 10 - 10
Libs/CommandLineModules/Core/ctkCmdLineModuleManager.h

@@ -1,22 +1,22 @@
 /*=============================================================================
-  
+
   Library: CTK
-  
+
   Copyright (c) German Cancer Research Center,
     Division of Medical and Biological Informatics
-    
+
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
-  
+
     http://www.apache.org/licenses/LICENSE-2.0
-    
+
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-  
+
 =============================================================================*/
 
 #ifndef CTKCMDLINEMODULEMANAGER_H
@@ -115,15 +115,15 @@ public:
    *
    * The default time-out is 30 seconds.
    *
-   * @param xmlTimeout The timeout in milli seconds.
+   * @param timeout The timeout in milli seconds.
    */
-  void setXmlTimeout(int xmlTimeout);
+  void setTimeOutForXMLRetrieval(int timeout);
 
   /**
-   * @brief Get the timeout for retrieving the XML parameter description from a ´module.
+   * @brief Get the timeout for retrieving the XML parameter description from a module.
    * @return The timeout in milli seconds.
    */
-  int xmlTimeout() const;
+  int timeOutForXMLRetrieval() const;
 
   /**
    * @brief Registers a new back-end.