Parcourir la source

Added XMLChecker CLI backend

Matt Clarkson il y a 11 ans
Parent
commit
adf1a01ac5

+ 1 - 0
Applications/ctkCommandLineModuleExplorer/target_libraries.cmake

@@ -7,6 +7,7 @@
 set(target_libraries
   CTKCommandLineModulesFrontendQtGui
   CTKCommandLineModulesFrontendQtWebKit
+  CTKCommandLineModulesBackendXMLChecker
   CTKCommandLineModulesBackendLocalProcess
   CTKCommandLineModulesBackendFunctionPointer
   CTKWidgets

+ 3 - 0
CMakeLists.txt

@@ -484,6 +484,9 @@ ctk_lib_option(CommandLineModules/Frontend/QtWebKit
 ctk_lib_option(CommandLineModules/Frontend/QtGui
                "Build the QtGui based Command Line Module front-end" OFF)
 
+ctk_lib_option(CommandLineModules/Backend/XMLChecker
+               "Build the Command Line Module back-end for checking XML" OFF)
+
 ctk_lib_option(CommandLineModules/Backend/LocalProcess
                "Build the Command Line Module back-end for local processes" OFF)
 

+ 62 - 0
Libs/CommandLineModules/Backend/XMLChecker/CMakeLists.txt

@@ -0,0 +1,62 @@
+project(CTKCommandLineModulesBackendXMLChecker)
+
+#
+# 3rd party dependencies
+#
+
+#
+# See CTK/CMake/ctkMacroBuildLib.cmake for details
+#
+
+set(KIT_export_directive "CTK_CMDLINEMODULEBACKENDXMLCHECKER_EXPORT")
+
+# Additional directories to include
+
+# Source files
+set(KIT_SRCS
+  ctkCmdLineModuleXMLCheckerTask.cpp
+  ctkCmdLineModuleBackendXMLChecker.cpp
+)
+
+# Headers that should run through moc
+set(KIT_MOC_SRCS
+)
+
+# UI files
+set(KIT_UI_FORMS
+)
+
+# Resources
+set(KIT_resources
+)
+
+# Target libraries - See CMake/ctkFunctionGetTargetLibraries.cmake
+# The following macro will read the target libraries from the file 'target_libraries.cmake'
+ctkFunctionGetTargetLibraries(KIT_target_libraries)
+
+ctkMacroBuildLib(
+  NAME ${PROJECT_NAME}
+  EXPORT_DIRECTIVE ${KIT_export_directive}
+  INCLUDE_DIRECTORIES ${KIT_include_directories}
+  SRCS ${KIT_SRCS}
+  MOC_SRCS ${KIT_MOC_SRCS}
+  UI_FORMS ${KIT_UI_FORMS}
+  TARGET_LIBRARIES ${KIT_target_libraries}
+  RESOURCES ${KIT_resources}
+  LIBRARY_TYPE ${CTK_LIBRARY_MODE}
+  )
+
+target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES})
+
+if(CTK_WRAP_PYTHONQT_FULL OR CTK_WRAP_PYTHONQT_LIGHT)
+  ctkMacroBuildLibWrapper(
+    TARGET ${PROJECT_NAME}
+    SRCS ${KIT_SRCS}
+    WRAPPER_LIBRARY_TYPE ${CTK_LIBRARY_MODE}
+    )
+endif()
+
+# Testing
+if(BUILD_TESTING)
+  #add_subdirectory(Testing)
+endif()

+ 95 - 0
Libs/CommandLineModules/Backend/XMLChecker/ctkCmdLineModuleBackendXMLChecker.cpp

@@ -0,0 +1,95 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) University College London
+
+  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 "ctkCmdLineModuleBackendXMLChecker.h"
+#include "ctkCmdLineModuleXMLCheckerTask_p.h"
+
+#include "ctkCmdLineModuleFrontend.h"
+#include "ctkCmdLineModuleFuture.h"
+#include <QUrl>
+#include <QString>
+#include <QDateTime>
+#include <ctkUtils.h>
+
+//----------------------------------------------------------------------------
+struct ctkCmdLineModuleBackendXMLCheckerPrivate
+{
+  QString m_HardCodedXML;
+};
+
+
+//----------------------------------------------------------------------------
+ctkCmdLineModuleBackendXMLChecker::ctkCmdLineModuleBackendXMLChecker(const QString &xmlToValidate)
+  : d(new ctkCmdLineModuleBackendXMLCheckerPrivate)
+{
+  d->m_HardCodedXML = xmlToValidate;
+}
+
+
+//----------------------------------------------------------------------------
+ctkCmdLineModuleBackendXMLChecker::~ctkCmdLineModuleBackendXMLChecker()
+{
+}
+
+
+//----------------------------------------------------------------------------
+QString ctkCmdLineModuleBackendXMLChecker::name() const
+{
+  return "XML Checker";
+}
+
+
+//----------------------------------------------------------------------------
+QString ctkCmdLineModuleBackendXMLChecker::description() const
+{
+  return "Fakes a backend process, returning a hard coded piece of XML, provided at construction time.";
+}
+
+
+//----------------------------------------------------------------------------
+QList<QString> ctkCmdLineModuleBackendXMLChecker::schemes() const
+{
+  static QList<QString> supportedSchemes = QList<QString>() << "xml checker";
+  return supportedSchemes;
+}
+
+
+//----------------------------------------------------------------------------
+qint64 ctkCmdLineModuleBackendXMLChecker::timeStamp(const QUrl & /*location*/) const
+{
+  QDateTime now = QDateTime::currentDateTime();
+  return ctk::msecsTo(QDateTime::fromTime_t(0), now);
+}
+
+
+//----------------------------------------------------------------------------
+QByteArray ctkCmdLineModuleBackendXMLChecker::rawXmlDescription(const QUrl &/*location*/)
+{
+  return d->m_HardCodedXML.toAscii();
+}
+
+
+//----------------------------------------------------------------------------
+ctkCmdLineModuleFuture ctkCmdLineModuleBackendXMLChecker::run(ctkCmdLineModuleFrontend* /*frontend*/)
+{
+  // Instances of ctkCmdLineModuleProcessTask are auto-deleted by the thread pool.
+  ctkCmdLineModuleXMLCheckerTask* moduleProcess = new ctkCmdLineModuleXMLCheckerTask();
+  return moduleProcess->start();
+}

+ 87 - 0
Libs/CommandLineModules/Backend/XMLChecker/ctkCmdLineModuleBackendXMLChecker.h

@@ -0,0 +1,87 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) University College London
+
+  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 CTKCMDLINEMODULEBACKENDXMLCHECKER_H
+#define CTKCMDLINEMODULEBACKENDXMLCHECKER_H
+
+#include "ctkCmdLineModuleBackend.h"
+
+#include "ctkCommandLineModulesBackendXMLCheckerExport.h"
+
+#include <QScopedPointer>
+
+struct ctkCmdLineModuleBackendXMLCheckerPrivate;
+
+/**
+ * @ingroup CommandLineModulesBackendXMLChecker_API
+ *
+ * @brief Provides a ctkCmdLineModuleBackend implementation
+ * to pretend to run a command line process, but actually
+ * it returns a fixed, static piece of XML which can then
+ * be validated by the core library.
+ */
+class CTK_CMDLINEMODULEBACKENDXMLCHECKER_EXPORT ctkCmdLineModuleBackendXMLChecker : public ctkCmdLineModuleBackend
+{
+
+public:
+
+  ctkCmdLineModuleBackendXMLChecker(const QString &xmlToValidate);
+  ~ctkCmdLineModuleBackendXMLChecker();
+
+  virtual QString name() const;
+  virtual QString description() const;
+
+  /**
+   * @brief This back-end can handle the "xml checker" URL scheme.
+   * @return Returns the schemes this back-end can handle.
+   */
+  virtual QList<QString> schemes() const;
+
+  /**
+   * @brief Returns the last modified time of the module at \c location.
+   * @param location The location URL of the module for which to get the timestamp.
+   * @return A timestamp.
+   */
+  virtual qint64 timeStamp(const QUrl &location) const;
+
+  /**
+   * @brief Get the raw XML description from the module at \c location.
+   * @param location The location URL of the module for which to get the XML description.
+   * @return The raw XML description.
+   *
+   * This method always calls the executable with a \c &ndash;&ndash;xml argument and returns
+   * the complete data emitted on the standard output channel.
+   */
+  virtual QByteArray rawXmlDescription(const QUrl& location);
+
+  /**
+   * @brief Run a front-end for this module in a local process.
+   * @param frontend The front-end to run.
+   * @return A future object for communicating with the running process.
+   */
+  virtual ctkCmdLineModuleFuture run(ctkCmdLineModuleFrontend *frontend);
+
+private:
+
+  QScopedPointer<ctkCmdLineModuleBackendXMLCheckerPrivate> d;
+
+};
+
+#endif // CTKCMDLINEMODULEBACKENDLOCALPROCESS_H

