- Changed Native.get() to cache integration instances.
- Extracted DefaultSystemInfo out of a couple of separate places.
This commit is contained in:
@@ -4,11 +4,12 @@ import net.rubygrapefruit.platform.Terminal;
|
||||
import net.rubygrapefruit.platform.Terminals;
|
||||
|
||||
public abstract class AbstractTerminals implements Terminals {
|
||||
private static Output currentlyOpen;
|
||||
private static AbstractTerminal current;
|
||||
private final Object lock = new Object();
|
||||
private Output currentlyOpen;
|
||||
private AbstractTerminal current;
|
||||
|
||||
public Terminal getTerminal(Output output) {
|
||||
synchronized (AbstractTerminals.class) {
|
||||
synchronized (lock) {
|
||||
if (currentlyOpen != null && currentlyOpen != output) {
|
||||
throw new UnsupportedOperationException("Currently only one output can be used as a terminal.");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.rubygrapefruit.platform.internal;
|
||||
|
||||
import net.rubygrapefruit.platform.NativeException;
|
||||
import net.rubygrapefruit.platform.PosixFile;
|
||||
import net.rubygrapefruit.platform.internal.jni.NativeLibraryFunctions;
|
||||
import net.rubygrapefruit.platform.internal.jni.PosixFileFunctions;
|
||||
|
||||
import java.io.File;
|
||||
@@ -12,14 +11,8 @@ public class DefaultPosixFile implements PosixFile {
|
||||
private final String characterEncoding;
|
||||
|
||||
public DefaultPosixFile() {
|
||||
MutableSystemInfo systemInfo = new MutableSystemInfo();
|
||||
FunctionResult result = new FunctionResult();
|
||||
NativeLibraryFunctions.getSystemInfo(systemInfo, result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not fetch system information: %s",
|
||||
result.getMessage()));
|
||||
}
|
||||
this.characterEncoding = systemInfo.characterEncoding;
|
||||
DefaultSystemInfo systemInfo = new DefaultSystemInfo();
|
||||
this.characterEncoding = systemInfo.getCharacterEncoding();
|
||||
}
|
||||
|
||||
public void setMode(File file, int perms) {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package net.rubygrapefruit.platform.internal;
|
||||
|
||||
import net.rubygrapefruit.platform.NativeException;
|
||||
import net.rubygrapefruit.platform.SystemInfo;
|
||||
import net.rubygrapefruit.platform.internal.jni.NativeLibraryFunctions;
|
||||
|
||||
public class DefaultSystemInfo implements SystemInfo {
|
||||
MutableSystemInfo systemInfo = new MutableSystemInfo();
|
||||
|
||||
public DefaultSystemInfo() {
|
||||
FunctionResult result = new FunctionResult();
|
||||
NativeLibraryFunctions.getSystemInfo(systemInfo, result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not fetch system information: %s",
|
||||
result.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKernelName() {
|
||||
return systemInfo.getKernelName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKernelVersion() {
|
||||
return systemInfo.getKernelVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMachineArchitecture() {
|
||||
return systemInfo.getMachineArchitecture();
|
||||
}
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return systemInfo.characterEncoding;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package net.rubygrapefruit.platform.internal;
|
||||
|
||||
import net.rubygrapefruit.platform.*;
|
||||
import net.rubygrapefruit.platform.Process;
|
||||
import net.rubygrapefruit.platform.internal.jni.NativeLibraryFunctions;
|
||||
|
||||
public abstract class Platform {
|
||||
private static Platform platform;
|
||||
@@ -75,14 +74,7 @@ public abstract class Platform {
|
||||
return type.cast(new TerminfoTerminals());
|
||||
}
|
||||
if (type.equals(SystemInfo.class)) {
|
||||
MutableSystemInfo systemInfo = new MutableSystemInfo();
|
||||
FunctionResult result = new FunctionResult();
|
||||
NativeLibraryFunctions.getSystemInfo(systemInfo, result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not fetch system information: %s",
|
||||
result.getMessage()));
|
||||
}
|
||||
return type.cast(systemInfo);
|
||||
return type.cast(new DefaultSystemInfo());
|
||||
}
|
||||
return super.get(type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user