idk routing stuff i guess
This commit is contained in:
@@ -1,101 +1,71 @@
|
||||
package kernel.peripherals;
|
||||
|
||||
import haxe.exceptions.NotImplementedException;
|
||||
import haxe.Exception;
|
||||
using tink.CoreApi;
|
||||
|
||||
using lua.Table;
|
||||
|
||||
class Modem {
|
||||
private final nativ:cc.periphs.Modem.Modem;
|
||||
import kernel.net.Package;
|
||||
import kernel.net.INetworkInterface;
|
||||
|
||||
class Modem implements INetworkInterface implements IPeripheral {
|
||||
public final addr:String;
|
||||
public var onMessage(default, null):Signal<Package>;
|
||||
|
||||
private final onMessageTrigger:SignalTrigger<Package> = Signal.trigger();
|
||||
private final native:cc.periphs.Modem.Modem;
|
||||
|
||||
@:allow(kernel.peripherals)
|
||||
private function new(nativePeripherals:cc.periphs.Modem.Modem, addr:String) {
|
||||
this.nativ = nativePeripherals;
|
||||
this.onMessage = onMessageTrigger.asSignal();
|
||||
this.native = nativePeripherals;
|
||||
this.addr = addr;
|
||||
|
||||
KernelEvents.instance.onModemMessage.handle(params ->{
|
||||
if (params.addr == this.addr){
|
||||
var pack:Package = {
|
||||
fromID: params.replyChannel,
|
||||
toID: params.channel,
|
||||
msgID: params.message.msgID,
|
||||
type: params.message.type,
|
||||
data: params.message.data,
|
||||
};
|
||||
|
||||
this.onMessageTrigger.trigger(pack);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function open(chan:Int) {
|
||||
nativ.open(chan);
|
||||
public function listen(chan:Int) {
|
||||
native.open(chan);
|
||||
}
|
||||
|
||||
public function isOpen(chan:Int):Bool {
|
||||
return nativ.isOpen(chan);
|
||||
public function isListening(chan:Int):Bool {
|
||||
return native.isOpen(chan);
|
||||
}
|
||||
|
||||
public function closeAll() {
|
||||
native.closeAll();
|
||||
}
|
||||
|
||||
public function send(chan:Int, replyChan:Int, payload:Any) {
|
||||
native.transmit(chan, replyChan, payload);
|
||||
}
|
||||
|
||||
public function name():String {
|
||||
return addr;
|
||||
}
|
||||
|
||||
public function close(chan:Int) {
|
||||
nativ.close(chan);
|
||||
native.close(chan);
|
||||
}
|
||||
|
||||
public function closAll() {
|
||||
nativ.closeAll();
|
||||
public function getAddr():String {
|
||||
return this.addr;
|
||||
}
|
||||
|
||||
public function transmit(chan:Int, replyChan:Int, payload:Any) {
|
||||
nativ.transmit(chan, replyChan, payload);
|
||||
}
|
||||
|
||||
public function isWireless():Bool {
|
||||
return nativ.isWireless();
|
||||
}
|
||||
|
||||
public function getNamesRemote():Array<String> {
|
||||
if (isWireless()) {
|
||||
throw new Exception("'getNamesRemote' only works with wired modems");
|
||||
public function getBaseRoutingCost():Int {
|
||||
if (this.native.isWireless()){
|
||||
return 2; // Prefere messages over cable
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return nativ.getNamesRemote().toArray();
|
||||
}
|
||||
|
||||
public function isPresentRemote(name:String):Bool {
|
||||
if (isWireless()) {
|
||||
throw new Exception("'isPresentRemote' only works with wired modems");
|
||||
}
|
||||
|
||||
return nativ.isPresentRemote(name);
|
||||
}
|
||||
|
||||
public function getTypeRemote(name:String):String {
|
||||
if (isWireless()) {
|
||||
throw new Exception("'getTypeRemote' only works with wired modems");
|
||||
}
|
||||
|
||||
return nativ.getTypeRemote(name);
|
||||
}
|
||||
|
||||
public function hasTypeRemote(name:String, type:String):Bool {
|
||||
if (isWireless()) {
|
||||
throw new Exception("'hasTypeRemote' only works with wired modems");
|
||||
}
|
||||
|
||||
// Missing in upstream API
|
||||
throw new haxe.exceptions.NotImplementedException();
|
||||
// return nativ.hasRemoteType(name,type);
|
||||
}
|
||||
|
||||
public function getMethodsRemote(name:String):Array<String> {
|
||||
if (isWireless()) {
|
||||
throw new Exception("'getMethodsRemote' only works with wired modems");
|
||||
}
|
||||
|
||||
return nativ.getMethodsRemote(name).toArray();
|
||||
}
|
||||
|
||||
public function callRemote(remoteName:String, method:String):Dynamic {
|
||||
if (isWireless()) {
|
||||
throw new Exception("'callRemote' only works with wired modems");
|
||||
}
|
||||
|
||||
// TODO: implment or solve differently
|
||||
throw new haxe.exceptions.NotImplementedException();
|
||||
}
|
||||
|
||||
public function getNameLocal():String {
|
||||
if (isWireless()) {
|
||||
throw new Exception("'getNameLocal' only works with wired modems");
|
||||
}
|
||||
|
||||
return nativ.getNameLocal();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user