diff --git a/src/bin/srsc/CLI.hx b/src/bin/srsc/CLI.hx deleted file mode 100644 index 8c3d748..0000000 --- a/src/bin/srsc/CLI.hx +++ /dev/null @@ -1,99 +0,0 @@ -package bin.srsc; - -import kernel.KernelSettings; -import kernel.net.Package.NetworkID; -import lib.CLIAppBase; - -using tink.CoreApi; - -class CLI extends CLIAppBase { - public function new() { - registerAsyncSubcommand("get", (args) -> { - if (args.length < 1) { - handle.writeLine("Not enough arguments"); - return Future.sync(false); - } - - var rpc = new SiteRessourceControllerRPC(KernelSettings.siteController); - - return rpc.get(args[0]).map((res) -> { - switch (res) { - case Success(data): - if (data == null) { - handle.writeLine("Not found"); - } else { - handle.writeLine("Found: " + data); - } - case Failure(error): - handle.writeLine("Error: " + error); - } - return true; - }); - }, ""); - - registerAsyncSubcommand("register", (args) -> { - if (args.length < 2) { - handle.writeLine("Not enough arguments"); - return Future.sync(false); - } - - var id:NetworkID = Std.parseInt(args[1]); - if (id == null) { - handle.writeLine("Invalid id"); - return Future.sync(false); - } - - var rpc = new SiteRessourceControllerRPC(KernelSettings.siteController); - - return rpc.register(args[0], 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 < 1) { - handle.writeLine("Not enough arguments"); - return Future.sync(false); - } - - var rpc = new SiteRessourceControllerRPC(KernelSettings.siteController); - - // FIXME - return Future.sync(true); - // return rpc.unregister(args[0]).map((res) -> { - // switch (res) { - // case Success(_): - // handle.writeLine("Success"); - // case Failure(error): - // handle.writeLine("Error: " + error); - // } - - // return true; - // }); - }, ""); - - registerAsyncSubcommand("list", (args) -> { - var rpc = new SiteRessourceControllerRPC(KernelSettings.siteController); - - return rpc.list().map((res) -> { - switch (res) { - case Success(data): - for (name in data) { - handle.writeLine(name); - } - case Failure(error): - handle.writeLine("Error: " + error); - } - - return true; - }); - }); - } -} diff --git a/src/bin/srsc/SiteRessourceController.hx b/src/bin/srsc/SiteRessourceController.hx deleted file mode 100644 index 816430e..0000000 --- a/src/bin/srsc/SiteRessourceController.hx +++ /dev/null @@ -1,76 +0,0 @@ -package bin.srsc; - -import macros.rpc.RPC; -import lib.KVStore; -import kernel.net.Package; -import kernel.ps.ProcessHandle; -import kernel.ps.Process; - -using tink.CoreApi; - -/** - The SiteRessourceController is responsible for the management of ressources on the site. - It makes sure that ressources are have a unique id and that they are not duplicated. - It also keeps track of the responsible NetID for each ressource. Kinda like a DNS. -**/ -@:build(macros.rpc.RPC.buildRPC()) -class SiteRessourceController implements Process { - private var handle:ProcessHandle; - private var ressources:Map; - - public function new() {} - - public function run(handle:ProcessHandle) { - this.handle = handle; - - load(); - - RPC.generateRPCPackageHandle(); - } - - @rpc - public function register(name:String, netID:NetworkID):Bool { - if (ressources.exists(name) && ressources.get(name) != netID) { - return false; - } - - ressources.set(name, netID); - save(); - return true; - } - - @rpc - public function unregister(name:String):Void { - if (ressources.exists(name)) { - ressources.remove(name); - } - save(); - } - - @rpc - public function get(name:String):Null { - return ressources.get(name); - } - - @rpc - public function list():Array { - return [for (k in ressources.keys()) k]; - } - - private function load() { - var store = KVStore.getStoreForClass(); - var data:Null> = store.get("ressources"); - - if (data != null) { - this.ressources = data; - } else { - this.ressources = new Map(); - } - } - - private function save() { - var store = KVStore.getStoreForClass(); - store.set("ressources", this.ressources); - store.save(); - } -}