Loading...
Searching...
No Matches
Public Member Functions | List of all members
ChildProcessCoordinator Class Reference

Acts as the coordinator in a coordinator/worker pair of connected processes. More...

#include <juce_ConnectedChildProcess.h>

Public Member Functions

 ChildProcessCoordinator ()
 Creates an uninitialised coordinator process object.
 
virtual ~ChildProcessCoordinator ()
 Destructor.
 
bool launchWorkerProcess (const File &executableToLaunch, const String &commandLineUniqueID, int timeoutMs=0, int streamFlags=ChildProcess::wantStdOut|ChildProcess::wantStdErr)
 Attempts to launch and connect to a worker process.
 
bool launchSlaveProcess (const File &executableToLaunch, const String &commandLineUniqueID, int timeoutMs=0, int streamFlags=ChildProcess::wantStdOut|ChildProcess::wantStdErr)
 
void killWorkerProcess ()
 Sends a kill message to the worker, and disconnects from it.
 
void killSlaveProcess ()
 
virtual void handleMessageFromWorker (const MemoryBlock &)
 This will be called to deliver a message from the worker process.
 
virtual void handleMessageFromSlave (const MemoryBlock &)
 
virtual void handleConnectionLost ()
 This will be called when the worker process dies or is somehow disconnected.
 
bool sendMessageToWorker (const MemoryBlock &)
 Attempts to send a message to the worker process.
 
bool sendMessageToSlave (const MemoryBlock &mb)
 

Detailed Description

Acts as the coordinator in a coordinator/worker pair of connected processes.

The ChildProcessWorker and ChildProcessCoordinator classes make it easy for an app to spawn a child process, and to manage a 2-way messaging connection to control it.

To use the system, you need to create subclasses of both ChildProcessWorker and ChildProcessCoordinator. When you want your coordinator process to launch the worker, you just call launchWorkerProcess(), and it'll attempt to launch the executable that you specify (which may be the same exe), and assuming it has been set-up to correctly parse the command-line parameters (see ChildProcessWorker) then a two-way connection will be created.

The juce demo app has a good example of this class in action.

See also
ChildProcessWorker, InterprocessConnection, ChildProcess

Constructor & Destructor Documentation

◆ ChildProcessCoordinator()

ChildProcessCoordinator::ChildProcessCoordinator ( )

Creates an uninitialised coordinator process object.

Use launchWorkerProcess to launch and connect to a child process.

◆ ~ChildProcessCoordinator()

virtual ChildProcessCoordinator::~ChildProcessCoordinator ( )
virtual

Destructor.

Note that the destructor calls killWorkerProcess(), but doesn't wait for the child process to finish terminating.

Member Function Documentation

◆ launchWorkerProcess()

bool ChildProcessCoordinator::launchWorkerProcess ( const File & executableToLaunch,
const String & commandLineUniqueID,
int timeoutMs = 0,
int streamFlags = ChildProcess::wantStdOut|ChildProcess::wantStdErr )

Attempts to launch and connect to a worker process.

This will start the given executable, passing it a special command-line parameter based around the commandLineUniqueID string, which must be a short alphanumeric string (no spaces!) that identifies your app. The exe that gets launched must respond by calling ChildProcessWorker::initialiseFromCommandLine() in its startup code, and must use a matching ID to commandLineUniqueID.

The timeoutMs parameter lets you specify how long the child process is allowed to go without sending a ping before it is considered to have died and handleConnectionLost() will be called. Passing <= 0 for this timeout makes it use a default value.

If this all works, the method returns true, and you can begin sending and receiving messages with the worker process.

If a child process is already running, this will call killWorkerProcess() and start a new one.

◆ launchSlaveProcess()

bool ChildProcessCoordinator::launchSlaveProcess ( const File & executableToLaunch,
const String & commandLineUniqueID,
int timeoutMs = 0,
int streamFlags = ChildProcess::wantStdOut | ChildProcess::wantStdErr )

◆ killWorkerProcess()

void ChildProcessCoordinator::killWorkerProcess ( )

Sends a kill message to the worker, and disconnects from it.

Note that this won't wait for it to terminate.

◆ killSlaveProcess()

void ChildProcessCoordinator::killSlaveProcess ( )

◆ handleMessageFromWorker()

virtual void ChildProcessCoordinator::handleMessageFromWorker ( const MemoryBlock & )
virtual

This will be called to deliver a message from the worker process.

The call will probably be made on a background thread, so be careful with your thread-safety!

◆ handleMessageFromSlave()

virtual void ChildProcessCoordinator::handleMessageFromSlave ( const MemoryBlock & )
virtual

◆ handleConnectionLost()

virtual void ChildProcessCoordinator::handleConnectionLost ( )
virtual

This will be called when the worker process dies or is somehow disconnected.

The call will probably be made on a background thread, so be careful with your thread-safety!

◆ sendMessageToWorker()

bool ChildProcessCoordinator::sendMessageToWorker ( const MemoryBlock & )

Attempts to send a message to the worker process.

This returns true if the message was dispatched, but doesn't check that it actually gets delivered at the other end. If successful, the data will emerge in a call to your ChildProcessWorker::handleMessageFromCoordinator().

◆ sendMessageToSlave()

bool ChildProcessCoordinator::sendMessageToSlave ( const MemoryBlock & mb)

The documentation for this class was generated from the following file:
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram