ctkCmdLineModuleBackendXMLChecker.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) University College London
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =============================================================================*/
  14. #include "ctkCmdLineModuleBackendXMLChecker.h"
  15. #include "ctkCmdLineModuleXMLCheckerTask_p.h"
  16. #include "ctkCmdLineModuleFrontend.h"
  17. #include "ctkCmdLineModuleFuture.h"
  18. #include <QUrl>
  19. #include <QString>
  20. #include <QDateTime>
  21. #include <ctkUtils.h>
  22. //----------------------------------------------------------------------------
  23. struct ctkCmdLineModuleBackendXMLCheckerPrivate
  24. {
  25. QString m_HardCodedXML;
  26. };
  27. //----------------------------------------------------------------------------
  28. ctkCmdLineModuleBackendXMLChecker::ctkCmdLineModuleBackendXMLChecker(const QString &xmlToValidate)
  29. : d(new ctkCmdLineModuleBackendXMLCheckerPrivate)
  30. {
  31. d->m_HardCodedXML = xmlToValidate;
  32. }
  33. //----------------------------------------------------------------------------
  34. ctkCmdLineModuleBackendXMLChecker::~ctkCmdLineModuleBackendXMLChecker()
  35. {
  36. }
  37. //----------------------------------------------------------------------------
  38. QString ctkCmdLineModuleBackendXMLChecker::name() const
  39. {
  40. return "XML Checker";
  41. }
  42. //----------------------------------------------------------------------------
  43. QString ctkCmdLineModuleBackendXMLChecker::description() const
  44. {
  45. return "Fakes a backend process, returning a hard coded piece of XML, provided at construction time.";
  46. }
  47. //----------------------------------------------------------------------------
  48. QList<QString> ctkCmdLineModuleBackendXMLChecker::schemes() const
  49. {
  50. static QList<QString> supportedSchemes = QList<QString>() << "xml checker";
  51. return supportedSchemes;
  52. }
  53. //----------------------------------------------------------------------------
  54. qint64 ctkCmdLineModuleBackendXMLChecker::timeStamp(const QUrl & /*location*/) const
  55. {
  56. QDateTime now = QDateTime::currentDateTime();
  57. return ctk::msecsTo(QDateTime::fromTime_t(0), now);
  58. }
  59. //----------------------------------------------------------------------------
  60. QByteArray ctkCmdLineModuleBackendXMLChecker::rawXmlDescription(const QUrl &/*location*/)
  61. {
  62. return d->m_HardCodedXML.toAscii();
  63. }
  64. //----------------------------------------------------------------------------
  65. ctkCmdLineModuleFuture ctkCmdLineModuleBackendXMLChecker::run(ctkCmdLineModuleFrontend* /*frontend*/)
  66. {
  67. // Instances of ctkCmdLineModuleProcessTask are auto-deleted by the thread pool.
  68. ctkCmdLineModuleXMLCheckerTask* moduleProcess = new ctkCmdLineModuleXMLCheckerTask();
  69. return moduleProcess->start();
  70. }