From 690a82fac06197ea379322e486df1976ce598405 Mon Sep 17 00:00:00 2001 From: Youngsoo Choi Date: Tue, 26 Nov 2019 21:29:54 -0800 Subject: [PATCH] [Service][Global] Add handler of stop-service This adds handler of stop-service. Change-Id: I7c73f9a204844216141edc47ab26e142368ec3d1 Signed-off-by: Youngsoo Choi --- wrt_app/service/main.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/wrt_app/service/main.js b/wrt_app/service/main.js index 9713ffb..19594ce 100755 --- a/wrt_app/service/main.js +++ b/wrt_app/service/main.js @@ -19,12 +19,18 @@ const wrt = require('../browser/wrt'); const vm = require('vm'); const TizenExtension = require('./tizen_extension'); + var sandbox = []; +var sandbox_count = 0; wrt.on('start-service', (event, app_id) => { console.log('start service app : ' + app_id); new TizenExtension(); if (sandbox[app_id] === undefined) { + if (sandbox_count === 0) { + new TizenExtension(); + } + sandbox_count++; const Module = require('module'); sandbox[app_id] = { console: console, @@ -57,13 +63,33 @@ wrt.on('start-service', (event, app_id) => { } if (sandbox[app_id]['started'] === undefined) { sandbox[app_id]['started'] = true; + sandbox[app_id]['stopped'] = undefined; const start_callback_string = 'if (module.exports.onStart !== undefined) { module.exports.onStart(); }'; vm.runInContext(start_callback_string, sandbox[app_id]); } const request_callback_string = 'if (module.exports.onRequest !== undefined) { module.exports.onRequest(); }'; vm.runInContext(request_callback_string, sandbox[app_id]); -}) +}); + +wrt.on('stop-service', (event, app_id) => { + if (sandbox[app_id]['stopped'] === undefined) { + sandbox_count--; + sandbox[app_id]['stopped'] = true; + sandbox[app_id]['started'] = undefined; + const stop_callback_string = 'if (module.exports.onStop !== undefined) { module.exports.onStop(); }'; + vm.runInContext(stop_callback_string, sandbox[app_id]); + for(let key in sandbox[app_id]) { + delete sandbox[app_id][key]; + } + delete sandbox[app_id]; + if (sandbox_count === 0) { + tizen = null; + } + } else { + console.log('The global service has been already stopped.'); + } +}); process.on('exit', (code) => { console.log('Exit with code : ' + code); -}) +}); -- 2.7.4