2016-10-04 06:33:25 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2015 Laurent CLOUET
|
|
|
|
|
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-11-20 17:50:23 +00:00
|
|
|
package com.sheepit.client.standalone;
|
|
|
|
|
|
2015-01-15 23:20:17 +01:00
|
|
|
import com.sheepit.client.Client;
|
2014-11-20 17:50:23 +00:00
|
|
|
import com.sheepit.client.Gui;
|
2017-02-19 14:19:48 +01:00
|
|
|
import com.sheepit.client.Job;
|
2016-10-12 00:34:51 +02:00
|
|
|
import com.sheepit.client.Stats;
|
2017-02-19 14:19:48 +01:00
|
|
|
import com.sheepit.client.standalone.text.CLIInputActionHandler;
|
|
|
|
|
import com.sheepit.client.standalone.text.CLIInputObserver;
|
2016-10-12 00:34:51 +02:00
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
import sun.misc.Signal;
|
|
|
|
|
import sun.misc.SignalHandler;
|
2014-11-20 17:50:23 +00:00
|
|
|
|
|
|
|
|
public class GuiTextOneLine implements Gui {
|
2015-04-08 20:32:24 +01:00
|
|
|
public static final String type = "oneLine";
|
|
|
|
|
|
2016-10-12 00:34:51 +02:00
|
|
|
private String project;
|
2014-11-20 17:50:23 +00:00
|
|
|
private int rendered;
|
|
|
|
|
private int remaining;
|
2016-07-29 23:59:11 +02:00
|
|
|
private String creditsEarned;
|
2016-01-27 13:41:11 +01:00
|
|
|
private int sigIntCount = 0;
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2017-05-07 21:00:20 +02:00
|
|
|
private String computeMethod;
|
2014-11-20 17:50:23 +00:00
|
|
|
private String status;
|
|
|
|
|
private String line;
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2020-04-20 01:01:43 +10:00
|
|
|
private int uploadQueueSize;
|
|
|
|
|
private long uploadQueueVolume;
|
|
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
private boolean exiting = false;
|
2014-11-20 17:50:23 +00:00
|
|
|
|
2015-01-27 21:44:32 +00:00
|
|
|
private Client client;
|
|
|
|
|
|
2014-11-20 17:50:23 +00:00
|
|
|
public GuiTextOneLine() {
|
2016-10-12 00:34:51 +02:00
|
|
|
project = "";
|
2014-11-20 17:50:23 +00:00
|
|
|
rendered = 0;
|
|
|
|
|
remaining = 0;
|
2016-07-29 23:59:11 +02:00
|
|
|
creditsEarned = null;
|
2014-11-20 17:50:23 +00:00
|
|
|
status = "";
|
2017-05-07 21:00:20 +02:00
|
|
|
computeMethod = "";
|
2014-11-20 17:50:23 +00:00
|
|
|
line = "";
|
2020-04-20 01:01:43 +10:00
|
|
|
uploadQueueSize = 0;
|
|
|
|
|
uploadQueueVolume = 0;
|
2014-11-20 17:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void start() {
|
2015-01-27 21:44:32 +00:00
|
|
|
if (client != null) {
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2017-02-19 14:19:48 +01:00
|
|
|
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();
|
|
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
Signal.handle(new Signal("INT"), new SignalHandler() {
|
|
|
|
|
@Override
|
|
|
|
|
public void handle(Signal signal) {
|
|
|
|
|
sigIntCount++;
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
if (sigIntCount == 5) {
|
|
|
|
|
Signal.raise(new Signal("INT"));
|
|
|
|
|
Runtime.getRuntime().halt(0);
|
|
|
|
|
}
|
|
|
|
|
else if (client.isRunning() && client.isSuspended() == false) {
|
|
|
|
|
client.askForStop();
|
|
|
|
|
exiting = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
client.stop();
|
2016-02-16 23:51:16 +01:00
|
|
|
GuiTextOneLine.this.stop();
|
2016-01-27 13:41:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2015-01-27 21:44:32 +00:00
|
|
|
client.run();
|
|
|
|
|
client.stop();
|
|
|
|
|
}
|
2014-11-20 17:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void stop() {
|
2016-01-27 13:41:11 +01:00
|
|
|
Runtime.getRuntime().halt(0);
|
2014-11-20 17:50:23 +00:00
|
|
|
}
|
2020-03-19 23:48:06 +01:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateTrayIcon(Integer percentage) {
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 17:50:23 +00:00
|
|
|
@Override
|
|
|
|
|
public void status(String msg_) {
|
2020-04-26 23:35:05 +10:00
|
|
|
status(msg_, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void status(String msg_, boolean overwriteSuspendedMsg) {
|
|
|
|
|
if (client != null && client.isSuspended()) {
|
|
|
|
|
if (overwriteSuspendedMsg) {
|
|
|
|
|
status = msg_;
|
|
|
|
|
updateLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
status = msg_;
|
|
|
|
|
updateLine();
|
|
|
|
|
}
|
2014-11-20 17:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
2016-10-12 00:34:51 +02:00
|
|
|
@Override
|
|
|
|
|
public void setRenderingProjectName(String name_) {
|
|
|
|
|
if (name_ == null || name_.isEmpty()) {
|
|
|
|
|
project = "";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
project = "Project \"" + name_ + "\" |";
|
|
|
|
|
}
|
|
|
|
|
updateLine();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 17:50:23 +00:00
|
|
|
@Override
|
|
|
|
|
public void error(String msg_) {
|
|
|
|
|
status = "Error " + msg_;
|
|
|
|
|
updateLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void AddFrameRendered() {
|
|
|
|
|
rendered += 1;
|
|
|
|
|
updateLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-10-12 00:34:51 +02:00
|
|
|
public void displayStats(Stats stats) {
|
|
|
|
|
remaining = stats.getRemainingFrame();
|
|
|
|
|
creditsEarned = String.valueOf(stats.getCreditsEarnedDuringSession());
|
|
|
|
|
updateLine();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 01:01:43 +10:00
|
|
|
@Override
|
|
|
|
|
public void displayUploadQueueStats(int queueSize, long queueVolume) {
|
|
|
|
|
this.uploadQueueSize = queueSize;
|
|
|
|
|
this.uploadQueueVolume = queueVolume;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-12 00:34:51 +02:00
|
|
|
@Override
|
|
|
|
|
public void setRemainingTime(String time_) {
|
2017-05-25 12:17:55 +02:00
|
|
|
status = "(remaining " + time_ + ")";
|
2016-10-12 00:34:51 +02:00
|
|
|
updateLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setRenderingTime(String time_) {
|
2016-12-06 06:33:31 +01:00
|
|
|
status = "Rendering " + time_;
|
2014-11-20 17:50:23 +00:00
|
|
|
updateLine();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-15 23:20:17 +01:00
|
|
|
@Override
|
|
|
|
|
public void setClient(Client cli) {
|
2015-01-27 21:44:32 +00:00
|
|
|
client = cli;
|
2015-01-15 23:20:17 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-07 21:00:20 +02:00
|
|
|
@Override
|
|
|
|
|
public void setComputeMethod(String computeMethod_) {
|
|
|
|
|
computeMethod = computeMethod_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-15 23:20:17 +01:00
|
|
|
@Override
|
|
|
|
|
public Client getClient() {
|
2015-01-27 21:44:32 +00:00
|
|
|
return client;
|
2015-01-15 23:20:17 +01:00
|
|
|
}
|
|
|
|
|
|
2019-08-22 21:35:26 +02:00
|
|
|
@Override
|
|
|
|
|
public void successfulAuthenticationEvent(String publickey) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 17:50:23 +00:00
|
|
|
private void updateLine() {
|
|
|
|
|
int charToRemove = line.length();
|
|
|
|
|
|
|
|
|
|
System.out.print("\r");
|
2020-04-20 01:01:43 +10:00
|
|
|
|
|
|
|
|
line = String.format("Frames: %d Points: %s | Queued uploads: %d%s | %s %s %s",
|
|
|
|
|
rendered,
|
|
|
|
|
creditsEarned != null ? creditsEarned : "unknown",
|
|
|
|
|
this.uploadQueueSize,
|
|
|
|
|
(this.uploadQueueSize > 0 ? String.format(" (%.2fMB)", (this.uploadQueueVolume / 1024.0 / 1024.0)) : ""),
|
|
|
|
|
project,
|
|
|
|
|
computeMethod,
|
|
|
|
|
status + (exiting ? " (Exiting after all frames are uploaded)" : "")
|
|
|
|
|
);
|
|
|
|
|
|
2014-11-20 17:50:23 +00:00
|
|
|
System.out.print(line);
|
|
|
|
|
for (int i = line.length(); i <= charToRemove; i++) {
|
|
|
|
|
System.out.print(" ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|