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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. ==============================================================================
  3. This file is part of the Water library.
  4. Copyright (c) 2016 ROLI Ltd.
  5. Copyright (C) 2017-2022 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 "CarlaScopeUtils.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. /** Child process type, only used in macOS. */
  36. enum Type {
  37. TypeAny,
  38. TypeARM,
  39. TypeIntel
  40. };
  41. /** Creates a process object.
  42. To actually launch the process, use start().
  43. */
  44. ChildProcess();
  45. /** Destructor.
  46. Note that deleting this object won't terminate the child process.
  47. */
  48. ~ChildProcess();
  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, Type type = TypeAny);
  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, Type type = TypeAny);
  67. /** Returns true if the child process is alive. */
  68. bool isRunning() const;
  69. /** Blocks until the process is no longer running. */
  70. bool waitForProcessToFinish (int timeoutMs);
  71. /** If the process has finished, this returns its exit code and also clears assigned PID. */
  72. uint32 getExitCodeAndClearPID();
  73. /** Attempts to kill the child process.
  74. Returns true if it succeeded. Trying to read from the process after calling this may
  75. result in undefined behaviour.
  76. */
  77. bool kill();
  78. bool terminate();
  79. uint32 getPID() const noexcept;
  80. private:
  81. //==============================================================================
  82. class ActiveProcess;
  83. CarlaScopedPointer<ActiveProcess> activeProcess;
  84. CARLA_DECLARE_NON_COPYABLE (ChildProcess)
  85. };
  86. }
  87. #endif // WATER_CHILDPROCESS_H_INCLUDED