Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChildProcess.h 4.5KB

7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. ==============================================================================
  3. This file is part of the Water library.
  4. Copyright (c) 2016 ROLI Ltd.
  5. Copyright (C) 2017 Filipe Coelho <falktx@falktx.com>
  6. Permission is granted to use this software under the terms of the ISC license
  7. http://www.isc.org/downloads/software-support-policy/isc-license/
  8. Permission to use, copy, modify, and/or distribute this software for any
  9. purpose with or without fee is hereby granted, provided that the above
  10. copyright notice and this permission notice appear in all copies.
  11. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  12. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  13. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  14. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  15. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  17. OF THIS SOFTWARE.
  18. ==============================================================================
  19. */
  20. #ifndef WATER_CHILDPROCESS_H_INCLUDED
  21. #define WATER_CHILDPROCESS_H_INCLUDED
  22. #include "../text/StringArray.h"
  23. #include "CarlaJuceUtils.hpp"
  24. namespace water {
  25. //==============================================================================
  26. /**
  27. Launches and monitors a child process.
  28. This class lets you launch an executable, and read its output. You can also
  29. use it to check whether the child process has finished.
  30. */
  31. class ChildProcess
  32. {
  33. public:
  34. //==============================================================================
  35. /** Creates a process object.
  36. To actually launch the process, use start().
  37. */
  38. ChildProcess();
  39. /** Destructor.
  40. Note that deleting this object won't terminate the child process.
  41. */
  42. ~ChildProcess();
  43. /** These flags are used by the start() methods. */
  44. enum StreamFlags
  45. {
  46. wantStdOut = 1,
  47. wantStdErr = 2
  48. };
  49. /** Attempts to launch a child process command.
  50. The command should be the name of the executable file, followed by any arguments
  51. that are required.
  52. If the process has already been launched, this will launch it again. If a problem
  53. occurs, the method will return false.
  54. The streamFlags is a combinations of values to indicate which of the child's output
  55. streams should be read and returned by readProcessOutput().
  56. */
  57. bool start (const String& command, int streamFlags = wantStdOut | wantStdErr);
  58. /** Attempts to launch a child process command.
  59. The first argument should be the name of the executable file, followed by any other
  60. arguments that are needed.
  61. If the process has already been launched, this will launch it again. If a problem
  62. occurs, the method will return false.
  63. The streamFlags is a combinations of values to indicate which of the child's output
  64. streams should be read and returned by readProcessOutput().
  65. */
  66. bool start (const StringArray& arguments, int streamFlags = wantStdOut | wantStdErr);
  67. /** Returns true if the child process is alive. */
  68. bool isRunning() const;
  69. /** Attempts to read some output from the child process.
  70. This will attempt to read up to the given number of bytes of data from the
  71. process. It returns the number of bytes that were actually read.
  72. */
  73. int readProcessOutput (void* destBuffer, int numBytesToRead);
  74. /** Blocks until the process has finished, and then returns its complete output
  75. as a string.
  76. */
  77. String readAllProcessOutput();
  78. /** Blocks until the process is no longer running. */
  79. bool waitForProcessToFinish (int timeoutMs) const;
  80. /** If the process has finished, this returns its exit code. */
  81. uint32 getExitCode() const;
  82. /** Attempts to kill the child process.
  83. Returns true if it succeeded. Trying to read from the process after calling this may
  84. result in undefined behaviour.
  85. */
  86. bool kill();
  87. bool terminate();
  88. uint32 getPID() const noexcept;
  89. private:
  90. //==============================================================================
  91. class ActiveProcess;
  92. ScopedPointer<ActiveProcess> activeProcess;
  93. CARLA_DECLARE_NON_COPY_CLASS (ChildProcess)
  94. };
  95. }
  96. #endif // WATER_CHILDPROCESS_H_INCLUDED