removed export system
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
package lib.exporter;
|
||||
|
||||
import kernel.peripherals.IPeripheral;
|
||||
import kernel.log.Log;
|
||||
|
||||
using tink.CoreApi;
|
||||
|
||||
class Export {
|
||||
private final exportConfig:ExportConfig;
|
||||
private final peripheral:IPeripheral;
|
||||
|
||||
public function new<T:IExportable & IPeripheral>(exportPerph:T) {
|
||||
this.peripheral = exportPerph;
|
||||
this.exportConfig = exportPerph.export();
|
||||
}
|
||||
|
||||
public function handleRequest(req:Request):Response {
|
||||
switch (req.operation) {
|
||||
case Get:
|
||||
return handleGet(req);
|
||||
case Set(value):
|
||||
// TODO: implement
|
||||
return NotFound;
|
||||
}
|
||||
}
|
||||
|
||||
private function handleGet(request:Request):Response {
|
||||
if (!this.exportConfig.getDelegates.exists(request.field)) {
|
||||
Log.warn('Requested get field ${request.field} does not exist in ??');
|
||||
return NotFound;
|
||||
}
|
||||
|
||||
var delegate = this.exportConfig.getDelegates.get(request.field);
|
||||
var value = delegate(request.index);
|
||||
|
||||
return Get(value);
|
||||
}
|
||||
|
||||
public function getType():String {
|
||||
return this.peripheral.getType();
|
||||
}
|
||||
|
||||
public function getAddr():String {
|
||||
return this.peripheral.getAddr();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package lib.exporter;
|
||||
|
||||
import lib.exporter.Response;
|
||||
|
||||
typedef ExportConfig = {
|
||||
getDelegates:Map<String, Null<Int>->ValueType>,
|
||||
// setDelegates: Map<String, (ValueType, Null<Int>)->ValueType>,
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package lib.exporter;
|
||||
|
||||
interface IExportable {
|
||||
public function export():ExportConfig;
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package lib.exporter;
|
||||
|
||||
import kernel.KernelSettings;
|
||||
import kernel.net.Net;
|
||||
import kernel.net.Package.NetworkID;
|
||||
|
||||
using tink.CoreApi;
|
||||
|
||||
class Import {
|
||||
public static function get(ressourceLocator:String):Promise<Response> {
|
||||
var request = Request.fromString(ressourceLocator);
|
||||
var rpc = new SiteRessourceControllerRPC(KernelSettings.siteController);
|
||||
|
||||
return rpc.get(request.id).next((response) -> {
|
||||
return performRequest(response, request);
|
||||
});
|
||||
}
|
||||
|
||||
private static function performRequest(netID:NetworkID, request:Request):Promise<Response> {
|
||||
return Net.sendAndAwait(netID, "res", request).map((response) -> {
|
||||
switch (response) {
|
||||
case Success(data):
|
||||
return Success(cast(data.data, Response));
|
||||
case Failure(error):
|
||||
return Failure(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package lib.exporter;
|
||||
|
||||
enum Operation {
|
||||
Get;
|
||||
Set(value:Dynamic);
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package lib.exporter;
|
||||
|
||||
import lua.TableTools;
|
||||
import lua.NativeStringTools;
|
||||
|
||||
class Request {
|
||||
public final id:String;
|
||||
public final field:String;
|
||||
public final index:Null<Int>;
|
||||
public final operation:Operation;
|
||||
|
||||
public function new(id:String, field:String, index:Null<Int>, operation:Operation) {
|
||||
this.id = id;
|
||||
this.field = field;
|
||||
this.index = index;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
/**
|
||||
Example:
|
||||
"myfield[2]@myid"
|
||||
"myfield@myid"
|
||||
**/
|
||||
public static function fromString(locator:String):Request {
|
||||
if (StringTools.contains(locator, "[")) {
|
||||
var f = TableTools.pack(NativeStringTools.gmatch(locator, "(%a+)%[([%d]+)%]@(%a+)")());
|
||||
|
||||
var field = f[1];
|
||||
var index = Std.parseInt(f[2]);
|
||||
var id = f[3];
|
||||
|
||||
return new Request(id, field, index, Get);
|
||||
} else {
|
||||
var f = TableTools.pack(NativeStringTools.gmatch(locator, "(%a+)@(%a+)")());
|
||||
|
||||
var field = f[1];
|
||||
var id = f[2];
|
||||
|
||||
return new Request(id, field, null, Get);
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() {
|
||||
if (index == null) {
|
||||
return field + "@" + id;
|
||||
} else {
|
||||
return field + "[" + index + "]@" + id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package lib.exporter;
|
||||
|
||||
enum Response {
|
||||
NotFound;
|
||||
Set;
|
||||
NotSet;
|
||||
Get(value:ValueType);
|
||||
}
|
||||
|
||||
enum ValueType {
|
||||
Number(value:Int);
|
||||
String(value:String);
|
||||
Bool(value:Bool);
|
||||
}
|
||||
Reference in New Issue
Block a user