Files
sheepit-shadow-nabber/src/main/java/com/sheepit/client/standalone/text/CLIInputActionHandler.java

104 lines
3.1 KiB
Java
Raw Normal View History

2017-02-19 14:19:48 +01:00
/*
* Copyright (C) 2017 Laurent CLOUET
* Author Rolf Aretz Lap <rolf.aretz@ottogroup.com>
*
* This program is free software; you can redistribute it and/or
2017-02-19 14:19:48 +01:00
* 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) {
2017-02-19 14:19:48 +01:00
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 {
2023-10-19 11:09:08 +00:00
config.setPriority(Integer.parseInt(newPriority.trim()));
2017-02-19 14:19:48 +01:00
}
catch (NumberFormatException e) {
System.out.println("Invalid priority: " + newPriority);
}
}
}
2017-02-19 14:19:48 +01:00
void displayStatus(Client client) {
if (client.isSuspended()) {
System.out.println("Status: paused");
}
else if (client.isRunning()) {
2017-03-06 14:58:09 +01:00
System.out.println("Status: running");
2017-02-19 14:19:48 +01:00
}
else {
2017-03-06 14:58:09 +01:00
System.out.println("Status: will exit after the current frame");
2017-02-19 14:19:48 +01:00
}
}
}