get local services

This commit is contained in:
Djeeberjr 2023-06-04 16:36:29 +02:00
parent f8b226bae5
commit 2051f486d4
3 changed files with 24 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package bin; package bin;
import kernel.service.ServiceManager;
import kernel.log.Log; import kernel.log.Log;
import kernel.Timer; import kernel.Timer;
import kernel.ps.ProcessHandle; import kernel.ps.ProcessHandle;
@ -11,7 +12,9 @@ class HelloWorldService implements Process {
public function run(handle:ProcessHandle) { public function run(handle:ProcessHandle) {
Log.debug("HelloWorldService started"); Log.debug("HelloWorldService started");
handle.write("Hello World! Started\n"); handle.write("Hello World! Started\n");
this.startTimer(handle); // this.startTimer(handle);
var srv: HelloWorldService = ServiceManager.instance.get("HelloWorldService");
srv.startTimer(handle);
} }
public function startTimer(handle: ProcessHandle) { public function startTimer(handle: ProcessHandle) {

View File

@ -1,16 +1,17 @@
package kernel.service; package kernel.service;
import kernel.ps.Process;
import kernel.ps.ProcessManager; import kernel.ps.ProcessManager;
import kernel.ps.ProcessHandle;
import kernel.binstore.BinStore; import kernel.binstore.BinStore;
using tink.CoreApi; using tink.CoreApi;
class Service { class Service {
private final binName:String; public final binName:String;
private final name:String; public final name:String;
private final args:Array<String>; public final args:Array<String>;
private var pid:PID; public var pid:PID;
public var ps: Process;
@:allow(kernel.service.ServiceManager) @:allow(kernel.service.ServiceManager)
private function new(binName: String,name: String,?args: Array<String> ) { private function new(binName: String,name: String,?args: Array<String> ) {
@ -26,9 +27,9 @@ class Service {
throw new Error('Bin ${this.binName} not found'); throw new Error('Bin ${this.binName} not found');
} }
var ps = Type.createInstance(bin.c,this.args); this.ps = Type.createInstance(bin.c,this.args);
this.pid = ProcessManager.run(ps,{}); this.pid = ProcessManager.run(this.ps,{});
} }
public function stop() { public function stop() {

View File

@ -128,4 +128,16 @@ class ServiceManager {
} }
return running; return running;
} }
public function get(name: String): Null<Dynamic> {
if (!this.services.exists(name)){
return null;
}
// TODO: Maybe there is a way to check types here?
var srv = this.services.get(name);
return srv.ps;
}
} }