-
Notifications
You must be signed in to change notification settings - Fork 2
Creating HFS devices
It is very similar to the idea of /dev in Unix-based systems. Basically, HFS devices aren't files, they are pseudo-files that when written to/read from, will run a method attached to the device.
HFS devices are defined by a Rary.HFS.HFSDevice class. HFSDevice provides a base for an HFS device. It includes DevicePath, SupportsStdout, SupportsStdin, stdout(), and stdin().
-
string DevicePath- Where the HFS has to interact with to access your HFSDevice. This HAS to be at /, for example,/console. If it's not at /, then your device won't show up anywhere except the device manager. -
bool SupportsStdout- If you are going to make aStdout()override, then set this to true. This is to prevent user confusion when interacting with a device does nothing. -
bool SupportsStdin- If you are going to make aStdin()override, then set this to true. This is to prevent user confusion when interacting with a device does nothing. -
string stdout()- This is what your device will return when your device is being read from. -
void stdin(string input)- This is what your device will do when your device is being written to.
For this example, we will be using
Rary.HFS.HFSDevices.HFSTextModeDevice.
In C#, you can build a class upon another class to override fields and methods set by the base class. This is done with the : symbol.
Example:
public class HFSTextModeDevice : HFSDevice
Then, to override the fields like DevicePath, we create a method that runs when new() is called (This is done by making a method with the same name as the class, also no return value at all). This method will initialize the fields so that they can be used properly for your device.
Example:
public HFSTextModeDevice()
{
DevicePath = "/console";
SupportsStdin = true;
SupportsStdout = true;
}After that, you have to create the overrides for the stdout and stdin methods. You can do this by parsing the override keyword to show that you are overriding a method in the base class.
Example:
public override string stdout()
{
return Console.ReadLine();
}
public override void stdin(string input)
{
Console.Write(input);
}And there you have it! An HFSDevice override.
That sounds complicated, but don't worry.
The device manager handles all communication and registration of HFS devices.
It has a List that shows what devices have been registered, and it has Read, Write, and Delete methods to interact with devices.
Rary.HFS.HFSDeviceManager is non-static, which means that we will need to use an instance of it to do anything. However, Rary.HFS.HFS handles this by creating an instance automatically when an HFS is created. So, we can initialize a new instance of our device, then add it to HFSDeviceManager's devices list. Right now, There's no method to add a device, so we can directly use the list's add method.
Example:
Rary.HFS.HFS hfs = new("/");
hfs.devmanager.devices.Add(new InsertDeviceNameHere());And that's it! If you have any problems following this guide, then open an issue and I'll be happy to help.