OpenShot Audio Library | OpenShotAudio  0.6.0
juce_ChildProcessManager.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2022 - Raw Material Software Limited
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11  Agreement and JUCE Privacy Policy.
12 
13  End User License Agreement: www.juce.com/juce-7-licence
14  Privacy Policy: www.juce.com/juce-privacy-policy
15 
16  Or: You may also use this code under the terms of the GPL v3 (see
17  www.gnu.org/licenses).
18 
19  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21  DISCLAIMED.
22 
23  ==============================================================================
24 */
25 
26 namespace juce
27 {
47  class JUCE_API ChildProcessManager final : private DeletedAtShutdown
48  {
49  public:
50  #ifndef DOXYGEN
51  JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (ChildProcessManager)
52  #endif
53 
62  template <typename... Args>
63  std::shared_ptr<ChildProcess> createAndStartManagedChildProcess (Args&&... args)
64  {
65  auto p = std::make_shared<ChildProcess>();
66 
67  if (! p->start (std::forward<Args> (args)...))
68  return nullptr;
69 
70  processes.insert (p);
71  timer.startTimer (1000);
72 
73  return p;
74  }
75 
80  auto addChildProcessExitedListener (std::function<void (ChildProcess*)> listener)
81  {
82  return listeners.addListener (std::move (listener));
83  }
84 
88  auto hasRunningProcess() const
89  {
90  return timer.isTimerRunning();
91  }
92 
93  private:
94  ChildProcessManager() = default;
95  ~ChildProcessManager() override { clearSingletonInstance(); }
96 
97  void checkProcesses();
98 
99  std::set<std::shared_ptr<ChildProcess>> processes;
100  detail::CallbackListenerList<ChildProcess*> listeners;
101  TimedCallback timer { [this] { checkProcesses(); } };
102  };
103 
104 } // namespace juce
auto addChildProcessExitedListener(std::function< void(ChildProcess *)> listener)
std::shared_ptr< ChildProcess > createAndStartManagedChildProcess(Args &&... args)