+ 61 - 0
Libs/CommandLineModules/Backend/XMLChecker/ctkCmdLineModuleXMLCheckerTask.cpp

@@ -0,0 +1,61 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) University College London
+
+  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 "ctkCmdLineModuleXMLCheckerTask_p.h"
+#include "ctkCmdLineModuleFuture.h"
+
+#include <QThreadPool>
+
+//----------------------------------------------------------------------------
+ctkCmdLineModuleXMLCheckerTask::ctkCmdLineModuleXMLCheckerTask()
+{
+}
+
+
+//----------------------------------------------------------------------------
+ctkCmdLineModuleFuture ctkCmdLineModuleXMLCheckerTask::start()
+{
+  this->setRunnable(this);
+  this->setProgressRange(0,0);
+  this->reportStarted();
+
+  ctkCmdLineModuleFuture future = this->future();
+  QThreadPool::globalInstance()->start(this, /*m_priority*/ 0);
+
+  return future;
+}
+
+
+//----------------------------------------------------------------------------
+void ctkCmdLineModuleXMLCheckerTask::run()
+{
+  if (this->isCanceled())
+  {
+    this->reportFinished();
+    return;
+  }
+
+  // Actually nothing to do, as we don't actually run the process.
+
+  // Report a successful finish.
+  this->setProgressRange(0,1);
+  this->setProgressValue(1);
+  this->reportFinished();
+}

+ 45 - 0
Libs/CommandLineModules/Backend/XMLChecker/ctkCmdLineModuleXMLCheckerTask_p.h

@@ -0,0 +1,45 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) University College London
+
+  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 CTKCMDLINEMODULEXMLCHECKERTASK_P_H
+#define CTKCMDLINEMODULEXMLCHECKERTASK_P_H
+
+#include <ctkCmdLineModuleFutureInterface.h>
+#include <QRunnable>
+
+/**
+ * \class ctkCmdLineModuleXMLCheckerTask
+ * \brief Provides a ctkCmdLineModuleFutureInterface implementation specifically to
+ * run an XML Checker asynchronously.
+ * \ingroup CommandLineModulesBackendXMLChecker_API
+ */
+class ctkCmdLineModuleXMLCheckerTask : public ctkCmdLineModuleFutureInterface, public QRunnable
+{
+public:
+
+  ctkCmdLineModuleXMLCheckerTask();
+  ctkCmdLineModuleFuture start();
+
+  void run();
+
+private:
+};
+
+#endif // CTKCMDLINEMODULEXMLCHECKERTASK_P_H

+ 9 - 0
Libs/CommandLineModules/Backend/XMLChecker/target_libraries.cmake

@@ -0,0 +1,9 @@
+#
+# See CMake/ctkMacroGetTargetLibraries.cmake
+# 
+# This file should list the libraries required to build the current CTK libraries
+#
+
+set(target_libraries
+  CTKCommandLineModulesCore
+  )