2014-11-20 13:21:19 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2010-2014 Laurent CLOUET
|
|
|
|
|
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
|
|
|
|
|
*
|
2020-05-28 13:28:42 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
2014-11-20 13:21:19 +00: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.os;
|
|
|
|
|
|
2021-12-29 17:08:51 +00:00
|
|
|
import java.io.File;
|
2014-11-20 13:21:19 +00:00
|
|
|
import java.io.IOException;
|
2015-01-25 19:07:32 +00:00
|
|
|
import java.util.List;
|
2015-01-16 17:51:50 +01:00
|
|
|
import java.util.Map;
|
2014-11-20 13:21:19 +00:00
|
|
|
|
2021-09-10 00:23:57 +00:00
|
|
|
import oshi.SystemInfo;
|
|
|
|
|
import oshi.hardware.CentralProcessor;
|
|
|
|
|
import oshi.software.os.OperatingSystem;
|
|
|
|
|
import oshi.hardware.HardwareAbstractionLayer;
|
2014-11-20 13:21:19 +00:00
|
|
|
import com.sheepit.client.hardware.cpu.CPU;
|
|
|
|
|
|
|
|
|
|
public abstract class OS {
|
2021-09-10 00:23:57 +00:00
|
|
|
private static SystemInfo systemInfo = new SystemInfo();
|
|
|
|
|
|
2021-11-16 14:51:53 +00:00
|
|
|
public static OperatingSystem operatingSystem = systemInfo.getOperatingSystem();
|
2021-09-10 00:23:57 +00:00
|
|
|
|
|
|
|
|
private static HardwareAbstractionLayer hardwareAbstractionLayer = systemInfo.getHardware();
|
|
|
|
|
|
2017-05-21 15:21:52 +02:00
|
|
|
private static OS instance = null;
|
|
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* Operating system name
|
|
|
|
|
* @return a string representing the OS name.
|
|
|
|
|
*/
|
2015-06-11 22:19:52 +01:00
|
|
|
public abstract String name();
|
2014-11-20 13:21:19 +00:00
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* Blender requires 64 bits
|
|
|
|
|
* @return boolean if we are supported i.e. if we run on 64 bits
|
|
|
|
|
*/
|
2023-10-16 18:05:29 +00:00
|
|
|
public boolean isSupported() { return "64bit".equals(getCPU().getArch()); }
|
2021-09-10 00:23:57 +00:00
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/** Get the full version of the operating system.
|
2021-06-24 10:36:25 +02:00
|
|
|
* For example windows, should give "windows 8.1"
|
2023-11-12 13:57:18 +00:00
|
|
|
* @return a lowercassed string with the os name and the version info
|
|
|
|
|
* @see OperatingSystem#getVersionInfo()
|
2021-06-24 10:36:25 +02:00
|
|
|
*/
|
|
|
|
|
public String getVersion() {
|
2021-09-10 00:23:57 +00:00
|
|
|
return (name() + " " + operatingSystem.getVersionInfo()).toLowerCase();
|
2021-06-24 10:36:25 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* @see oshi.hardware.GlobalMemory#getTotal()
|
|
|
|
|
* @return long of getTotal() in kilobytes
|
|
|
|
|
*/
|
2021-11-16 14:51:53 +00:00
|
|
|
public long getTotalMemory() {
|
2021-09-10 00:23:57 +00:00
|
|
|
return hardwareAbstractionLayer.getMemory().getTotal() / 1024;
|
|
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* @see oshi.hardware.GlobalMemory#getAvailable()
|
|
|
|
|
* @return long of getAvailable() in kilobytes
|
|
|
|
|
*/
|
2021-09-10 00:23:57 +00:00
|
|
|
public long getFreeMemory() {
|
|
|
|
|
return hardwareAbstractionLayer.getMemory().getAvailable() / 1024;
|
|
|
|
|
}
|
2018-08-10 17:33:50 +02:00
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* Get the path to the Blender executable
|
|
|
|
|
* @return a string representing a path to Blender,
|
|
|
|
|
* relative or absolute depends on the implementation
|
|
|
|
|
*/
|
2014-11-30 23:42:57 +00:00
|
|
|
public abstract String getRenderBinaryPath();
|
2015-01-20 22:06:05 +01:00
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* Get the path to the CUDA library
|
|
|
|
|
* @return a string representing a path the CUDA library,
|
|
|
|
|
* relative or absolute depends on the implementation
|
|
|
|
|
*/
|
2014-11-20 13:21:19 +00:00
|
|
|
public String getCUDALib() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* Get the path to the NVIDIA NVML library
|
|
|
|
|
* @return a string representing a path the NVIDIA NVML library,
|
|
|
|
|
* relative or absolute depends on the implementation
|
|
|
|
|
*/
|
2023-01-06 14:19:34 +00:00
|
|
|
public String getNVMLLib() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* Determines if the platform supports setting a higher priority
|
|
|
|
|
* @return a boolean representing if the platform supports setting a higher priority
|
|
|
|
|
*/
|
|
|
|
|
public abstract boolean isHighPrioritySupported();
|
2020-05-28 23:05:52 +10:00
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* Determines if the platform supports being IO nice
|
|
|
|
|
* @return a boolean representing if the platform supports being IO nice
|
|
|
|
|
*/
|
|
|
|
|
public abstract boolean isNiceAvailable();
|
2017-03-19 18:14:33 +01:00
|
|
|
|
2021-09-10 11:49:22 +02:00
|
|
|
/**
|
2023-11-12 13:57:18 +00:00
|
|
|
* Shuts the computer down waiting allow all SheepIt threads to close and exit
|
|
|
|
|
* @param delayInMinutes integer repressing the amount minutes to wait before shutting down
|
2021-09-10 11:49:22 +02:00
|
|
|
*/
|
2020-07-28 00:49:36 +10:00
|
|
|
public abstract void shutdownComputer(int delayInMinutes);
|
|
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* Creates and populates a CPU object
|
|
|
|
|
* @return a populated CPU object
|
|
|
|
|
*/
|
2021-09-10 00:23:57 +00:00
|
|
|
public CPU getCPU() {
|
|
|
|
|
CentralProcessor.ProcessorIdentifier cpuID = hardwareAbstractionLayer.getProcessor().getProcessorIdentifier();
|
|
|
|
|
CPU ret = new CPU();
|
|
|
|
|
ret.setName(cpuID.getName());
|
|
|
|
|
ret.setModel(cpuID.getModel());
|
|
|
|
|
ret.setFamily(cpuID.getFamily());
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* Executes a Process
|
|
|
|
|
* @param command List of strings of the command and the respective command line arguments
|
|
|
|
|
* @param env Map of strings of environment variables and their values for the execution
|
|
|
|
|
* @return a Process object reflecting the execution of the command
|
|
|
|
|
* @throws IOException if an I/O error occurs
|
|
|
|
|
*/
|
|
|
|
|
public abstract Process exec(List<String> command, Map<String, String> env) throws IOException;
|
2014-11-20 13:21:19 +00:00
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* Terminates a process
|
|
|
|
|
* @param proc Process to kill
|
|
|
|
|
* @return true if proc wasn't null and was destroyed
|
|
|
|
|
*/
|
2024-04-19 18:40:55 +00:00
|
|
|
public boolean kill(Process proc) throws InterruptedException {
|
2014-11-20 13:21:19 +00:00
|
|
|
if (proc != null) {
|
|
|
|
|
proc.destroy();
|
2024-04-19 18:40:55 +00:00
|
|
|
|
|
|
|
|
for (int i = 0; i <= 30; i++) {
|
|
|
|
|
if (proc.isAlive() == false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-06-03 14:02:30 +00:00
|
|
|
Thread.sleep(100);
|
2024-04-19 18:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
proc.destroyForcibly();
|
2014-11-20 13:21:19 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-12 13:57:18 +00:00
|
|
|
/**
|
|
|
|
|
* Get the operating system currently in use
|
|
|
|
|
* @return object instance of OS specific to the used operating system.
|
|
|
|
|
*/
|
2014-11-20 13:21:19 +00:00
|
|
|
public static OS getOS() {
|
2017-05-21 15:21:52 +02:00
|
|
|
if (instance == null) {
|
2021-09-10 00:23:57 +00:00
|
|
|
switch (operatingSystem.getManufacturer()){
|
|
|
|
|
case "Microsoft":
|
|
|
|
|
instance = new Windows();
|
|
|
|
|
break;
|
|
|
|
|
case "Apple":
|
2023-11-12 13:57:18 +00:00
|
|
|
if ("aarch64".equalsIgnoreCase(System.getProperty("os.arch"))) { // Set as M1 Mac if we are on ARM64
|
2021-12-31 15:22:37 +00:00
|
|
|
instance = new MacM1();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
instance = new Mac();
|
|
|
|
|
}
|
2021-09-10 00:23:57 +00:00
|
|
|
break;
|
|
|
|
|
case "GNU/Linux":
|
|
|
|
|
instance = new Linux();
|
|
|
|
|
break;
|
2017-05-21 15:21:52 +02:00
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
2017-05-21 15:21:52 +02:00
|
|
|
return instance;
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
2023-11-12 13:57:18 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the default path that SheepIt would place the config file
|
|
|
|
|
* This respects the XDG specification for Linux and macOS
|
|
|
|
|
* @see <a href="https://www.freedesktop.org/wiki/Software/xdg-user-dirs/">XDG specification</a>
|
|
|
|
|
* @return string representing the default path to the sheepit.conf
|
|
|
|
|
*/
|
2021-12-29 17:08:51 +00:00
|
|
|
public String getDefaultConfigFilePath() {
|
|
|
|
|
String xdgConfigHome = System.getenv("XDG_CONFIG_HOME");
|
|
|
|
|
String userHome = System.getProperty("user.home");
|
|
|
|
|
// fallback xdg config home should be ~/.config/
|
|
|
|
|
if (xdgConfigHome == null || xdgConfigHome.isEmpty()) {
|
|
|
|
|
xdgConfigHome = userHome + File.separator + ".config";
|
|
|
|
|
}
|
|
|
|
|
// add the config folder to the path
|
|
|
|
|
xdgConfigHome += File.separator + "sheepit";
|
|
|
|
|
|
|
|
|
|
// check if file already exists in ~/.config/sheepit/sheepit.conf
|
|
|
|
|
File file = new File(xdgConfigHome + File.separator + "sheepit.conf");
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
return file.getAbsolutePath();
|
|
|
|
|
}
|
|
|
|
|
// if it doesn't exist, try $HOME/.sheepit.conf
|
|
|
|
|
file = new File(userHome + File.separator + ".sheepit.conf");
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
return file.getAbsolutePath();
|
|
|
|
|
}
|
|
|
|
|
// if it doesn't exist, create the file in the XDG compliant location
|
|
|
|
|
file = new File(xdgConfigHome);
|
|
|
|
|
file.mkdirs();
|
|
|
|
|
return file.getAbsolutePath() + File.separator + "sheepit.conf";
|
|
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|