JUCE v8.0.9
JUCE API
 
Loading...
Searching...
No Matches
juce::ChildProcessManager Class Referencefinal

Manages a set of ChildProcesses and periodically checks their return value. More...

#include <juce_ChildProcessManager.h>

Inheritance diagram for juce::ChildProcessManager:
Collaboration diagram for juce::ChildProcessManager:

Public Member Functions

auto addChildProcessExitedListener (std::function< void(ChildProcess *)> listener)
 Registers a callback function that is called for every ChildProcess that terminated.
 
template<typename... Args>
std::shared_ptr< ChildProcesscreateAndStartManagedChildProcess (Args &&... args)
 Creates a new ChildProcess and starts it with the provided arguments.
 
auto hasRunningProcess () const
 Returns true if the ChildProcessManager contains any running ChildProcesses that it's monitoring.
 

Private Member Functions

 ChildProcessManager ()=default
 
 ~ChildProcessManager () override
 
void checkProcesses ()
 

Static Private Member Functions

static void deleteAll ()
 Deletes all extant objects.
 

Private Attributes

detail::CallbackListenerList< ChildProcess * > listeners
 
std::set< std::shared_ptr< ChildProcess > > processes
 
TimedCallback timer { [this] { checkProcesses(); } }
 

Detailed Description

Manages a set of ChildProcesses and periodically checks their return value.

Upon completion it calls listeners added with addChildProcessExitedListener().

This class is mostly aimed for usage on Linux, where terminated child processes are only cleaned up if their return code is read after termination. In order to ensure this one needs to call ChildProcess::isFinished() until it returns false or ChildProcess::waitForProcessToFinish() until it returns true.

This class will keep querying the return code on a Timer thread until the process terminates. This can be handy if one wants to start and stop multiple ChildProcesses on Linux that could take a long time to complete.

Since this class uses a Timer to check subprocess status, it's generally only safe to access the returned ChildProcesses from the message thread.

See also
ChildProcessManagerSingleton

@tags{Events}

Constructor & Destructor Documentation

◆ ChildProcessManager()

juce::ChildProcessManager::ChildProcessManager ( )
privatedefault

◆ ~ChildProcessManager()

juce::ChildProcessManager::~ChildProcessManager ( )
inlineoverrideprivate

Member Function Documentation

◆ addChildProcessExitedListener()

auto juce::ChildProcessManager::addChildProcessExitedListener ( std::function< void(ChildProcess *)>  listener)
inline

Registers a callback function that is called for every ChildProcess that terminated.

This registration is deleted when the returned ErasedScopedGuard is deleted.

◆ checkProcesses()

void juce::ChildProcessManager::checkProcesses ( )
private

◆ createAndStartManagedChildProcess()

template<typename... Args>
std::shared_ptr< ChildProcess > juce::ChildProcessManager::createAndStartManagedChildProcess ( Args &&...  args)
inline

Creates a new ChildProcess and starts it with the provided arguments.

The arguments are the same as the overloads to ChildProcess::start().

The manager will keep the returned ChildProcess object alive until it terminates and its return value has been queried. Calling ChildProcess::kill() on the returned object will eventually cause its removal from the ChildProcessManager after it terminates.

◆ deleteAll()

static void juce::DeletedAtShutdown::deleteAll ( )
staticinherited

Deletes all extant objects.

This shouldn't be used by applications, as it's called automatically in the shutdown code of the JUCEApplicationBase class.

◆ hasRunningProcess()

auto juce::ChildProcessManager::hasRunningProcess ( ) const
inline

Returns true if the ChildProcessManager contains any running ChildProcesses that it's monitoring.

Member Data Documentation

◆ listeners

detail::CallbackListenerList<ChildProcess*> juce::ChildProcessManager::listeners
private

◆ processes

std::set<std::shared_ptr<ChildProcess> > juce::ChildProcessManager::processes
private

◆ timer

TimedCallback juce::ChildProcessManager::timer { [this] { checkProcesses(); } }
private

The documentation for this class was generated from the following file: