瀏覽代碼

Add time-out in ms for XML retrieval for local process

Matt Clarkson 10 年之前
父節點
當前提交
d60d0f2472

+ 30 - 1
Libs/CommandLineModules/Backend/LocalProcess/ctkCmdLineModuleBackendLocalProcess.cpp

@@ -39,6 +39,23 @@
 struct ctkCmdLineModuleBackendLocalProcessPrivate
 {
 
+  int m_TimeoutForXMLRetrieval;
+
+  ctkCmdLineModuleBackendLocalProcessPrivate()
+    : m_TimeoutForXMLRetrieval(30000) /* 30000 = default of QProcess */
+  {
+  }
+
+  void setTimeOutForXMLRetrieval(const int& timeOut)
+  {
+    m_TimeoutForXMLRetrieval = timeOut;
+  }
+
+  int timeOutForXMLRetrieval()
+  {
+    return m_TimeoutForXMLRetrieval;
+  }
+
   QString normalizeFlag(const QString& flag) const
   {
     return flag.trimmed().remove(QRegExp("^-*"));
@@ -165,13 +182,25 @@ qint64 ctkCmdLineModuleBackendLocalProcess::timeStamp(const QUrl &location) cons
 }
 
 //----------------------------------------------------------------------------
+void ctkCmdLineModuleBackendLocalProcess::setTimeOutForXMLRetrieval(const int& timeOut)
+{
+  d->setTimeOutForXMLRetrieval(timeOut);
+}
+
+//----------------------------------------------------------------------------
+int ctkCmdLineModuleBackendLocalProcess::timeOutForXMLRetrieval()
+{
+  return d->timeOutForXMLRetrieval();
+}
+
+//----------------------------------------------------------------------------
 QByteArray ctkCmdLineModuleBackendLocalProcess::rawXmlDescription(const QUrl &location)
 {
   QProcess process;
   process.setReadChannel(QProcess::StandardOutput);
   process.start(location.toLocalFile(), QStringList("--xml"));
 
-  if (!process.waitForFinished() || process.exitStatus() == QProcess::CrashExit ||
+  if (!process.waitForFinished(d->timeOutForXMLRetrieval()) || process.exitStatus() == QProcess::CrashExit ||
       process.error() != QProcess::UnknownError)
   {
     throw ctkCmdLineModuleRunException(location, process.exitCode(), process.errorString());

+ 12 - 0
Libs/CommandLineModules/Backend/LocalProcess/ctkCmdLineModuleBackendLocalProcess.h

@@ -90,6 +90,18 @@ public:
    */
   virtual ctkCmdLineModuleFuture run(ctkCmdLineModuleFrontend *frontend);
 
+  /**
+   * @brief Setter for the number of milliseconds to wait when retrieving xml.
+   * @param timeOut in milliseconds.
+   */
+  void setTimeOutForXMLRetrieval(const int& timeOut);
+
+  /**
+   * @brief returns the number of milliseconds to wait when retrieving xml.
+   * @return int in milliseconds
+   */
+  int timeOutForXMLRetrieval();
+
 private:
 
   QScopedPointer<ctkCmdLineModuleBackendLocalProcessPrivate> d;