cc-haxe/src/kernel/peripherals/Modem.hx
2022-02-21 15:35:37 +01:00

102 lines
2.3 KiB
Haxe

package kernel.peripherals;
import haxe.exceptions.NotImplementedException;
import haxe.Exception;
using lua.Table;
class Modem {
private final nativ:cc.periphs.Modem.Modem;
public final addr:String;
@:allow(kernel.peripherals)
private function new(nativePeripherals:cc.periphs.Modem.Modem, addr:String) {
this.nativ = nativePeripherals;
this.addr = addr;
}
public function open(chan:Int) {
nativ.open(chan);
}
public function isOpen(chan:Int):Bool {
return nativ.isOpen(chan);
}
public function close(chan:Int) {
nativ.close(chan);
}
public function closAll() {
nativ.closeAll();
}
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");
}
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();
}
}