[Service][VD] Apply main thread with standalone model 90/246990/6 accepted/tizen/6.0/unified/20201110.010759 submit/tizen_6.0/20201109.073041 submit/tizen_6.0/20201109.093913
authorDongHyun Song <dh81.song@samsung.com>
Fri, 6 Nov 2020 00:39:03 +0000 (09:39 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Mon, 9 Nov 2020 01:48:47 +0000 (01:48 +0000)
With standalone model of service application, this patch will apply
main thread service_runner to solve crash problems of node worker.

Change-Id: I5fb69368a4bae36ac11d465200b2cd0a42e6c3a1
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt_app/common/service_manager.ts

index 757688b..14f0a87 100644 (file)
@@ -5,14 +5,15 @@ interface WorkerMap {
   [id: string]: any;
 }
 let workers: WorkerMap = {};
+let runner: any;
 
 Object.defineProperty(global, 'serviceType', {
   value: wrt.getServiceModel(),
   writable: false
 });
 
-function isServiceApplication() {
-  return global['serviceType'] !== 'UI';
+function isStandalone() {
+  return global['serviceType'] === 'STANDALONE';
 }
 
 function createWorker(id: string, startService: string, filename: string) {
@@ -48,13 +49,26 @@ function terminateWorker(id: string, delay: number) {
 
 export function startService(id: string, filename: string) {
   console.log(`startService - ${id}`);
-  let startService = `${__dirname}/service_runner.js`;
-  createWorker(id, startService, filename);
+  if (isStandalone()) {
+    runner = require('../common/service_runner');
+    runner.start(id, filename);
+  } else {
+    let startService = `${__dirname}/service_runner.js`;
+    createWorker(id, startService, filename);
+  }
 }
 
 export function stopService(id: string) {
   console.log(`stopService - ${id}`);
-  terminateWorker(id, 500);
+  if (isStandalone()) {
+    if (!runner) {
+      console.log('runner instance is null in standalone mode');
+      return;
+    }
+    runner.stop(id);
+  } else {
+    terminateWorker(id, 500);
+  }
 }
 
 export function handleBuiltinService(serviceId: string, serviceName: string) {