//File: transmit.java //CS 471 - Operating Systems Project //Dennis Pereira, Ely Soto, John Cavalieri //The transmit command is an enhanced feature of our OS simulator //this command enables inter-process communication //transmit's functionality is similar to 'send' however, the messaging //is between processes rather than users public class transmit extends VMachine { public transmit() { } public void run() { try { //if there are two arguments //then try to 'transmit' the message if(args.length == 2) { //show error if not possible to 'transmit' if(!sysapi.writeProcessMsg(args[0],args[1])) { sysapi.Write(OUT,"Thread Not Found.\n"); } } //if there is only one arg, prompt the user for more input else if(args.length == 1) { String buffer = ""; String str = ""; str = sysapi.Read(IN); //while there is still input while(str.compareTo("") != 0) { //if a blank line, then finish if(buffer.compareTo("") == 0) { buffer = str; } //if more input, add to buffer else { buffer = buffer + "\n" + str; } //ask for more input str = sysapi.Read(IN); } //try to 'transmit' if(!sysapi.writeProcessMsg(args[0],buffer)) { sysapi.Write(OUT,"Thread Not Found.\n"); } } //if there is more than 2 args then loop through all of them passing from one to the other else if(args.length > 2) { String buffer = ""; //for each process; add message to buffer for(int i = 1; i < args.length; i++) { buffer = buffer + " " + args[i]; } buffer = buffer + "\n"; //try to 'transmit' if(!sysapi.writeProcessMsg(args[0],buffer)) { sysapi.Write(OUT,"Thread Not Found.\n"); } } //if no arguments are given then prompt the user for the parameters else if(args.length == 0) { String buffer = ""; String str = ""; //prompt user for input sysapi.Write(OUT,"Enter Process ID: "); String ThreadID = sysapi.Read(IN); str = sysapi.Read(IN); //loop until there is no more user input while(str.compareTo("") != 0) { if(buffer.compareTo("") == 0) //if blank line, then finish { buffer = str; } else //add message to buffer { buffer = buffer + "\n" + str; } //prompt for more input str = sysapi.Read(IN); } //try to 'transmit' if(!sysapi.writeProcessMsg(ThreadID,buffer)) { sysapi.Write(OUT,"Thread Not Found.\n"); } } } catch(Exception ex) { System.out.println(ex); } sysapi.Exit(vmh,owner); } }