ALL NEW improved Binstore
also automaticly inlcude everything in src/bin
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
package kernel;
|
||||
|
||||
@:keep
|
||||
class DCEHack {
|
||||
// Dont actually call this
|
||||
public static function load():Array<kernel.ps.Process> {
|
||||
macros.DCEHack.dceGenerateCreate();
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import kernel.net.Routing;
|
||||
import lib.Debug;
|
||||
import kernel.ui.WindowManager;
|
||||
import kernel.net.Net;
|
||||
import kernel.DCEHack; // Important for DCE hack
|
||||
|
||||
class Init {
|
||||
@:allow(kernel.KernelEvents)
|
||||
|
||||
@@ -6,7 +6,7 @@ import kernel.ps.Process;
|
||||
Represents a callable program.
|
||||
**/
|
||||
typedef Bin = {
|
||||
c:Class<Process>,
|
||||
c:Void->Process,
|
||||
name:String,
|
||||
aliases:Array<String>,
|
||||
}
|
||||
|
||||
@@ -1,64 +1,31 @@
|
||||
package kernel.binstore;
|
||||
|
||||
import bin.turtle.Excavate;
|
||||
import bin.turtle.Patrol;
|
||||
import bin.pathfinder.PFClient;
|
||||
import bin.ID;
|
||||
import bin.exporter.Res;
|
||||
import bin.exporter.ResManager;
|
||||
import bin.KSettings;
|
||||
import bin.Perf;
|
||||
import bin.srsc.CLI;
|
||||
import bin.srsc.SiteRessourceController;
|
||||
import bin.HelloWorldService;
|
||||
import bin.Service;
|
||||
import bin.LSPS;
|
||||
import bin.Turtle;
|
||||
import bin.Terminal;
|
||||
import bin.Redstone;
|
||||
import bin.Net;
|
||||
import bin.KernelLog;
|
||||
import bin.HelloWorld;
|
||||
import bin.GPS;
|
||||
import bin.Disk;
|
||||
import haxe.ds.ReadOnlyArray;
|
||||
import kernel.ps.Process;
|
||||
import macros.Binstore;
|
||||
|
||||
class BinStore {
|
||||
private static final store:ReadOnlyArray<Bin> = [
|
||||
{c: Disk, name: "Disk", aliases: ["disk"]},
|
||||
{c: GPS, name: "GPS", aliases: ["gps"]},
|
||||
{c: HelloWorld, name: "HelloWorld", aliases: ["hello"]},
|
||||
{c: KernelLog, name: "KernelLog", aliases: ["log"]},
|
||||
{c: Net, name: "Net", aliases: ["net"]},
|
||||
{c: Redstone, name: "Redstone", aliases: ["redstone", "rs"]},
|
||||
{c: Terminal, name: "Terminal", aliases: ["terminal", "term"]},
|
||||
{c: Turtle, name: "Turtle", aliases: ["turtle", "t"]},
|
||||
{c: LSPS, name: "PM", aliases: ["lsps"]},
|
||||
{c: Service, name: "Service", aliases: ["service", "srv"]},
|
||||
{c: HelloWorldService, name: "HelloWorldService", aliases: ["hello-service"]},
|
||||
{c: SiteRessourceController, name: "SiteRessourceController", aliases: ["srsc"]},
|
||||
{c: CLI, name: "SRSC CLI", aliases: ["srsc-cli"]},
|
||||
{c: Perf, name: "Perf", aliases: ["perf"]},
|
||||
{c: KSettings, name: "KSettings", aliases: ["ksettings", "ks"]},
|
||||
{c: ResManager, name: "ResManager", aliases: ["resmanager", "resmgr"]},
|
||||
{c: Res, name: "Res", aliases: ["res"]},
|
||||
{c: ID, name: "ID", aliases: ["id"]},
|
||||
{c: PFClient, name: "PFClient", aliases: ["pfclient"]},
|
||||
{c: Patrol, name: "Patrol", aliases: ["patrol"]},
|
||||
{c: Excavate, name: "Excavate", aliases: ["excavate"]}
|
||||
];
|
||||
private static final bins:Array<Bin> = populateStore();
|
||||
|
||||
public static function getBinByName(name:String):Null<Bin> {
|
||||
for (bin in store) {
|
||||
if (bin.name == name) {
|
||||
return bin;
|
||||
private static function populateStore()
|
||||
return {
|
||||
var bins:Array<Bin> = [];
|
||||
Binstore.generateBinStore();
|
||||
return bins;
|
||||
}
|
||||
|
||||
public static function instantiate(alias:String):Null<Process> {
|
||||
for (bin in bins) {
|
||||
for (a in bin.aliases) {
|
||||
if (a == alias) {
|
||||
return bin.c();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getBinByAlias(alias:String):Null<Bin> {
|
||||
for (bin in store) {
|
||||
private static function getBinByAlias(alias:String):Null<Bin> {
|
||||
for (bin in bins) {
|
||||
for (a in bin.aliases) {
|
||||
if (a == alias) {
|
||||
return bin;
|
||||
@@ -68,7 +35,7 @@ class BinStore {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getNameByAlias(alias:String):String {
|
||||
public static function getNameByAlias(alias:String):Null<String> {
|
||||
var bin = getBinByAlias(alias);
|
||||
if (bin == null) {
|
||||
return null;
|
||||
|
||||
@@ -3,7 +3,6 @@ package kernel.ps;
|
||||
/**
|
||||
Defines an independent process that can be run by the kernel.
|
||||
**/
|
||||
@:autoBuild(macros.DCEHack.DCEHack.dceInclude())
|
||||
interface Process {
|
||||
public function run(handle:ProcessHandle):Void;
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ class Service {
|
||||
}
|
||||
|
||||
public function start() {
|
||||
var bin = BinStore.getBinByAlias(this.binName);
|
||||
var ps = BinStore.instantiate(this.binName);
|
||||
|
||||
if (bin == null) {
|
||||
if (ps == null) {
|
||||
throw new Error('Bin ${this.binName} not found');
|
||||
}
|
||||
|
||||
this.ps = Type.createInstance(bin.c, this.args);
|
||||
this.ps = ps;
|
||||
|
||||
this.pid = ProcessManager.run(this.ps, {});
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class ServiceManager {
|
||||
}
|
||||
|
||||
public static function register(name:String, binName:String, args:Array<String>):Outcome<Noise, String> {
|
||||
if (BinStore.getBinByAlias(binName) == null) {
|
||||
if (BinStore.getNameByAlias(binName) == null) {
|
||||
return Failure("bin not found");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user