Rework and document OS class
This commit is contained in:
@@ -38,45 +38,90 @@ public abstract class OS {
|
||||
|
||||
private static OS instance = null;
|
||||
|
||||
/**
|
||||
* Operating system name
|
||||
* @return a string representing the OS name.
|
||||
*/
|
||||
public abstract String name();
|
||||
|
||||
/**
|
||||
* Blender requires 64 bits
|
||||
* @return boolean if we are supported i.e. if we run on 64 bits
|
||||
*/
|
||||
public boolean isSupported() { return "64bit".equals(getCPU().getArch()); }
|
||||
|
||||
/** Get the full version of the os.
|
||||
/** Get the full version of the operating system.
|
||||
* For example windows, should give "windows 8.1"
|
||||
* @return a lowercassed string with the os name and the version info
|
||||
* @see OperatingSystem#getVersionInfo()
|
||||
*/
|
||||
public String getVersion() {
|
||||
return (name() + " " + operatingSystem.getVersionInfo()).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see oshi.hardware.GlobalMemory#getTotal()
|
||||
* @return long of getTotal() in kilobytes
|
||||
*/
|
||||
public long getTotalMemory() {
|
||||
return hardwareAbstractionLayer.getMemory().getTotal() / 1024;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see oshi.hardware.GlobalMemory#getAvailable()
|
||||
* @return long of getAvailable() in kilobytes
|
||||
*/
|
||||
public long getFreeMemory() {
|
||||
return hardwareAbstractionLayer.getMemory().getAvailable() / 1024;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the Blender executable
|
||||
* @return a string representing a path to Blender,
|
||||
* relative or absolute depends on the implementation
|
||||
*/
|
||||
public abstract String getRenderBinaryPath();
|
||||
|
||||
/**
|
||||
* Get the path to the CUDA library
|
||||
* @return a string representing a path the CUDA library,
|
||||
* relative or absolute depends on the implementation
|
||||
*/
|
||||
public String getCUDALib() {
|
||||
return null;
|
||||
}
|
||||
|
||||
//path to NVIDIA NVML lib
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public String getNVMLLib() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean getSupportHighPriority();
|
||||
|
||||
public abstract boolean checkNiceAvailability();
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Shutdown the computer waiting delayInMinutes minutes to allow all SheepIt threads to close and exit the app
|
||||
* Determines if the platform supports being IO nice
|
||||
* @return a boolean representing if the platform supports being IO nice
|
||||
*/
|
||||
public abstract boolean isNiceAvailable();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public abstract void shutdownComputer(int delayInMinutes);
|
||||
|
||||
/**
|
||||
* Creates and populates a CPU object
|
||||
* @return a populated CPU object
|
||||
*/
|
||||
public CPU getCPU() {
|
||||
CentralProcessor.ProcessorIdentifier cpuID = hardwareAbstractionLayer.getProcessor().getProcessorIdentifier();
|
||||
CPU ret = new CPU();
|
||||
@@ -86,15 +131,20 @@ public abstract class OS {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
||||
ProcessBuilder builder = new ProcessBuilder(command);
|
||||
builder.redirectErrorStream(true);
|
||||
if (env != null) {
|
||||
builder.environment().putAll(env);
|
||||
}
|
||||
return builder.start();
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Terminates a process
|
||||
* @param proc Process to kill
|
||||
* @return true if proc wasn't null and was destroyed
|
||||
*/
|
||||
public boolean kill(Process proc) {
|
||||
if (proc != null) {
|
||||
proc.destroy();
|
||||
@@ -103,6 +153,10 @@ public abstract class OS {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the operating system currently in use
|
||||
* @return object instance of OS specific to the used operating system.
|
||||
*/
|
||||
public static OS getOS() {
|
||||
if (instance == null) {
|
||||
switch (operatingSystem.getManufacturer()){
|
||||
@@ -110,7 +164,7 @@ public abstract class OS {
|
||||
instance = new Windows();
|
||||
break;
|
||||
case "Apple":
|
||||
if ("aarch64".equalsIgnoreCase(System.getProperty("os.arch"))) { // ARM arch ?
|
||||
if ("aarch64".equalsIgnoreCase(System.getProperty("os.arch"))) { // Set as M1 Mac if we are on ARM64
|
||||
instance = new MacM1();
|
||||
}
|
||||
else {
|
||||
@@ -124,7 +178,13 @@ public abstract class OS {
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public String getDefaultConfigFilePath() {
|
||||
String xdgConfigHome = System.getenv("XDG_CONFIG_HOME");
|
||||
String userHome = System.getProperty("user.home");
|
||||
|
||||
Reference in New Issue
Block a user