bool ChildProcessMaster::launchSlaveProcess (const File& executable, const String& commandLineUniqueID, int timeoutMs) { connection = nullptr; jassert (childProcess.kill()); const String pipeName ("p" + String::toHexString (Random().nextInt64())); StringArray args; args.add (executable.getFullPathName()); args.add (getCommandLinePrefix (commandLineUniqueID) + pipeName); if (childProcess.start (args)) { connection = new Connection (*this, pipeName, timeoutMs <= 0 ? defaultTimeoutMs : timeoutMs); if (connection->isConnected()) { sendMessageToSlave (MemoryBlock (startMessage, specialMessageSize)); return true; } connection = nullptr; } return false; }
bool ChildProcessMaster::launchSlaveProcess (const File& executable, const String& commandLineUniqueID, int timeoutMs, int streamFlags) { killSlaveProcess(); auto pipeName = "p" + String::toHexString (Random().nextInt64()); StringArray args; args.add (executable.getFullPathName()); args.add (getCommandLinePrefix (commandLineUniqueID) + pipeName); childProcess.reset (new ChildProcess()); if (childProcess->start (args, streamFlags)) { connection.reset (new Connection (*this, pipeName, timeoutMs <= 0 ? defaultTimeoutMs : timeoutMs)); if (connection->isConnected()) { sendMessageToSlave ({ startMessage, specialMessageSize }); return true; } connection.reset(); } return false; }
ChildProcessMaster::~ChildProcessMaster() { if (connection != nullptr) { sendMessageToSlave (MemoryBlock (killMessage, specialMessageSize)); connection->disconnect(); connection = nullptr; } }
void sendPingMessageToSlave() { ValueTree message ("MESSAGE"); message.setProperty ("count", count++, nullptr); demo.logMessage ("Sending: " + valueTreeToString (message)); sendMessageToSlave (valueTreeToMemoryBlock (message)); }
void ChildProcessMaster::killSlaveProcess() { if (connection != nullptr) { sendMessageToSlave ({ killMessage, specialMessageSize }); connection->disconnect(); connection.reset(); } childProcess.reset(); }