ChildProcessMaster Class Referenceabstract
juce_events » interprocess

Acts as the master in a master/slave pair of connected processes. More...

## Public Member Functions

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

## Detailed Description

Acts as the master in a master/slave pair of connected processes.

The ChildProcessSlave and ChildProcessMaster 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 ChildProcessSlave and ChildProcessMaster. When you want your master process to launch the slave, you just call launchSlaveProcess(), 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 ChildProcessSlave) then a two-way connection will be created.

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

See also
  ChildProcessSlave, InterprocessConnection, ChildProcess

## Constructor & Destructor Documentation

## ChildProcessMaster()

ChildProcessMaster::ChildProcessMaster | ( |  | ) |

Creates an uninitialised master process object.

Use launchSlaveProcess to launch and connect to a child process.

## ~ChildProcessMaster()

virtual ChildProcessMaster::~ChildProcessMaster | ( |  | ) |

virtual

Destructor.

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

## Member Function Documentation

## launchSlaveProcess()

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

Attempts to launch and connect to a slave 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 ChildProcessSlave::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 slave process.

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

## killSlaveProcess()

void ChildProcessMaster::killSlaveProcess | ( |  | ) |

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

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

## handleMessageFromSlave()

virtual void ChildProcessMaster::handleMessageFromSlave | ( | const MemoryBlock & |  | ) |

pure virtual

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

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

## handleConnectionLost()

virtual void ChildProcessMaster::handleConnectionLost | ( |  | ) |

virtual

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

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

## sendMessageToSlave()

bool ChildProcessMaster::sendMessageToSlave | ( | const MemoryBlock & |  | ) |

Attempts to send a message to the slave 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 ChildProcessSlave::handleMessageFromMaster().

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

- juce_ConnectedChildProcess.h