54 lines
1.1 KiB
Haxe
54 lines
1.1 KiB
Haxe
package kernel.ps;
|
|
|
|
import kernel.ps.ProcessHandle.HandleConfig;
|
|
|
|
using tink.CoreApi;
|
|
|
|
typedef PID = Int;
|
|
|
|
class ProcessManager {
|
|
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 pid;
|
|
}
|
|
|
|
public static function kill(pid: PID) {
|
|
if (!processList.exists(pid)){
|
|
throw new Error("Process with PID " + pid + " does not exist");
|
|
}
|
|
|
|
var handle = processList.get(pid);
|
|
|
|
handle.close();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public static function listProcesses():Array<PID> {
|
|
return [for (pid in processList.keys()) pid];
|
|
}
|
|
}
|