Merge "Revert "[Service] Apply node worker for standalone model"" into tizen
authorBot Blink <blinkbot@samsung.com>
Tue, 13 Oct 2020 08:44:20 +0000 (08:44 +0000)
committerGerrit Code Review <gerrit@review>
Tue, 13 Oct 2020 08:44:20 +0000 (08:44 +0000)
wrt_app/common/service_manager.ts
wrt_app/service/main.ts

index c4b2940..3038364 100644 (file)
@@ -5,11 +5,16 @@ interface WorkerMap {
   [id: string]: any;
 }
 let workers: WorkerMap = {};
+let runner: any;
 
 global.serviceType = wrt.getServiceModel();
 
-function isServiceApplication() {
-  return global.serviceType !== 'UI';
+function isStandalone() {
+  return global.serviceType === 'STANDALONE';
+}
+
+function isGlobalService() {
+  return global.serviceType === 'DAEMON';
 }
 
 function createWorker(id: string, startService: string, filename: string) {
@@ -32,7 +37,7 @@ function terminateWorker(id: string, delay: number) {
     delete workers[id];
     let runningServices = Object.keys(workers).length;
     console.log('Running services : ' + runningServices);
-    if (runningServices === 0 && isServiceApplication()) {
+    if (runningServices === 0 && isGlobalService()) {
       process.exit();
     }
   }
@@ -41,15 +46,29 @@ function terminateWorker(id: string, delay: number) {
 
 export function startService(id: string, filename: string) {
   console.log(`startService - ${id}`);
-  if (isMainThread) {
-    let startService = `${__dirname}/service_runner.js`;
-    createWorker(id, startService, filename);
+  if (isStandalone()) {
+    runner = require('../common/service_runner');
+    runner.start(id, filename);
+  } else {
+    if (isMainThread) {
+      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);
+    setTimeout(() => process.exit(), 500);
+  } else {
+    terminateWorker(id, 500);
+  }
 }
 
 export function handleBuiltinService(serviceId: string, serviceName: string) {
index c64591e..b0c371a 100755 (executable)
@@ -27,6 +27,9 @@ wrt.on('start-service', (event: any, internal_id: string) => {
 
 wrt.on('stop-service', (event: any, internal_id: string) => {
   ServiceManager.stopService(internal_id);
+  if (wrt.getServiceModel() === 'STANDALONE') {
+    setTimeout(() => {process.exit()}, 10);
+  }
 });
 
 wrt.on('builtin-service', (event: any, internal_id: string, service_name: string) => {