ctkCmdLineModuleBackend.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKCMDLINEMODULEBACKEND_H
  16. #define CTKCMDLINEMODULEBACKEND_H
  17. #include "ctkCommandLineModulesCoreExport.h"
  18. class ctkCmdLineModuleFrontend;
  19. class ctkCmdLineModuleFuture;
  20. template<typename T> class QList;
  21. class QUrl;
  22. /**
  23. * @ingroup CommandLineModulesCore_API
  24. *
  25. * @brief Abstract base class for all back-end command line module
  26. * implementations.
  27. *
  28. * A back-end is responsible for providing the XML module description for a
  29. * given URL and its "timestamp". It also knows how to actually run a module,
  30. * using the current parameter values provided by a ctkCmdLineModuleFrontend instance.
  31. *
  32. * @see ctkCmdLineModuleBackendLocalProcess
  33. * @see ctkCmdLineModuleBackendFunctionPointer
  34. */
  35. struct CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleBackend
  36. {
  37. virtual ~ctkCmdLineModuleBackend();
  38. /**
  39. * @brief Returns the name of the type of the backend, not the name
  40. * of the thing or application that is run.
  41. * @return A QString containing the name.
  42. */
  43. virtual QString name() const = 0;
  44. /**
  45. * @brief Returns a brief description of the type of the backend.
  46. * @return A QString containing a description.
  47. */
  48. virtual QString description() const = 0;
  49. /**
  50. * @brief Returns a list of URL schemes this back-end can handle.
  51. * @return A list of "schemes", meaning the capabilities.
  52. */
  53. virtual QList<QString> schemes() const = 0;
  54. /**
  55. * @brief Returns a timestap of the backend, which for example in the
  56. * case of the LocalProcess may be the last modified time of the command line
  57. * application.
  58. */
  59. virtual qint64 timeStamp(const QUrl& location) const = 0;
  60. /**
  61. * @brief Get the XML parameter description from the given location.
  62. * @param location The location URL specifying the module.
  63. * @param timeout The time-out for retrieving the XML parameter description
  64. * @return The raw XML parameter description.
  65. *
  66. * This method may be concurrently called by the ctkCmdLineModuleManager and
  67. * must be thread-safe. Implementations must not use any caching mechanism,
  68. * as caching is done by the ctkCmdLineModuleManager itself, checking the
  69. * return value of timeStamp().
  70. *
  71. * Implementations should also throw either a ctkCmdLineModuleTimeoutException
  72. * object if a time-out occured when retrieving the XML parameter description
  73. * or a ctkCmdLineModuleRunException for any other error during invocation
  74. * of the module.
  75. *
  76. * @throws ctkCmdLineModuleTimeoutException if a time-out occurred when
  77. * retrieving the XML parameter description.
  78. * @throws ctkCmdLineModuleRunException if a runtime error occurred when
  79. * invoking the module to retrieve the XML parameter description.
  80. */
  81. virtual QByteArray rawXmlDescription(const QUrl& location, int timeout) = 0;
  82. /**
  83. * @brief Get the XML parameter description from the given location.
  84. * @param location The location URL specifying the module.
  85. * @return The raw XML parameter description.
  86. *
  87. * This method calls rawXmlDescription(const QUrl&, int) with a timeout
  88. * of 30 seconds.
  89. *
  90. * @throws ctkCmdLineModuleTimeoutException if a time-out occurred when
  91. * retrieving the XML parameter description.
  92. * @throws ctkCmdLineModuleRunException if a runtime error occurred when
  93. * invoking the module to retrieve the XML parameter description.
  94. */
  95. QByteArray rawXmlDescription(const QUrl& location);
  96. /**
  97. * @brief returns the number of milliseconds to wait when retrieving xml.
  98. *
  99. * The default implementation returns 0, which signals that the global
  100. * timeout value from the ctkCmdLineModuleManager object with which this
  101. * backend was registered should be used.
  102. *
  103. * @return int Time-out in milliseconds.
  104. */
  105. virtual int timeOutForXmlRetrieval() const;
  106. protected:
  107. friend class ctkCmdLineModuleManager;
  108. /**
  109. * @brief The main method to actually execute the back-end process.
  110. * @param frontend A pointer to a front end implementation.
  111. *
  112. * Implementations must execute the actual task of running the module asynchronously
  113. * and return from this method immediately. After returning from this method,
  114. * accessing the <code>frontend</code> pointer is not guaranteed to be safe.
  115. */
  116. virtual ctkCmdLineModuleFuture run(ctkCmdLineModuleFrontend* frontend) = 0;
  117. };
  118. #endif // CTKCMDLINEMODULEBACKEND_H