ctkCmdLineModuleFuture.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include "ctkCmdLineModuleFuture.h"
  16. struct ctkCmdLineModuleFutureInterfacePrivate
  17. {
  18. ctkCmdLineModuleFutureInterfacePrivate()
  19. : refCount(1), _exitCode(0), _exitStatus(QProcess::NormalExit),
  20. _processError(QProcess::UnknownError)
  21. {}
  22. QAtomicInt refCount;
  23. int _exitCode;
  24. QProcess::ExitStatus _exitStatus;
  25. QProcess::ProcessError _processError;
  26. QString _errorString;
  27. QString _stdOut;
  28. QString _stdErr;
  29. };
  30. ctkCmdLineModuleFutureInterface::QFutureInterface(State initialState)
  31. : QFutureInterfaceBase(initialState), d(new ctkCmdLineModuleFutureInterfacePrivate)
  32. { }
  33. ctkCmdLineModuleFutureInterface::QFutureInterface(const ctkCmdLineModuleFutureInterface& other)
  34. : QFutureInterfaceBase(other), d(other.d)
  35. {
  36. d->refCount.ref();
  37. }
  38. ctkCmdLineModuleFutureInterface ctkCmdLineModuleFutureInterface::canceledResult()
  39. { return ctkCmdLineModuleFutureInterface(State(Started | Finished | Canceled)); }
  40. ctkCmdLineModuleFutureInterface& ctkCmdLineModuleFutureInterface::operator=(const ctkCmdLineModuleFutureInterface& other)
  41. {
  42. QFutureInterfaceBase::operator=(other);
  43. other.d->refCount.ref();
  44. if(!d->refCount.deref()) delete d;
  45. d = other.d;
  46. return *this;
  47. }
  48. int ctkCmdLineModuleFutureInterface::exitCode() const
  49. { QMutexLocker lock(this->mutex()); return d->_exitCode; }
  50. void ctkCmdLineModuleFutureInterface::reportExitCode(int code)
  51. { QMutexLocker lock(this->mutex()); d->_exitCode = code; }
  52. QProcess::ExitStatus ctkCmdLineModuleFutureInterface::exitStatus() const
  53. { QMutexLocker lock(this->mutex()); return d->_exitStatus; }
  54. void ctkCmdLineModuleFutureInterface::reportExitStatus(QProcess::ExitStatus status)
  55. { QMutexLocker lock(this->mutex()); d->_exitStatus = status; }
  56. QProcess::ProcessError ctkCmdLineModuleFutureInterface::error() const
  57. { QMutexLocker lock(this->mutex()); return d->_processError; }
  58. void ctkCmdLineModuleFutureInterface::reportProcessError(QProcess::ProcessError procErr)
  59. { QMutexLocker lock(this->mutex()); d->_processError = procErr; }
  60. QString ctkCmdLineModuleFutureInterface::errorString() const
  61. { QMutexLocker lock(this->mutex()); return d->_errorString; }
  62. void ctkCmdLineModuleFutureInterface::reportErrorString(const QString& errorStr)
  63. { QMutexLocker lock(this->mutex()); d->_errorString = errorStr; }
  64. QString ctkCmdLineModuleFutureInterface::standardOutput() const
  65. { QMutexLocker lock(this->mutex()); return d->_stdOut; }
  66. void ctkCmdLineModuleFutureInterface::reportStandardOutput(const QString& stdOut)
  67. { QMutexLocker lock(this->mutex()); d->_stdOut = stdOut; }
  68. QString ctkCmdLineModuleFutureInterface::standardError() const
  69. { QMutexLocker lock(this->mutex()); return d->_stdErr; }
  70. void ctkCmdLineModuleFutureInterface::reportStandardError(const QString& stdErr)
  71. { QMutexLocker lock(this->mutex()); d->_stdErr = stdErr; }