[Service][Builtin] Stop function of wasm-builder 09/237009/12
authorDongHyun Song <dh81.song@samsung.com>
Mon, 6 Jul 2020 02:23:40 +0000 (11:23 +0900)
committerSangYong Park <sy302.park@samsung.com>
Fri, 10 Jul 2020 01:47:36 +0000 (01:47 +0000)
wasm-builder builtin service is starting when an application, which has
'wasm.caching.support' metadata, is installed. But if a user try to
launch the application as soon as its installation done, both wasm cache
buillding of builtin service and UI application are able to overlap by
its wasm compiling time.
Thus, builtin service has to be stopped when UI application is starting.

Related chromium-efl patch:
  https://review.tizen.org/gerrit/237014/

Change-Id: Ieff3fcf529cc3f2b72ad5d921d16cee6b278092c
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt_app/service/builtins/builtin_handler.ts [new file with mode: 0644]
wrt_app/service/builtins/wasm_builder.ts
wrt_app/service/main.ts

diff --git a/wrt_app/service/builtins/builtin_handler.ts b/wrt_app/service/builtins/builtin_handler.ts
new file mode 100644 (file)
index 0000000..de9c8a8
--- /dev/null
@@ -0,0 +1,30 @@
+import * as vm from 'vm';
+
+let sandbox: vm.Context = {
+  console: console,
+  require: require,
+  services: {}
+};
+
+export function handleService(service_name: string, service_id: string) {
+  if (!service_name)
+    return;
+
+  let need_stop = (service_name.substr(0, 5) === 'stop_');
+  if (need_stop) {
+    service_name = service_name.substr(5);
+  }
+  let builtin_service = `./${service_name}.js`;
+  console.log(`Builtin service is ${builtin_service}`);
+  let options = {
+    filename: service_id,
+  };
+  if (need_stop) {
+    let code = `services['${service_id}'].stop('${service_id}')`;
+    vm.runInContext(code, sandbox);
+  } else {
+    let code = `services['${service_id}'] = require('${builtin_service}');`;
+    code += `services['${service_id}'].run('${service_id}')`;
+    vm.runInNewContext(code, sandbox, options);
+  }
+}
\ No newline at end of file
index 2403ee3..b61ed86 100644 (file)
@@ -17,9 +17,15 @@ export function run(app_id: string) {
   let tv = wrt.tv as NativeWRTjs.TVExtension;
   tv.setWasmFlags();
   tv.setDiskCache(app_id);
+  tv.delayShutdown();
   let files = tv.getWasmFiles(app_id);
   console.log(files);
-  files.forEach((file_path) => {
+  files.forEach((file_path: string) => {
     compileWasmForCaching(file_path);
   });
 }
+
+export function stop(app_id: string) {
+  // TODO, stop caching will be implemented here
+  console.log(`wasm_builder.js suspended, app_id:(${app_id})`);
+}
\ No newline at end of file
index 7d3ff1a..26cf56f 100755 (executable)
 import '../common/init';
 import { wrt } from '../browser/wrt';
 import * as ServiceManager from '../common/service_manager';
+import * as BuiltinService from './builtins/builtin_handler';
 
-wrt.on('start-service', (event, internal_id) => {
+wrt.on('start-service', (event: any, internal_id: string) => {
   console.log('start service app : ' + internal_id);
   ServiceManager.startService(internal_id);
 });
 
-wrt.on('stop-service', (event, internal_id) => {
+wrt.on('stop-service', (event: any, internal_id: string) => {
   ServiceManager.stopService(internal_id);
   if (wrt.getServiceModel() == "STANDALONE")
     process.exit();
 });
 
-wrt.on('builtin-service', (event, internal_id, service_name) => {
-    console.log(`service_name: ${service_name}`);
-    const vm = require('vm');
-    let builtin_service = '';
-    if (service_name === 'wasm_builder') {
-      builtin_service = './builtins/wasm_builder.js';
-    }
-    if (builtin_service) {
-      console.log(`Builtin service is ${builtin_service}`);
-      let sandbox = {
-          console: console,
-          require: require,
-      };
-      let options = {
-        filename: internal_id,
-      };
-      let code = `require('${builtin_service}').run('${internal_id}')`;
-      vm.runInNewContext(code, sandbox, options);
-    }
+wrt.on('builtin-service', (event: any, internal_id: string, service_name: string) => {
+  console.log(`service_name: ${service_name}`);
+  BuiltinService.handleService(service_name, internal_id);
 });
 
-wrt.on('quit', (event) => {
-    process.exit();
+wrt.on('quit', (event: any) => {
+  process.exit();
 });
 
 process.on('exit', (code) => {