added shutdown
This commit is contained in:
parent
f8f5f5e5c7
commit
14f7b6c6df
@ -13,6 +13,10 @@ import kernel.peripherals.Peripherals.Peripheral;
|
|||||||
import kernel.net.Net;
|
import kernel.net.Net;
|
||||||
|
|
||||||
class Init {
|
class Init {
|
||||||
|
|
||||||
|
@:allow(kernel.KernelEvents)
|
||||||
|
private static var mainEvent:MainEvent;
|
||||||
|
|
||||||
public static function initKernel() {
|
public static function initKernel() {
|
||||||
// Init singeltons here because haxe is confused about the order to create them.
|
// Init singeltons here because haxe is confused about the order to create them.
|
||||||
Log.instance = new Log();
|
Log.instance = new Log();
|
||||||
@ -44,9 +48,8 @@ class Init {
|
|||||||
FS.makeDir("/var/ns");
|
FS.makeDir("/var/ns");
|
||||||
}
|
}
|
||||||
|
|
||||||
MainLoop.add(()->{
|
Init.mainEvent = MainLoop.add(()->{
|
||||||
KernelEvents.instance.startEventLoop();
|
KernelEvents.instance.startEventLoop();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package kernel;
|
package kernel;
|
||||||
|
|
||||||
|
import haxe.MainLoop;
|
||||||
|
import cc.OS;
|
||||||
import kernel.log.Log;
|
import kernel.log.Log;
|
||||||
import lib.Pos;
|
import lib.Pos;
|
||||||
import cc.HTTP.HTTPResponse;
|
import cc.HTTP.HTTPResponse;
|
||||||
import lua.TableTools;
|
import lua.TableTools;
|
||||||
import lua.Coroutine;
|
import lua.Coroutine;
|
||||||
import lib.Vec.Vec2;
|
|
||||||
import haxe.Exception;
|
import haxe.Exception;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
@ -95,6 +96,8 @@ class KernelEvents {
|
|||||||
private final onWebsocketMessageTrigger:SignalTrigger<{url:String, message:String, isBinary:Bool}> = Signal.trigger();
|
private final onWebsocketMessageTrigger:SignalTrigger<{url:String, message:String, isBinary:Bool}> = Signal.trigger();
|
||||||
private final onWebsocketSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
|
private final onWebsocketSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
|
||||||
|
|
||||||
|
private var stopLoop:Bool = false;
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private function new() {
|
private function new() {
|
||||||
this.onAlarm = onAlarmTrigger.asSignal();
|
this.onAlarm = onAlarmTrigger.asSignal();
|
||||||
@ -132,16 +135,27 @@ class KernelEvents {
|
|||||||
/**
|
/**
|
||||||
Start pulling events. Blocking.
|
Start pulling events. Blocking.
|
||||||
**/
|
**/
|
||||||
public function startEventLoop() {
|
@:allow(kernel.Init)
|
||||||
while (true) {
|
private function startEventLoop() {
|
||||||
|
while (!stopLoop) {
|
||||||
var event:Table<Int, Dynamic> = pullEvents();
|
var event:Table<Int, Dynamic> = pullEvents();
|
||||||
|
|
||||||
var eventName:String = event[1];
|
var eventName:String = event[1];
|
||||||
|
try {
|
||||||
fireSignal(eventName,event);
|
fireSignal(eventName,event);
|
||||||
|
}catch(e:Dynamic) {
|
||||||
|
Log.error('Error while handling event: $eventName: ${e}');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function shutdown() {
|
||||||
|
Log.info('Shutting down event loop');
|
||||||
|
this.stopLoop = true;
|
||||||
|
MainTerm.instance.reset();
|
||||||
|
Init.mainEvent.stop();
|
||||||
|
}
|
||||||
|
|
||||||
private function pullEvents():Table<Int, Dynamic> {
|
private function pullEvents():Table<Int, Dynamic> {
|
||||||
return cast TableTools.pack(Coroutine.yield(null));
|
return cast TableTools.pack(Coroutine.yield(null));
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,7 @@ class HomeContext {
|
|||||||
|
|
||||||
children.push(new TextElement('Add Terminal', {onClick: this.addTerminal}));
|
children.push(new TextElement('Add Terminal', {onClick: this.addTerminal}));
|
||||||
children.push(new TextElement('Add Log', {onClick: this.addLog}));
|
children.push(new TextElement('Add Log', {onClick: this.addLog}));
|
||||||
|
children.push(new TextElement('Exit', {onClick: KernelEvents.instance.shutdown}));
|
||||||
|
|
||||||
renderer.setChildren(children);
|
renderer.setChildren(children);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user