ctkCmdLineModuleBackendXMLChecker.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. QDateTime m_LastModified;
  27. };
  28. //----------------------------------------------------------------------------
  29. ctkCmdLineModuleBackendXMLChecker::ctkCmdLineModuleBackendXMLChecker()
  30. : d(new ctkCmdLineModuleBackendXMLCheckerPrivate)
  31. {
  32. d->m_HardCodedXML = QString("");
  33. d->m_LastModified = QDateTime::currentDateTime();
  34. }
  35. //----------------------------------------------------------------------------
  36. ctkCmdLineModuleBackendXMLChecker::ctkCmdLineModuleBackendXMLChecker(const QString &xmlToValidate)
  37. : d(new ctkCmdLineModuleBackendXMLCheckerPrivate)
  38. {
  39. d->m_HardCodedXML = xmlToValidate;
  40. d->m_LastModified = QDateTime::currentDateTime();
  41. }
  42. //----------------------------------------------------------------------------
  43. ctkCmdLineModuleBackendXMLChecker::~ctkCmdLineModuleBackendXMLChecker()
  44. {
  45. }
  46. //----------------------------------------------------------------------------
  47. void ctkCmdLineModuleBackendXMLChecker::setXML(const QString& xml)
  48. {
  49. d->m_HardCodedXML = xml;
  50. d->m_LastModified = QDateTime::currentDateTime();
  51. }
  52. //----------------------------------------------------------------------------
  53. QString ctkCmdLineModuleBackendXMLChecker::xml() const
  54. {
  55. return d->m_HardCodedXML;
  56. }
  57. //----------------------------------------------------------------------------
  58. QString ctkCmdLineModuleBackendXMLChecker::name() const
  59. {
  60. return "XML Checker";
  61. }
  62. //----------------------------------------------------------------------------
  63. QString ctkCmdLineModuleBackendXMLChecker::description() const
  64. {
  65. return "Fakes a backend process, returning a static piece of XML.";
  66. }
  67. //----------------------------------------------------------------------------
  68. QList<QString> ctkCmdLineModuleBackendXMLChecker::schemes() const
  69. {
  70. static QList<QString> supportedSchemes = QList<QString>() << "xmlchecker";
  71. return supportedSchemes;
  72. }
  73. //----------------------------------------------------------------------------
  74. qint64 ctkCmdLineModuleBackendXMLChecker::timeStamp(const QUrl & /*location*/) const
  75. {
  76. return ctk::msecsTo(QDateTime::fromTime_t(0), d->m_LastModified);
  77. }
  78. //----------------------------------------------------------------------------
  79. QByteArray ctkCmdLineModuleBackendXMLChecker::rawXmlDescription(const QUrl &/*location*/)
  80. {
  81. return d->m_HardCodedXML.toAscii();
  82. }
  83. //----------------------------------------------------------------------------
  84. ctkCmdLineModuleFuture ctkCmdLineModuleBackendXMLChecker::run(ctkCmdLineModuleFrontend* /*frontend*/)
  85. {
  86. // Instances of ctkCmdLineModuleProcessTask are auto-deleted by the thread pool.
  87. ctkCmdLineModuleXMLCheckerTask* moduleProcess = new ctkCmdLineModuleXMLCheckerTask();
  88. return moduleProcess->start();
  89. }