// We've closed mspdebug's stdin and are now waiting for process // exit. void ManagerExiting(ITC.Primitive source) { Message msg; if (rawOutput.IsClosed) { Output.Close(); return; } if (rawOutput.TryReceive(out msg)) { Output.Send(msg); } ITC.Pool.Continue(rawOutput, this.ManagerExiting); }
// Manager: ready state. mspdebug is sitting idle and waiting // for a command. void ManagerReady(ITC.Primitive source) { string cmd; if (Commands.IsClosed) { try { rawInput.Close(); } catch (Exception) { } ManagerExiting(null); return; } if (Commands.TryReceive(out cmd)) { try { rawInput.Write(":" + cmd + "\n"); } catch (Exception) { } ManagerSubmitting(null); return; } if (Cancel.Signalled) { Cancel.Clear(); CancelAccepted.Raise(); Ready.Raise(); } ITC.Pool.Continue(new ITC.Primitive[] { Cancel, Commands }, this.ManagerReady); }
// Manager: submitting state. We've just been given a command // and have sent it to mspdebug. Wait for mspdebug's // acknowledgement of receipt before doing anything further, // otherwise any cancellation requests we might want to send // could get lost without effect. void ManagerSubmitting(ITC.Primitive source) { Message msg; if (rawOutput.IsClosed) { Output.Close(); return; } if (rawOutput.TryReceive(out msg)) { Output.Send(msg); if ((msg.Type == MessageType.Shell) && (msg.Text.Equals("busy"))) { ManagerBusy(null); return; } } ITC.Pool.Continue(rawOutput, this.ManagerSubmitting); }
// Manager: busy state. A command, or startup is in progress. We // move to the ready state once the command is finished. void ManagerBusy(ITC.Primitive source) { Message msg; if (rawOutput.IsClosed) { Output.Close(); return; } if (Cancel.Signalled) { try { rawInput.Write("\\break\n"); } catch (Exception) { } Cancel.Clear(); CancelAccepted.Raise(); } if (rawOutput.TryReceive(out msg)) { Output.Send(msg); if ((msg.Type == MessageType.Shell) && (msg.Text.Equals("ready"))) { Ready.Raise(); ManagerReady(null); return; } } ITC.Pool.Continue(new ITC.Primitive[] { Cancel, rawOutput }, this.ManagerBusy); }
// Clean up when the process exits. void CleanProcess(ITC.Primitive prim) { rawOutput.Close(); proc.WaitForExit(); }