added windowContext to ProcessHandle
This commit is contained in:
parent
17be4149db
commit
2da337b8a9
@ -1,5 +1,8 @@
|
||||
package kernel.ps;
|
||||
|
||||
import kernel.ps.ProcessManager.PID;
|
||||
import kernel.ui.WindowContext;
|
||||
import kernel.ui.WindowManager;
|
||||
import haxe.ds.ReadOnlyArray;
|
||||
using tink.CoreApi;
|
||||
|
||||
@ -12,13 +15,17 @@ typedef HandleConfig = {
|
||||
class ProcessHandle {
|
||||
public var args(get,null): ReadOnlyArray<String>;
|
||||
|
||||
private final pid: PID;
|
||||
private final config:HandleConfig;
|
||||
private final closeFuture: Future<Bool>;
|
||||
private var closeFutureResolev: Bool -> Void;
|
||||
private final windowContexts: Array<WindowContext> = [];
|
||||
|
||||
@:allow(kernel.ps.ProcessManager)
|
||||
private function new(config: HandleConfig) {
|
||||
private function new(config: HandleConfig,pid: PID) {
|
||||
this.config = config;
|
||||
this.pid = pid;
|
||||
|
||||
this.closeFuture = new Future<Bool>((trigger)->{
|
||||
this.closeFutureResolev = trigger;
|
||||
return null;
|
||||
@ -27,6 +34,8 @@ class ProcessHandle {
|
||||
if (this.config.onExit != null) {
|
||||
this.closeFuture.handle(this.config.onExit);
|
||||
}
|
||||
|
||||
this.closeFuture.eager();
|
||||
}
|
||||
|
||||
public function onExit(): Future<Bool> {
|
||||
@ -36,6 +45,7 @@ class ProcessHandle {
|
||||
public function close(success: Bool = true): Void {
|
||||
this.dispose();
|
||||
this.closeFutureResolev(success);
|
||||
ProcessManager.removeProcess(this.pid);
|
||||
}
|
||||
|
||||
public function write(message: String): Void {
|
||||
@ -46,6 +56,22 @@ class ProcessHandle {
|
||||
this.write(message + "\n");
|
||||
}
|
||||
|
||||
public function createBufferdWindowContext(): WindowContext {
|
||||
var ctx = WindowManager.instance.createNewContext();
|
||||
this.windowContexts.push(ctx);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public function createStatelessWindowContext(): {ctx:WindowContext, setRenderFunc: (() -> Void) -> Void, requestRender:() -> Void} {
|
||||
var ctx = WindowManager.instance.createNewStatelessContext();
|
||||
this.windowContexts.push(ctx.ctx);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public function getWindowContexts(): ReadOnlyArray<WindowContext> {
|
||||
return this.windowContexts;
|
||||
}
|
||||
|
||||
private function dispose() {
|
||||
// TODO
|
||||
}
|
||||
|
@ -2,10 +2,36 @@ package kernel.ps;
|
||||
|
||||
import kernel.ps.ProcessHandle.HandleConfig;
|
||||
|
||||
typedef PID = Int;
|
||||
|
||||
class ProcessManager {
|
||||
public static function run(process:Process, config: HandleConfig):ProcessHandle {
|
||||
var handle = new ProcessHandle(config);
|
||||
private static final processList = new Map<PID,ProcessHandle>();
|
||||
|
||||
public static function run(process:Process, config: HandleConfig):PID {
|
||||
var pid = createPID();
|
||||
var handle = new ProcessHandle(config, pid);
|
||||
|
||||
processList.set(pid, handle);
|
||||
|
||||
process.run(handle);
|
||||
return handle;
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
private static function createPID(): PID {
|
||||
// TODO: better PID generation
|
||||
|
||||
// generate a random PID
|
||||
return Math.ceil(Math.random() * 1000000);
|
||||
}
|
||||
|
||||
@:allow(kernel.ui.WindowManager)
|
||||
private static function getProcess(pid:PID):Null<ProcessHandle>{
|
||||
return processList.get(pid);
|
||||
}
|
||||
|
||||
@:allow(kernel.ps.ProcessHandle)
|
||||
private static function removeProcess(pid:PID):Void {
|
||||
processList.remove(pid);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package kernel.ui;
|
||||
|
||||
import kernel.ps.ProcessManager;
|
||||
import kernel.ps.ProcessManager.PID;
|
||||
import haxe.ds.ReadOnlyArray;
|
||||
import kernel.ui.TermWriteable;
|
||||
import kernel.peripherals.Peripherals.Peripheral;
|
||||
@ -162,4 +164,13 @@ class WindowManager {
|
||||
context.setTarget(target);
|
||||
context.enable();
|
||||
}
|
||||
|
||||
public function getContextByPID(pid: PID): ReadOnlyArray<WindowContext> {
|
||||
var handle = ProcessManager.getProcess(pid);
|
||||
if (handle == null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return handle.getWindowContexts();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user