From: Marcin Wasowski Date: Fri, 19 Dec 2014 18:36:01 +0000 (+0100) Subject: [TV Display] Fixes for js api X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~502 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=154254462fbd745e3cbebf67c3b2698893dc5f0a;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [TV Display] Fixes for js api - NativeManager helper used - is3DModeEnabled() returns enum now - js implementation of getSupported3DEffectModeList() Change-Id: I0ce69c399f384ea53ec3ed7a13741f48599f84a7 Signed-off-by: Marcin Wasowski --- diff --git a/src/tvdisplay/tvdisplay_api.js b/src/tvdisplay/tvdisplay_api.js index 55761144..3e3048a4 100644 --- a/src/tvdisplay/tvdisplay_api.js +++ b/src/tvdisplay/tvdisplay_api.js @@ -3,128 +3,131 @@ // found in the LICENSE file. /** - * @author Marcin Wasowski (m.wasowski2@samsung.com) + * @author m.wasowski2@samsung.com (Marcin Wasowski) */ function TVDisplay() {} +var native = new xwalk.utils.NativeManager(extension); +var validator = xwalk.utils.validator; +var validatorTypes = xwalk.utils.validator.Types; + var UNKNOWN_ERROR = 'UnknownError'; + +/** + * Allowed values for is3DModeEnabled return value + * @type {Display3DModeState} + */ +var Display3DModeState = { + NOT_CONNECTED: 'NOT_CONNECTED', + NOT_SUPPORTED: 'NOT_SUPPORTED', + READY: 'READY' +}; +Object.freeze(Display3DModeState); + + /** * Check if 3D mode is enabled - * @return {boolean} true if enabled else false + * @return {Display3DModeState} mode String informing if 3D content + * is supported and ready */ TVDisplay.prototype.is3DModeEnabled = function() { - var msg = { - cmd: 'TVDisplay_is3DModeEnabled', - args: {}, - arg: '' - }; - var reply = sendSyncMessage(msg); - if (reply.error) { - throw new tizen.WebAPIException(0, UNKNOWN_ERROR, reply.error); + var ret = native.callSync('TVDisplay_is3DModeEnabled', {}); + if (native.isFailure(ret)) { + throw native.getErrorObject(ret); } - return reply.result; + return native.getResultObject(ret); }; + +/** + * Allowed values for 3D effect modes mapped to return values from C API + * + * OFF - identifier for 3DEffect mode off + * TOP_BOTTOM - Top-bottom: Left at top, right at bottom + * SIDE_BY_SIDE - Top-bottom: Left at left side, right at right side + * LINE_BY_LINE - Line-by-line: Left and right image interlaced by row + * VERTICAL_STRIP - Vertical-strip: Left and right image + * interlaced by column + * FRAME_SEQUENCE - Left and right image interlaced by frame + * CHECKER_BD - Checkerboard (only for PC or game console sources) + * FROM_2D_TO_3D - Left and right image computed from + * No-stereoscopic image +*/ +var Display3DEffectMode = [ + 'OFF', + 'TOP_BOTTOM', + 'SIDE_BY_SIDE', + 'LINE_BY_LINE', + 'VERTICAL_STRIPE', + 'FRAME_SEQUENCE', + 'CHECKER_BD', + 'FROM_2D_TO_3D' +]; +Object.freeze(Display3DEffectMode); + + /** * Get current 3D effect mode or 'OFF' if no 3D enabled * @return {string} current mode name */ TVDisplay.prototype.get3DEffectMode = function() { - var msg = { - cmd: 'TVDisplay_get3DEffectMode', // returns index - args: {}, - arg: '' - }; - var reply = sendSyncMessage(msg); - if (reply.error) { - throw new tizen.WebAPIException(0, reply.error, UNKNOWN_ERROR); + var ret = native.callSync('TVDisplay_get3DEffectMode', {}); + if (native.isFailure(ret)) { + throw native.getErrorObject(ret); } - var mode = Display3DEffectMode[reply.result]; + var mode = Display3DEffectMode[native.getResultObject(ret)]; if (!mode) { - throw new tizen.WebAPIException( - 0, - 'Unknown 3D effect mode (' + reply.result + ')', - UNKNOWN_ERROR); + var error_msg = 'Unknown 3D effect mode (' + reply.result + ')'; + throw new tizen.WebAPIException(0, error_msg, UNKNOWN_ERROR); } return mode; }; + /** * Get list of supported 3D effects * * @param {!Mode3DEffectListSupportCallback} successCallback * @param {?ErrorCallback} errorCallback - * @return {Display3DEffectMode[]} mode3DEffects */ -TVDisplay.prototype.getSupported3DEffectModeList = -function(successCallback, errorCallback) { +TVDisplay.prototype.getSupported3DEffectModeList = function( + successCallback, + errorCallback) { - - var Types = xwalk.utils.validator.Types; var successCallback = { name: 'successCallback', - type: Types.FUNCTION, + type: validatorTypes.FUNCTION, optional: false, nullable: false }; var errorCallback = { name: 'errorCallback', - type: Types.FUNCTION, + type: validatorTypes.FUNCTION, optional: true, - nullable: false + nullable: true }; - var msg = { - cmd: 'TVDisplay_getSupported3DEffectModeList', - args: {}, - arg: {} // TODO: here callback id should be passed - }; - - var args = xwalk.utils.validator.validateArgs( + var args = validator.validateArgs( arguments, [successCallback, errorCallback]); - return sendSyncMessage(msg); // undefined -}; -function sendSyncMessage(msg) { - var serialized = null; - serialized = JSON.stringify(msg); - return JSON.parse(extension.internal.sendSyncMessage(serialized)); -} - -/** - * Allowed values for 3D effect modes mapped to return values from C API - * - * OFF - identifier for 3DEffect mode off - * TOP_BOTTOM - Top-bottom: Left at top, right at bottom - * SIDE_BY_SIDE - Top-bottom: Left at left side, right at right side - * LINE_BY_LINE - Line-by-line: Left and right image interlaced by row - * VERTICAL_STRIP - Vertical-strip: Left and right image - * interlaced by column - * FRAME_SEQUENCE - Left and right image interlaced by frame - * CHECKER_BD - Checkerboard (only for PC or game console sources) - * FROM_2D_TO_3D - Left and right image computed from - * No-stereoscopic image -*/ -var Display3DEffectMode = [ - 'OFF', - 'TOP_BOTTOM', - 'SIDE_BY_SIDE', - 'LINE_BY_LINE', - 'VERTICAL_STRIPE', - 'FRAME_SEQUENCE', - 'CHECKER_BD', - 'FROM_2D_TO_3D' -]; -Object.freeze(Display3DEffectMode); + native.call( + 'TVDisplay_getSupported3DEffectModeList', + {}, + function(msg) { + if (msg && !msg.error) { + args.successCallback(msg.result); + } else if (msg && validatorTypes.isFunction(args.errorCallback)) { + args.errorCallback(native.getErrorObject(msg.error)); + } else { + return; + } + } + ); -var Display3DModeState = { - NOT_CONNECTED: 'NOT_CONNECTED', - NOT_SUPPORTED: 'NOT_SUPPORTED', - READY: 'READY' }; -Object.freeze(Display3DModeState); + exports = new TVDisplay(); diff --git a/src/tvdisplay/tvdisplay_instance.cc b/src/tvdisplay/tvdisplay_instance.cc index 299c4241..860a4df1 100644 --- a/src/tvdisplay/tvdisplay_instance.cc +++ b/src/tvdisplay/tvdisplay_instance.cc @@ -48,11 +48,6 @@ TVDisplayInstance::TVDisplayInstance() { TVDisplayInstance::~TVDisplayInstance() {} -// TVDisplayInstance* getInstance() { -// static TVDisplayInstance instance; -// return &instance; -// } - void TVDisplayInstance::Is3DModeEnabled( const picojson::value& value, picojson::object& out) { @@ -60,19 +55,20 @@ void TVDisplayInstance::Is3DModeEnabled( bool is_supported = true; picojson::value::object o; - // auto intance = getInstance(); - - int result = system_info_get_value_bool( + int ret = system_info_get_value_bool( SYSTEM_INFO_KEY_3D_EFFECT_SUPPORTED, &is_supported); - if (SYSTEM_INFO_ERROR_NONE != result) { + + if (SYSTEM_INFO_ERROR_NONE != ret) { std::string err = "'system_info' error while getting 3d mode details: " - + std::to_string(result); + + std::to_string(ret); LoggerE("%s", err.c_str()); ReportError(common::UnknownException(err), out); } - ReportSuccess(picojson::value(is_supported), out); + std::string mode = is_supported ? "READY" : "NOT_SUPPORTED"; + LoggerD("3D Mode is: %s", mode.c_str()); + ReportSuccess(picojson::value(mode), out); } void TVDisplayInstance::Get3DEffectMode(