use new kernel settings

This commit is contained in:
Djeeberjr 2023-06-07 21:29:29 +02:00
parent 6fcbcfce8d
commit 7c7529ae39
4 changed files with 35 additions and 51 deletions

View File

@ -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;
});
}, "<id> <name>");
}, "<name>");
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;
});
}, "<id> <name> <id>");
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;
});
}, "<id> <name>");
}, "<name> <id>");
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;
});
}, "<name>");
}
}

View File

@ -19,6 +19,7 @@ class DCEHack {
new bin.srsc.SiteRessourceController(),
new bin.srsc.CLI(),
new bin.Perf(),
new bin.KSettings(),
];
}
}

View File

@ -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)

View File

@ -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<Null<NetworkID>> {
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<Bool> {
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<Noise> {
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
);