Add commands to text user interface
This commit is contained in:
committed by
Laurent Clouet
parent
c91bfc38fd
commit
7d2209a0f4
@@ -92,6 +92,15 @@ public class Job {
|
||||
render = new RenderProcess();
|
||||
}
|
||||
|
||||
public void block() {
|
||||
setAskForRendererKill(true);
|
||||
setUserBlockJob(true);
|
||||
RenderProcess process = getProcessRender();
|
||||
if (process != null) {
|
||||
OS.getOS().kill(process.getProcess());
|
||||
}
|
||||
}
|
||||
|
||||
public RenderProcess getProcessRender() {
|
||||
return render;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,11 @@ package com.sheepit.client.standalone;
|
||||
|
||||
import com.sheepit.client.Client;
|
||||
import com.sheepit.client.Gui;
|
||||
import com.sheepit.client.Job;
|
||||
import com.sheepit.client.Log;
|
||||
import com.sheepit.client.Stats;
|
||||
import com.sheepit.client.standalone.text.CLIInputActionHandler;
|
||||
import com.sheepit.client.standalone.text.CLIInputObserver;
|
||||
|
||||
import sun.misc.Signal;
|
||||
import sun.misc.SignalHandler;
|
||||
@@ -47,6 +50,11 @@ public class GuiText implements Gui {
|
||||
public void start() {
|
||||
if (client != null) {
|
||||
|
||||
CLIInputObserver cli_input_observer = new CLIInputObserver(client);
|
||||
cli_input_observer.addListener(new CLIInputActionHandler());
|
||||
Thread cli_input_observer_thread = new Thread(cli_input_observer);
|
||||
cli_input_observer_thread.start();
|
||||
|
||||
Signal.handle(new Signal("INT"), new SignalHandler() {
|
||||
@Override
|
||||
public void handle(Signal signal) {
|
||||
|
||||
@@ -21,7 +21,10 @@ package com.sheepit.client.standalone;
|
||||
|
||||
import com.sheepit.client.Client;
|
||||
import com.sheepit.client.Gui;
|
||||
import com.sheepit.client.Job;
|
||||
import com.sheepit.client.Stats;
|
||||
import com.sheepit.client.standalone.text.CLIInputActionHandler;
|
||||
import com.sheepit.client.standalone.text.CLIInputObserver;
|
||||
|
||||
import sun.misc.Signal;
|
||||
import sun.misc.SignalHandler;
|
||||
@@ -55,6 +58,11 @@ public class GuiTextOneLine implements Gui {
|
||||
public void start() {
|
||||
if (client != null) {
|
||||
|
||||
CLIInputObserver cli_input_observer = new CLIInputObserver(client);
|
||||
cli_input_observer.addListener(new CLIInputActionHandler());
|
||||
Thread cli_input_observer_thread = new Thread(cli_input_observer);
|
||||
cli_input_observer_thread.start();
|
||||
|
||||
Signal.handle(new Signal("INT"), new SignalHandler() {
|
||||
@Override
|
||||
public void handle(Signal signal) {
|
||||
|
||||
@@ -394,12 +394,7 @@ public class Working implements Activity {
|
||||
if (client != null) {
|
||||
Job job = client.getRenderingJob();
|
||||
if (job != null) {
|
||||
job.setAskForRendererKill(true);
|
||||
job.setUserBlockJob(true);
|
||||
RenderProcess process = job.getProcessRender();
|
||||
if (process != null) {
|
||||
OS.getOS().kill(process.getProcess());
|
||||
}
|
||||
job.block();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Laurent CLOUET
|
||||
* Author Rolf Aretz Lap <rolf.aretz@ottogroup.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; version 2
|
||||
* of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package com.sheepit.client.standalone.text;
|
||||
|
||||
import com.sheepit.client.Client;
|
||||
import com.sheepit.client.Configuration;
|
||||
import com.sheepit.client.Job;
|
||||
|
||||
public class CLIInputActionHandler implements CLIInputListener {
|
||||
|
||||
@Override
|
||||
public void commandEntered(Client client, String command) {
|
||||
int priorityLength = "priority".length();
|
||||
|
||||
//prevent Null Pointer at next step
|
||||
if (command == null) {
|
||||
return;
|
||||
}
|
||||
if (client == null) {
|
||||
return;
|
||||
}
|
||||
if (command.equalsIgnoreCase("block")) {
|
||||
Job job = client.getRenderingJob();
|
||||
if (job != null) {
|
||||
job.block();
|
||||
}
|
||||
}
|
||||
else if (command.equalsIgnoreCase("resume")) {
|
||||
client.resume();
|
||||
}
|
||||
else if (command.equalsIgnoreCase("pause")) {
|
||||
client.suspend();
|
||||
}
|
||||
else if (command.equalsIgnoreCase("stop")) {
|
||||
client.askForStop();
|
||||
}
|
||||
else if (command.equalsIgnoreCase("status")) {
|
||||
displayStatus(client);
|
||||
}
|
||||
else if (command.equalsIgnoreCase("cancel")) {
|
||||
client.cancelStop();
|
||||
}
|
||||
else if (command.equalsIgnoreCase("quit")) {
|
||||
client.stop();
|
||||
System.exit(0);
|
||||
}
|
||||
else if ((command.length() > priorityLength) && (command.substring(0, priorityLength).equalsIgnoreCase("priority"))) {
|
||||
changePriority(client, command.substring(priorityLength));
|
||||
}
|
||||
else {
|
||||
System.out.println("Unknown command: " + command);
|
||||
System.out.println("status: display client status");
|
||||
System.out.println("priority <n>: set the priority for the next renderjob");
|
||||
System.out.println("block: block project");
|
||||
System.out.println("pause: pause client requesting new jobs");
|
||||
System.out.println("resume: resume after client was paused");
|
||||
System.out.println("stop: exit after frame was finished");
|
||||
System.out.println("cancel: cancel exit");
|
||||
System.out.println("quit: exit now");
|
||||
}
|
||||
}
|
||||
|
||||
void changePriority(Client client, String newPriority) {
|
||||
Configuration config = client.getConfiguration();
|
||||
if (config != null) {
|
||||
try {
|
||||
config.setUsePriority(Integer.parseInt(newPriority.trim()));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
System.out.println("Invalid priority: " + newPriority);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void displayStatus(Client client) {
|
||||
if (client.isSuspended()) {
|
||||
System.out.println("Status: paused");
|
||||
}
|
||||
else if (client.isRunning()) {
|
||||
System.out.println("Status: will exit after the current frame");
|
||||
}
|
||||
else {
|
||||
System.out.println("Status: running");
|
||||
}
|
||||
}
|
||||
}
|
||||
26
src/com/sheepit/client/standalone/text/CLIInputListener.java
Normal file
26
src/com/sheepit/client/standalone/text/CLIInputListener.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Laurent CLOUET
|
||||
* Author Rolf Aretz Lap <rolf.aretz@ottogroup.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; version 2
|
||||
* of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package com.sheepit.client.standalone.text;
|
||||
|
||||
import com.sheepit.client.Client;
|
||||
|
||||
public interface CLIInputListener {
|
||||
public void commandEntered(Client client, String command);
|
||||
}
|
||||
65
src/com/sheepit/client/standalone/text/CLIInputObserver.java
Normal file
65
src/com/sheepit/client/standalone/text/CLIInputObserver.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Laurent CLOUET
|
||||
* Author Rolf Aretz Lap <rolf.aretz@ottogroup.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; version 2
|
||||
* of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package com.sheepit.client.standalone.text;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sheepit.client.Client;
|
||||
|
||||
public class CLIInputObserver implements Runnable {
|
||||
private BufferedReader in;
|
||||
private Client client;
|
||||
|
||||
public CLIInputObserver(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
private List<CLIInputListener> listeners = new ArrayList<CLIInputListener>();
|
||||
|
||||
public void addListener(CLIInputListener toAdd) {
|
||||
listeners.add(toAdd);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
in = new BufferedReader(new InputStreamReader(System.in));
|
||||
String line = "";
|
||||
|
||||
while ((line != null) && (line.equalsIgnoreCase("quit") == false)) {
|
||||
try {
|
||||
line = in.readLine();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
for (CLIInputListener cliil : listeners)
|
||||
cliil.commandEntered(client, line);
|
||||
}
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user