From fefed5b84edc7fbe3800642a1ca79ed450d28b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 21 Feb 2018 15:00:10 +0100 Subject: [PATCH] Implement first version of ProcessManagerService --- src/app/services/processcommand.ts | 3 ++ src/app/services/processmanager.service.ts | 41 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/app/services/processcommand.ts create mode 100644 src/app/services/processmanager.service.ts diff --git a/src/app/services/processcommand.ts b/src/app/services/processcommand.ts new file mode 100644 index 0000000..9b6d711 --- /dev/null +++ b/src/app/services/processcommand.ts @@ -0,0 +1,3 @@ +export class ProcessCommand { + command: string; +} diff --git a/src/app/services/processmanager.service.ts b/src/app/services/processmanager.service.ts new file mode 100644 index 0000000..092a7ac --- /dev/null +++ b/src/app/services/processmanager.service.ts @@ -0,0 +1,41 @@ +import { Injectable } from '@angular/core'; + +import { WebSocketService } from './websocket.service'; +import { ProcessCommand } from './processcommand'; + + +@Injectable() +export class ProcessManagerService { + anchor = 'anchor_processmanager'; + process_name: string; + + constructor(private webSocketService: WebSocketService) {} + + init(process_name: string) { + this.process_name = process_name; + this.webSocketService.connect(); + } + + subscribeCallback(callback: (event: any) => void) { + this.webSocketService.observeAnchor(this.anchor).subscribe(callback); + } + + sendCommand(command: string, callback?: (event: any) => void) { + if (callback) { + this.subscribeCallback(callback); + } + this.webSocketService.send(this.anchor, {'command': command}); + } + + startProcess(callback?: (event: any) => void) { + this.sendCommand('start', callback); + } + + stopProcess(callback?: (event: any) => void) { + this.sendCommand('stop', callback); + } + + restartProcess(callback?: (event: any) => void) { + this.sendCommand('restart', callback); + } +}