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.

129 lines
4.7KB

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