From 7c7529ae39738798fb0a144c1376f19eb2a29323 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Wed, 7 Jun 2023 21:29:29 +0200 Subject: [PATCH] use new kernel settings --- src/bin/srsc/CLI.hx | 66 ++++++++++++--------------------- src/kernel/DCEHack.hx | 1 + src/kernel/binstore/BinStore.hx | 4 +- src/lib/RessourceNames.hx | 15 ++++---- 4 files changed, 35 insertions(+), 51 deletions(-) diff --git a/src/bin/srsc/CLI.hx b/src/bin/srsc/CLI.hx index 3a74bb7..8cb832f 100644 --- a/src/bin/srsc/CLI.hx +++ b/src/bin/srsc/CLI.hx @@ -9,18 +9,12 @@ using tink.CoreApi; class CLI extends CLIAppBase { public function new() { registerAsyncSubcommand("get", (args) -> { - if (args.length < 2) { + if (args.length < 1) { handle.writeLine("Not enough arguments"); return Future.sync(false); } - var id:NetworkID = Std.parseInt(args[0]); - if (id == null) { - handle.writeLine("Invalid id"); - return Future.sync(false); - } - - return RessourceNames.get(args[1], id).map((res) -> { + return RessourceNames.get(args[0]).map((res) -> { switch (res) { case Success(data): if (data == null) { @@ -33,51 +27,21 @@ class CLI extends CLIAppBase { } return true; }); - }, " "); + }, ""); registerAsyncSubcommand("register", (args) -> { - if (args.length < 3) { - handle.writeLine("Not enough arguments"); - return Future.sync(false); - } - - var id:NetworkID = Std.parseInt(args[0]); - if (id == null) { - handle.writeLine("Invalid id"); - return Future.sync(false); - } - - var id2:NetworkID = Std.parseInt(args[2]); - if (id2 == null) { - handle.writeLine("Invalid id"); - return Future.sync(false); - } - - return RessourceNames.register(args[1], id2, id).map((res) -> { - switch (res) { - case Success(data): - handle.writeLine("Success"); - case Failure(error): - handle.writeLine("Error: " + error); - } - - return true; - }); - }, " "); - - registerAsyncSubcommand("unregister", (args) -> { if (args.length < 2) { handle.writeLine("Not enough arguments"); return Future.sync(false); } - var id:NetworkID = Std.parseInt(args[0]); + var id:NetworkID = Std.parseInt(args[1]); if (id == null) { handle.writeLine("Invalid id"); return Future.sync(false); } - return RessourceNames.unregister(args[1], id).map((res) -> { + return RessourceNames.register(args[0], id).map((res) -> { switch (res) { case Success(data): handle.writeLine("Success"); @@ -87,6 +51,24 @@ class CLI extends CLIAppBase { return true; }); - }, " "); + }, " "); + + registerAsyncSubcommand("unregister", (args) -> { + if (args.length < 1) { + handle.writeLine("Not enough arguments"); + return Future.sync(false); + } + + return RessourceNames.unregister(args[0]).map((res) -> { + switch (res) { + case Success(data): + handle.writeLine("Success"); + case Failure(error): + handle.writeLine("Error: " + error); + } + + return true; + }); + }, ""); } } diff --git a/src/kernel/DCEHack.hx b/src/kernel/DCEHack.hx index d24c0b9..bd9c7c1 100644 --- a/src/kernel/DCEHack.hx +++ b/src/kernel/DCEHack.hx @@ -19,6 +19,7 @@ class DCEHack { new bin.srsc.SiteRessourceController(), new bin.srsc.CLI(), new bin.Perf(), + new bin.KSettings(), ]; } } diff --git a/src/kernel/binstore/BinStore.hx b/src/kernel/binstore/BinStore.hx index c83b760..463af4a 100644 --- a/src/kernel/binstore/BinStore.hx +++ b/src/kernel/binstore/BinStore.hx @@ -1,5 +1,6 @@ package kernel.binstore; +import bin.KSettings; import bin.Perf; import bin.srsc.CLI; import bin.srsc.SiteRessourceController; @@ -33,7 +34,8 @@ class BinStore { {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: Perf, name: "Perf", aliases: ["perf"]}, + {c: KSettings, name: "KSettings", aliases: ["ksettings","ks"]}, ]; @:allow(kernel.Init) diff --git a/src/lib/RessourceNames.hx b/src/lib/RessourceNames.hx index bb1481e..35a91b2 100644 --- a/src/lib/RessourceNames.hx +++ b/src/lib/RessourceNames.hx @@ -1,5 +1,6 @@ package lib; +import kernel.KernelSettings; import bin.srsc.PackageTypes.UnregisterRequest; import kernel.log.Log; import bin.srsc.PackageTypes.RegisterRequest; @@ -11,15 +12,13 @@ import kernel.net.Package.NetworkID; using tink.CoreApi; class RessourceNames { - private static final SITE_CONTROLLER:NetworkID = 0; // Temporary TODO: Change to real ID - public static function get(name: String, controllerID: NetworkID = -1): Promise> { - if (controllerID == -1) controllerID = SITE_CONTROLLER; + if (controllerID == -1) controllerID = KernelSettings.siteController; var payload: GetRequest = {name: name, type: "get"}; return Net.instance.sendAndAwait( - SITE_CONTROLLER, + controllerID, SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, payload ).map((res)->{ @@ -33,12 +32,12 @@ class RessourceNames { } public static function register(name: String, netID: NetworkID, controllerID: NetworkID = -1): Promise { - if (controllerID == -1) controllerID = SITE_CONTROLLER; + if (controllerID == -1) controllerID = KernelSettings.siteController; var payload: RegisterRequest = {name: name, netID: netID, type: "register"}; return Net.instance.sendAndAwait( - SITE_CONTROLLER, + controllerID, SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, payload ).map((res)->{ @@ -53,12 +52,12 @@ class RessourceNames { } public static function unregister(name: String, controllerID: NetworkID = -1): Promise { - if (controllerID == -1) controllerID = SITE_CONTROLLER; + if (controllerID == -1) controllerID = KernelSettings.siteController; var payload: UnregisterRequest = {name: name, type: "unregister"}; return Net.instance.sendAndAwait( - SITE_CONTROLLER, + controllerID, SiteRessourceController.SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, payload );