mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-13 09:18:05 -04:00
Extended file system API to allow specifying a speed multiplier for file systems.
For now, valid range is [1,6]. Floppies use 1, HDDs use 2-4, Raid is 6. Deprecated some internal FileSystem interface methods to allow simplifying the interface a bit when the time comes. Let's hope nobody is shipping the API \o/
This commit is contained in:
parent
fa36908170
commit
20239780e1
@ -16,7 +16,7 @@ import li.cil.oc.api.detail.NetworkAPI;
|
|||||||
*/
|
*/
|
||||||
public class API {
|
public class API {
|
||||||
public static final String ID_OWNER = "OpenComputers|Core";
|
public static final String ID_OWNER = "OpenComputers|Core";
|
||||||
public static final String VERSION = "5.1.1";
|
public static final String VERSION = "5.2.0";
|
||||||
|
|
||||||
public static DriverAPI driver = null;
|
public static DriverAPI driver = null;
|
||||||
public static FileSystemAPI fileSystem = null;
|
public static FileSystemAPI fileSystem = null;
|
||||||
|
@ -141,6 +141,63 @@ public final class FileSystem {
|
|||||||
* access sounds.
|
* access sounds.
|
||||||
* <p/>
|
* <p/>
|
||||||
* The container may be <tt>null</tt>, if no such context can be provided.
|
* The container may be <tt>null</tt>, if no such context can be provided.
|
||||||
|
* <p/>
|
||||||
|
* The access sound is the name of the sound effect to play when the file
|
||||||
|
* system is accessed, for example by listing a directory or reading from
|
||||||
|
* a file. It may be <tt>null</tt> to create a silent file system.
|
||||||
|
* <p/>
|
||||||
|
* The speed multiplier controls how fast read and write operations on the
|
||||||
|
* file system are. It must be a value in [1,6], and controls the access
|
||||||
|
* speed, with the default being one.
|
||||||
|
* For reference, floppies are using the default, hard drives scale with
|
||||||
|
* their tiers, i.e. a tier one hard drive uses speed two, tier three uses
|
||||||
|
* speed four.
|
||||||
|
*
|
||||||
|
* @param fileSystem the file system to wrap.
|
||||||
|
* @param label the label of the file system.
|
||||||
|
* @param host the tile entity containing the file system.
|
||||||
|
* @param accessSound the name of the sound effect to play when the file
|
||||||
|
* system is accessed. This has to be the fully
|
||||||
|
* qualified resource name, e.g.
|
||||||
|
* <tt>opencomputers:floppy_access</tt>.
|
||||||
|
* @param speed the speed multiplier for this file system.
|
||||||
|
* @return the network node wrapping the file system.
|
||||||
|
*/
|
||||||
|
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final Label label, final EnvironmentHost host, final String accessSound, int speed) {
|
||||||
|
if (API.fileSystem != null)
|
||||||
|
return API.fileSystem.asManagedEnvironment(fileSystem, label, host, accessSound, speed);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a network node that makes the specified file system available via
|
||||||
|
* the common file system driver.
|
||||||
|
* <p/>
|
||||||
|
* Creates a file system with the a read-only label and the specified
|
||||||
|
* access sound and file system speed.
|
||||||
|
*
|
||||||
|
* @param fileSystem the file system to wrap.
|
||||||
|
* @param label the label of the file system.
|
||||||
|
* @param host the tile entity containing the file system.
|
||||||
|
* @param accessSound the name of the sound effect to play when the file
|
||||||
|
* system is accessed. This has to be the fully
|
||||||
|
* qualified resource name, e.g.
|
||||||
|
* <tt>opencomputers:floppy_access</tt>.
|
||||||
|
* @param speed the speed multiplier for this file system.
|
||||||
|
* @return the network node wrapping the file system.
|
||||||
|
*/
|
||||||
|
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final String label, final EnvironmentHost host, final String accessSound, int speed) {
|
||||||
|
if (API.fileSystem != null)
|
||||||
|
return API.fileSystem.asManagedEnvironment(fileSystem, label, host, accessSound, speed);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a network node that makes the specified file system available via
|
||||||
|
* the common file system driver.
|
||||||
|
* <p/>
|
||||||
|
* Creates a file system with the specified label and the specified access
|
||||||
|
* sound, using the default file system speed.
|
||||||
*
|
*
|
||||||
* @param fileSystem the file system to wrap.
|
* @param fileSystem the file system to wrap.
|
||||||
* @param label the label of the file system.
|
* @param label the label of the file system.
|
||||||
@ -152,14 +209,15 @@ public final class FileSystem {
|
|||||||
* @return the network node wrapping the file system.
|
* @return the network node wrapping the file system.
|
||||||
*/
|
*/
|
||||||
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final Label label, final EnvironmentHost host, final String accessSound) {
|
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final Label label, final EnvironmentHost host, final String accessSound) {
|
||||||
if (API.fileSystem != null)
|
return asManagedEnvironment(fileSystem, label, host, accessSound, 1);
|
||||||
return API.fileSystem.asManagedEnvironment(fileSystem, label, host, accessSound);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, li.cil.oc.api.driver.EnvironmentHost, String)},
|
* Creates a network node that makes the specified file system available via
|
||||||
* but creates a read-only label initialized to the specified value.
|
* the common file system driver.
|
||||||
|
* <p/>
|
||||||
|
* Creates a file system with a read-only label and the specified access
|
||||||
|
* sound, using the default file system speed.
|
||||||
*
|
*
|
||||||
* @param fileSystem the file system to wrap.
|
* @param fileSystem the file system to wrap.
|
||||||
* @param label the read-only label of the file system.
|
* @param label the read-only label of the file system.
|
||||||
@ -171,51 +229,52 @@ public final class FileSystem {
|
|||||||
* @return the network node wrapping the file system.
|
* @return the network node wrapping the file system.
|
||||||
*/
|
*/
|
||||||
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final String label, final EnvironmentHost host, final String accessSound) {
|
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final String label, final EnvironmentHost host, final String accessSound) {
|
||||||
if (API.fileSystem != null)
|
return asManagedEnvironment(fileSystem, label, host, accessSound, 1);
|
||||||
return API.fileSystem.asManagedEnvironment(fileSystem, label, host, accessSound);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, li.cil.oc.api.driver.EnvironmentHost, String)},
|
* Creates a network node that makes the specified file system available via
|
||||||
* but does not provide a container.
|
* the common file system driver.
|
||||||
|
* <p/>
|
||||||
|
* Creates a file system with the specified label, without an environment
|
||||||
|
* and access sound, using the default file system speed.
|
||||||
*
|
*
|
||||||
* @param fileSystem the file system to wrap.
|
* @param fileSystem the file system to wrap.
|
||||||
* @param label the label of the file system.
|
* @param label the label of the file system.
|
||||||
* @return the network node wrapping the file system.
|
* @return the network node wrapping the file system.
|
||||||
*/
|
*/
|
||||||
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final Label label) {
|
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final Label label) {
|
||||||
if (API.fileSystem != null)
|
return asManagedEnvironment(fileSystem, label, null, null, 1);
|
||||||
return API.fileSystem.asManagedEnvironment(fileSystem, label);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label)},
|
* Creates a network node that makes the specified file system available via
|
||||||
* but creates a read-only label initialized to the specified value.
|
* the common file system driver.
|
||||||
|
* <p/>
|
||||||
|
* Creates a file system with a read-only label, without an environment and
|
||||||
|
* access sound, using the default file system speed.
|
||||||
*
|
*
|
||||||
* @param fileSystem the file system to wrap.
|
* @param fileSystem the file system to wrap.
|
||||||
* @param label the read-only label of the file system.
|
* @param label the read-only label of the file system.
|
||||||
* @return the network node wrapping the file system.
|
* @return the network node wrapping the file system.
|
||||||
*/
|
*/
|
||||||
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final String label) {
|
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem, final String label) {
|
||||||
if (API.fileSystem != null)
|
return asManagedEnvironment(fileSystem, label, null, null, 1);
|
||||||
return API.fileSystem.asManagedEnvironment(fileSystem, label);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label)},
|
* Creates a network node that makes the specified file system available via
|
||||||
* but creates an unlabeled file system (i.e. the label can neither be read
|
* the common file system driver.
|
||||||
* nor written).
|
* <p/>
|
||||||
|
* Creates an unlabeled file system (i.e. the label can neither be read nor
|
||||||
|
* written), without an environment and access sound, using the default
|
||||||
|
* file system speed.
|
||||||
*
|
*
|
||||||
* @param fileSystem the file system to wrap.
|
* @param fileSystem the file system to wrap.
|
||||||
* @return the network node wrapping the file system.
|
* @return the network node wrapping the file system.
|
||||||
*/
|
*/
|
||||||
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem) {
|
public static ManagedEnvironment asManagedEnvironment(final li.cil.oc.api.fs.FileSystem fileSystem) {
|
||||||
if (API.fileSystem != null)
|
return asManagedEnvironment(fileSystem, (Label) null, null, null, 1);
|
||||||
return API.fileSystem.asManagedEnvironment(fileSystem);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
@ -97,56 +97,76 @@ public interface FileSystemAPI {
|
|||||||
* access sounds.
|
* access sounds.
|
||||||
* <p/>
|
* <p/>
|
||||||
* The container may be <tt>null</tt>, if no such context can be provided.
|
* The container may be <tt>null</tt>, if no such context can be provided.
|
||||||
|
* <p/>
|
||||||
|
* The access sound is the name of the sound effect to play when the file
|
||||||
|
* system is accessed, for example by listing a directory or reading from
|
||||||
|
* a file. It may be <tt>null</tt> to create a silent file system.
|
||||||
|
* <p/>
|
||||||
|
* The speed multiplier controls how fast read and write operations on the
|
||||||
|
* file system are. It must be a value in [1,6], and controls the access
|
||||||
|
* speed, with the default being one.
|
||||||
|
* For reference, floppies are using the default, hard drives scale with
|
||||||
|
* their tiers, i.e. a tier one hard drive uses speed two, tier three uses
|
||||||
|
* speed four.
|
||||||
*
|
*
|
||||||
* @param fileSystem the file system to wrap.
|
* @param fileSystem the file system to wrap.
|
||||||
* @param label the label of the file system.
|
* @param label the label of the file system.
|
||||||
* @param host the tile entity containing the file system.
|
* @param host the tile entity containing the file system.
|
||||||
* @param accessSound the name of the sound effect to play when the file
|
* @param accessSound the name of the sound effect to play when the file
|
||||||
* system is accessed.
|
* system is accessed. This has to be the fully
|
||||||
|
* qualified resource name, e.g.
|
||||||
|
* <tt>opencomputers:floppy_access</tt>.
|
||||||
|
* @param speed the speed multiplier for this file system.
|
||||||
* @return the network node wrapping the file system.
|
* @return the network node wrapping the file system.
|
||||||
*/
|
*/
|
||||||
|
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label, EnvironmentHost host, String accessSound, int speed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a network node that makes the specified file system available via
|
||||||
|
* the common file system driver.
|
||||||
|
* <p/>
|
||||||
|
* Creates a file system with the a read-only label and the specified
|
||||||
|
* access sound and file system speed.
|
||||||
|
*
|
||||||
|
* @param fileSystem the file system to wrap.
|
||||||
|
* @param label the read-only label of the file system.
|
||||||
|
* @param host the tile entity containing the file system.
|
||||||
|
* @param accessSound the name of the sound effect to play when the file
|
||||||
|
* system is accessed. This has to be the fully
|
||||||
|
* qualified resource name, e.g.
|
||||||
|
* <tt>opencomputers:floppy_access</tt>.
|
||||||
|
* @param speed the speed multiplier for this file system.
|
||||||
|
* @return the network node wrapping the file system.
|
||||||
|
*/
|
||||||
|
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label, EnvironmentHost host, String accessSound, int speed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label, EnvironmentHost host, String accessSound);
|
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label, EnvironmentHost host, String accessSound);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, li.cil.oc.api.driver.EnvironmentHost, String)},
|
* @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}.
|
||||||
* but creates a read-only label initialized to the specified value.
|
|
||||||
*
|
|
||||||
* @param fileSystem the file system to wrap.
|
|
||||||
* @param label the read-only label of the file system.
|
|
||||||
* @param host the tile entity containing the file system.
|
|
||||||
* @param accessSound the name of the sound effect to play when the file
|
|
||||||
* system is accessed.
|
|
||||||
* @return the network node wrapping the file system.
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label, EnvironmentHost host, String accessSound);
|
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label, EnvironmentHost host, String accessSound);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, li.cil.oc.api.driver.EnvironmentHost, String)},
|
* @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}.
|
||||||
* but does not provide a container and access sound.
|
|
||||||
*
|
|
||||||
* @param fileSystem the file system to wrap.
|
|
||||||
* @param label the label of the file system.
|
|
||||||
* @return the network node wrapping the file system.
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label);
|
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label)},
|
* @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}.
|
||||||
* but creates a read-only label initialized to the specified value.
|
|
||||||
*
|
|
||||||
* @param fileSystem the file system to wrap.
|
|
||||||
* @param label the read-only label of the file system.
|
|
||||||
* @return the network node wrapping the file system.
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label);
|
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label)},
|
* @deprecated Don't use this directly, use the wrapper in {@link li.cil.oc.api.FileSystem}.
|
||||||
* but creates an unlabeled file system (i.e. the label can neither be read
|
|
||||||
* nor written).
|
|
||||||
*
|
|
||||||
* @param fileSystem the file system to wrap.
|
|
||||||
* @return the network node wrapping the file system.
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem);
|
ManagedEnvironment asManagedEnvironment(FileSystem fileSystem);
|
||||||
}
|
}
|
@ -5,7 +5,7 @@ import li.cil.oc.api.Persistable;
|
|||||||
/**
|
/**
|
||||||
* Used by file system components to get and set the file system's label.
|
* Used by file system components to get and set the file system's label.
|
||||||
*
|
*
|
||||||
* @see li.cil.oc.api.FileSystem#asManagedEnvironment(FileSystem, Label)
|
* @see li.cil.oc.api.FileSystem#asManagedEnvironment
|
||||||
*/
|
*/
|
||||||
public interface Label extends Persistable {
|
public interface Label extends Persistable {
|
||||||
/**
|
/**
|
||||||
|
@ -81,7 +81,7 @@ class Raid extends traits.Environment with traits.Inventory with traits.Rotatabl
|
|||||||
filesystem.foreach(fs => if (fs.node != null) fs.node.remove())
|
filesystem.foreach(fs => if (fs.node != null) fs.node.remove())
|
||||||
val fs = api.FileSystem.asManagedEnvironment(
|
val fs = api.FileSystem.asManagedEnvironment(
|
||||||
api.FileSystem.fromSaveDirectory(id, wipeDisksAndComputeSpace, Settings.get.bufferChanges),
|
api.FileSystem.fromSaveDirectory(id, wipeDisksAndComputeSpace, Settings.get.bufferChanges),
|
||||||
label, this, Settings.resourceDomain + ":hdd_access").
|
label, this, Settings.resourceDomain + ":hdd_access", 6).
|
||||||
asInstanceOf[FileSystem]
|
asInstanceOf[FileSystem]
|
||||||
val nbtToSetAddress = new NBTTagCompound()
|
val nbtToSetAddress = new NBTTagCompound()
|
||||||
nbtToSetAddress.setString("address", id)
|
nbtToSetAddress.setString("address", id)
|
||||||
|
@ -22,8 +22,8 @@ object DriverFileSystem extends Item {
|
|||||||
|
|
||||||
override def createEnvironment(stack: ItemStack, host: EnvironmentHost) =
|
override def createEnvironment(stack: ItemStack, host: EnvironmentHost) =
|
||||||
Delegator.subItem(stack) match {
|
Delegator.subItem(stack) match {
|
||||||
case Some(hdd: HardDiskDrive) => createEnvironment(stack, hdd.kiloBytes * 1024, host)
|
case Some(hdd: HardDiskDrive) => createEnvironment(stack, hdd.kiloBytes * 1024, host, hdd.tier + 2)
|
||||||
case Some(disk: FloppyDisk) => createEnvironment(stack, Settings.get.floppySize * 1024, host)
|
case Some(disk: FloppyDisk) => createEnvironment(stack, Settings.get.floppySize * 1024, host, 1)
|
||||||
case _ => null
|
case _ => null
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,14 +40,14 @@ object DriverFileSystem extends Item {
|
|||||||
case _ => 0
|
case _ => 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private def createEnvironment(stack: ItemStack, capacity: Int, host: EnvironmentHost) = {
|
private def createEnvironment(stack: ItemStack, capacity: Int, host: EnvironmentHost, speed: Int) = {
|
||||||
// We have a bit of a chicken-egg problem here, because we want to use the
|
// We have a bit of a chicken-egg problem here, because we want to use the
|
||||||
// node's address as the folder name... so we generate the address here,
|
// node's address as the folder name... so we generate the address here,
|
||||||
// if necessary. No one will know, right? Right!?
|
// if necessary. No one will know, right? Right!?
|
||||||
val address = addressFromTag(dataTag(stack))
|
val address = addressFromTag(dataTag(stack))
|
||||||
val isFloppy = api.Items.get(stack) == api.Items.get(Constants.ItemName.Floppy)
|
val isFloppy = api.Items.get(stack) == api.Items.get(Constants.ItemName.Floppy)
|
||||||
val fs = oc.api.FileSystem.fromSaveDirectory(address, capacity, Settings.get.bufferChanges)
|
val fs = oc.api.FileSystem.fromSaveDirectory(address, capacity, Settings.get.bufferChanges)
|
||||||
val environment = oc.api.FileSystem.asManagedEnvironment(fs, new ReadWriteItemLabel(stack), host, Settings.resourceDomain + ":" + (if (isFloppy) "floppy_access" else "hdd_access"))
|
val environment = oc.api.FileSystem.asManagedEnvironment(fs, new ReadWriteItemLabel(stack), host, Settings.resourceDomain + ":" + (if (isFloppy) "floppy_access" else "hdd_access"), speed)
|
||||||
if (environment != null && environment.node != null) {
|
if (environment != null && environment.node != null) {
|
||||||
environment.node.asInstanceOf[oc.server.network.Node].address = address
|
environment.node.asInstanceOf[oc.server.network.Node].address = address
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import net.minecraftforge.common.util.Constants.NBT
|
|||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
|
|
||||||
class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option[EnvironmentHost] = None, val sound: Option[String] = None) extends prefab.ManagedEnvironment {
|
class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option[EnvironmentHost], val sound: Option[String]) extends prefab.ManagedEnvironment {
|
||||||
override val node = Network.newNode(this, Visibility.Network).
|
override val node = Network.newNode(this, Visibility.Network).
|
||||||
withComponent("filesystem", Visibility.Neighbors).
|
withComponent("filesystem", Visibility.Neighbors).
|
||||||
withConnector().
|
withConnector().
|
||||||
@ -151,7 +151,6 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option
|
|||||||
result(handle)
|
result(handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback(direct = true, limit = 4, doc = """function(handle:number, count:number):string or nil -- Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached.""")
|
|
||||||
def read(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized {
|
def read(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized {
|
||||||
val handle = args.checkInteger(0)
|
val handle = args.checkInteger(0)
|
||||||
val n = math.min(Settings.get.maxReadBuffer, math.max(0, args.checkInteger(1)))
|
val n = math.min(Settings.get.maxReadBuffer, math.max(0, args.checkInteger(1)))
|
||||||
@ -183,7 +182,6 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback(direct = true, limit = 4, doc = """function(handle:number, whence:string, offset:number):number -- Seeks in an open file descriptor with the specified handle. Returns the new pointer position.""")
|
|
||||||
def seek(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized {
|
def seek(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized {
|
||||||
val handle = args.checkInteger(0)
|
val handle = args.checkInteger(0)
|
||||||
val whence = args.checkString(1)
|
val whence = args.checkString(1)
|
||||||
@ -202,7 +200,6 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback(doc = """function(handle:number, value:string):boolean -- Writes the specified data to an open file descriptor with the specified handle.""")
|
|
||||||
def write(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized {
|
def write(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized {
|
||||||
val handle = args.checkInteger(0)
|
val handle = args.checkInteger(0)
|
||||||
val value = args.checkByteArray(1)
|
val value = args.checkByteArray(1)
|
||||||
@ -315,3 +312,69 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object FileSystem {
|
||||||
|
// I really need to come up with a way to make the call limit dynamic...
|
||||||
|
def apply(fileSystem: IFileSystem, label: Label, host: Option[EnvironmentHost], sound: Option[String], speed: Int = 1): FileSystem = speed match {
|
||||||
|
case 6 => new FileSystem(fileSystem, label, host, sound) {
|
||||||
|
@Callback(direct = true, limit = 15, doc = """function(handle:number, count:number):string or nil -- Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached.""")
|
||||||
|
override def read(context: Context, args: Arguments): Array[AnyRef] = super.read(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 15, doc = """function(handle:number, whence:string, offset:number):number -- Seeks in an open file descriptor with the specified handle. Returns the new pointer position.""")
|
||||||
|
override def seek(context: Context, args: Arguments): Array[AnyRef] = super.seek(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 6, doc = """function(handle:number, value:string):boolean -- Writes the specified data to an open file descriptor with the specified handle.""")
|
||||||
|
override def write(context: Context, args: Arguments): Array[AnyRef] = super.write(context, args)
|
||||||
|
}
|
||||||
|
case 5 => new FileSystem(fileSystem, label, host, sound) {
|
||||||
|
@Callback(direct = true, limit = 13, doc = """function(handle:number, count:number):string or nil -- Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached.""")
|
||||||
|
override def read(context: Context, args: Arguments): Array[AnyRef] = super.read(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 13, doc = """function(handle:number, whence:string, offset:number):number -- Seeks in an open file descriptor with the specified handle. Returns the new pointer position.""")
|
||||||
|
override def seek(context: Context, args: Arguments): Array[AnyRef] = super.seek(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 5, doc = """function(handle:number, value:string):boolean -- Writes the specified data to an open file descriptor with the specified handle.""")
|
||||||
|
override def write(context: Context, args: Arguments): Array[AnyRef] = super.write(context, args)
|
||||||
|
}
|
||||||
|
case 4 => new FileSystem(fileSystem, label, host, sound) {
|
||||||
|
@Callback(direct = true, limit = 10, doc = """function(handle:number, count:number):string or nil -- Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached.""")
|
||||||
|
override def read(context: Context, args: Arguments): Array[AnyRef] = super.read(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 10, doc = """function(handle:number, whence:string, offset:number):number -- Seeks in an open file descriptor with the specified handle. Returns the new pointer position.""")
|
||||||
|
override def seek(context: Context, args: Arguments): Array[AnyRef] = super.seek(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 4, doc = """function(handle:number, value:string):boolean -- Writes the specified data to an open file descriptor with the specified handle.""")
|
||||||
|
override def write(context: Context, args: Arguments): Array[AnyRef] = super.write(context, args)
|
||||||
|
}
|
||||||
|
case 3 => new FileSystem(fileSystem, label, host, sound) {
|
||||||
|
@Callback(direct = true, limit = 7, doc = """function(handle:number, count:number):string or nil -- Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached.""")
|
||||||
|
override def read(context: Context, args: Arguments): Array[AnyRef] = super.read(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 7, doc = """function(handle:number, whence:string, offset:number):number -- Seeks in an open file descriptor with the specified handle. Returns the new pointer position.""")
|
||||||
|
override def seek(context: Context, args: Arguments): Array[AnyRef] = super.seek(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 3, doc = """function(handle:number, value:string):boolean -- Writes the specified data to an open file descriptor with the specified handle.""")
|
||||||
|
override def write(context: Context, args: Arguments): Array[AnyRef] = super.write(context, args)
|
||||||
|
}
|
||||||
|
case 2 => new FileSystem(fileSystem, label, host, sound) {
|
||||||
|
@Callback(direct = true, limit = 4, doc = """function(handle:number, count:number):string or nil -- Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached.""")
|
||||||
|
override def read(context: Context, args: Arguments): Array[AnyRef] = super.read(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 4, doc = """function(handle:number, whence:string, offset:number):number -- Seeks in an open file descriptor with the specified handle. Returns the new pointer position.""")
|
||||||
|
override def seek(context: Context, args: Arguments): Array[AnyRef] = super.seek(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 2, doc = """function(handle:number, value:string):boolean -- Writes the specified data to an open file descriptor with the specified handle.""")
|
||||||
|
override def write(context: Context, args: Arguments): Array[AnyRef] = super.write(context, args)
|
||||||
|
}
|
||||||
|
case _ => new FileSystem(fileSystem, label, host, sound) {
|
||||||
|
@Callback(direct = true, limit = 1, doc = """function(handle:number, count:number):string or nil -- Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached.""")
|
||||||
|
override def read(context: Context, args: Arguments): Array[AnyRef] = super.read(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 1, doc = """function(handle:number, whence:string, offset:number):number -- Seeks in an open file descriptor with the specified handle. Returns the new pointer position.""")
|
||||||
|
override def seek(context: Context, args: Arguments): Array[AnyRef] = super.seek(context, args)
|
||||||
|
|
||||||
|
@Callback(direct = true, limit = 1, doc = """function(handle:number, value:string):boolean -- Writes the specified data to an open file descriptor with the specified handle.""")
|
||||||
|
override def write(context: Context, args: Arguments): Array[AnyRef] = super.write(context, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -104,20 +104,26 @@ object FileSystem extends api.detail.FileSystemAPI {
|
|||||||
}
|
}
|
||||||
else null
|
else null
|
||||||
|
|
||||||
|
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, host: EnvironmentHost, accessSound: String, speed: Int) =
|
||||||
|
Option(fileSystem).flatMap(fs => Some(component.FileSystem(fs, label, Option(host), Option(accessSound), speed))).orNull
|
||||||
|
|
||||||
|
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String, host: EnvironmentHost, accessSound: String, speed: Int) =
|
||||||
|
asManagedEnvironment(fileSystem, new ReadOnlyLabel(label), host, accessSound, speed)
|
||||||
|
|
||||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, host: EnvironmentHost, sound: String) =
|
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label, host: EnvironmentHost, sound: String) =
|
||||||
Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label, Option(host), Option(sound)))).orNull
|
asManagedEnvironment(fileSystem, label, host, sound, 1)
|
||||||
|
|
||||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String, host: EnvironmentHost, sound: String) =
|
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String, host: EnvironmentHost, sound: String) =
|
||||||
asManagedEnvironment(fileSystem, new ReadOnlyLabel(label), host, sound)
|
asManagedEnvironment(fileSystem, new ReadOnlyLabel(label), host, sound, 1)
|
||||||
|
|
||||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label) =
|
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: Label) =
|
||||||
Option(fileSystem).flatMap(fs => Some(new component.FileSystem(fs, label))).orNull
|
asManagedEnvironment(fileSystem, label, null, null, 1)
|
||||||
|
|
||||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String) =
|
def asManagedEnvironment(fileSystem: api.fs.FileSystem, label: String) =
|
||||||
asManagedEnvironment(fileSystem, new ReadOnlyLabel(label))
|
asManagedEnvironment(fileSystem, new ReadOnlyLabel(label), null, null, 1)
|
||||||
|
|
||||||
def asManagedEnvironment(fileSystem: api.fs.FileSystem) =
|
def asManagedEnvironment(fileSystem: api.fs.FileSystem) =
|
||||||
asManagedEnvironment(fileSystem, null: Label)
|
asManagedEnvironment(fileSystem, null: Label, null, null, 1)
|
||||||
|
|
||||||
abstract class ItemLabel(val stack: ItemStack) extends Label
|
abstract class ItemLabel(val stack: ItemStack) extends Label
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
|
|||||||
|
|
||||||
val tmp = if (Settings.get.tmpSize > 0) {
|
val tmp = if (Settings.get.tmpSize > 0) {
|
||||||
Option(FileSystem.asManagedEnvironment(FileSystem.
|
Option(FileSystem.asManagedEnvironment(FileSystem.
|
||||||
fromMemory(Settings.get.tmpSize * 1024), "tmpfs"))
|
fromMemory(Settings.get.tmpSize * 1024), "tmpfs", null, null, 5))
|
||||||
} else None
|
} else None
|
||||||
|
|
||||||
var architecture: Architecture = _
|
var architecture: Architecture = _
|
||||||
|
Loading…
x
Reference in New Issue
Block a user