From: Arkadiusz Pietraszek Date: Fri, 12 Jul 2019 11:47:35 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/tizen_3.0' into tizen_4.0 X-Git-Tag: submit/tizen/20190805.070446~4^2^2^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2409e3ebef547fb7217863db448d09beb4ddcc83;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git Merge remote-tracking branch 'origin/tizen_3.0' into tizen_4.0 [Verification] TCT passrate 100%. Signed-off-by: Arkadiusz Pietraszek Change-Id: Id004158e62f5d0b6f2c09eeee5cf300d461a9d9f --- 2409e3ebef547fb7217863db448d09beb4ddcc83 diff --cc src/alarm/alarm_api.js index 089f6a3f,e7692a45..eb668868 --- a/src/alarm/alarm_api.js +++ b/src/alarm/alarm_api.js @@@ -21,14 -21,12 +21,14 @@@ var privUtils_ = xwalk.utils var native = new xwalk.utils.NativeManager(extension); +var isAlarmAbsolutePeriodDeprecated = true; + - var AlarmManager = function () { + var AlarmManager = function() { Object.defineProperties(this, { - PERIOD_MINUTE: { value: 60, writable: false, enumerable: true}, - PERIOD_HOUR: { value: 3600, writable: false, enumerable: true}, - PERIOD_DAY: { value: 86400, writable: false, enumerable: true}, - PERIOD_WEEK: { value: 604800, writable: false, enumerable: true}, + PERIOD_MINUTE: { value: 60, writable: false, enumerable: true }, + PERIOD_HOUR: { value: 3600, writable: false, enumerable: true }, + PERIOD_DAY: { value: 86400, writable: false, enumerable: true }, + PERIOD_WEEK: { value: 604800, writable: false, enumerable: true } }); }; @@@ -68,42 -66,29 +68,43 @@@ function UpdateInternalData_(internal, } } +var LogManager = function() { + this.enableLog = true; +}; + +LogManager.prototype.allow = function() { + this.enableLog = true; +}; + +LogManager.prototype.disallow = function() { + this.enableLog = false; +}; + +var _warningLogs = new LogManager(); + //class AlarmManager //////////////////////////////////////////////////// - AlarmManager.prototype.add = function () { + AlarmManager.prototype.add = function() { var args = AV.validateMethod(arguments, [ { - name : 'alarm', - type : AV.Types.PLATFORM_OBJECT, - values : [tizen.AlarmRelative, tizen.AlarmAbsolute] + name: 'alarm', + type: AV.Types.PLATFORM_OBJECT, + values: [tizen.AlarmRelative, tizen.AlarmAbsolute] }, { - name : 'applicationId', - type : AV.Types.STRING, + name: 'applicationId', + type: AV.Types.STRING }, { - name : 'appControl', - type : AV.Types.PLATFORM_OBJECT, - values : tizen.ApplicationControl, - optional : true, - nullable : true - }, + name: 'appControl', + type: AV.Types.PLATFORM_OBJECT, + values: tizen.ApplicationControl, + optional: true, + nullable: true + } ]); - var type = null, seconds = 0; + var type = null, + seconds = 0; if (args.alarm instanceof tizen.AlarmRelative) { type = 'AlarmRelative'; } else if (args.alarm instanceof tizen.AlarmAbsolute) { @@@ -132,52 -117,11 +133,54 @@@ } }; +AlarmManager.prototype.addAlarmNotification = function() { + var args = AV.validateMethod(arguments, [ - { - name: 'alarm', - type: AV.Types.PLATFORM_OBJECT, - values: [tizen.AlarmRelative, tizen.AlarmAbsolute] - }, { - name: 'notification', - type: AV.Types.PLATFORM_OBJECT, - values: [tizen.StatusNotification, tizen.UserNotification] - }]); - - var type = null, milliseconds = 0; ++ { ++ name: 'alarm', ++ type: AV.Types.PLATFORM_OBJECT, ++ values: [tizen.AlarmRelative, tizen.AlarmAbsolute] ++ }, ++ { ++ name: 'notification', ++ type: AV.Types.PLATFORM_OBJECT, ++ values: [tizen.StatusNotification, tizen.UserNotification] ++ } ++ ]); ++ ++ var type = null, ++ milliseconds = 0; + if (args.alarm instanceof tizen.AlarmRelative) { + type = 'AlarmRelative'; + } else if (args.alarm instanceof tizen.AlarmAbsolute) { + type = 'AlarmAbsolute'; + milliseconds = args.alarm.date.getTime(); + } + + var callArgs = {}; + callArgs.alarm = args.alarm; + callArgs.type = type; + callArgs.notification = args.notification; + callArgs.milliseconds = Converter.toString(milliseconds); + callArgs.isPeriodSet = !T.isNullOrUndefined(args.alarm.period); + + //add marker for UserNotification implementation - callArgs.newImpl = (callArgs.notification instanceof tizen.UserNotification); ++ callArgs.newImpl = callArgs.notification instanceof tizen.UserNotification; + + var result = native.callSync('AlarmManager_addAlarmNotification', callArgs); + if (native.isFailure(result)) { + throw native.getErrorObject(result); - } - else { ++ } else { + _edit.allow(); + UpdateInternalData_(args.alarm, native.getResultObject(result)); + _edit.disallow(); + } +}; + - AlarmManager.prototype.remove = function () { + AlarmManager.prototype.remove = function() { var args = AV.validateMethod(arguments, [ { - name : 'id', - type : AV.Types.STRING, + name: 'id', + type: AV.Types.STRING } ]); @@@ -210,71 -154,24 +213,88 @@@ AlarmManager.prototype.get = function( throw native.getErrorObject(result); } else { result = native.getResultObject(result); + + var alarm; + _warningLogs.disallow(); if ('AlarmRelative' === result.type) { - alarm = new tizen.AlarmRelative(result.delay, result.period, InternalData_(result)); - return new tizen.AlarmRelative( ++ alarm = new tizen.AlarmRelative( + result.delay, + result.period, + InternalData_(result) + ); } else { - var date = new Date(result.year, result.month, result.day, - result.hour, result.min, result.sec); + var date = new Date( + result.year, + result.month, + result.day, + result.hour, + result.min, + result.sec + ); - return new tizen.AlarmAbsolute(date, result.second, InternalData_(result)); + alarm = new tizen.AlarmAbsolute(date, result.second, InternalData_(result)); } + _warningLogs.allow(); + return alarm; + } +}; + +function _prepareAppControl(noti) { - if (!noti || !noti.actions || !noti.actions.appControl) { - privUtils_.log("Do nothing - appControl is NOT present"); - return; - } - if (!T.isNullOrUndefined(noti.actions.appControl.operation)) { - noti.actions.appControl = new tizen.ApplicationControl( - noti.actions.appControl.operation, - noti.actions.appControl.uri, - noti.actions.appControl.mime, - noti.actions.appControl.category, - noti.actions.appControl.data, - noti.actions.appControl.launchMode); - } ++ if (!noti || !noti.actions || !noti.actions.appControl) { ++ privUtils_.log('Do nothing - appControl is NOT present'); ++ return; ++ } ++ if (!T.isNullOrUndefined(noti.actions.appControl.operation)) { ++ noti.actions.appControl = new tizen.ApplicationControl( ++ noti.actions.appControl.operation, ++ noti.actions.appControl.uri, ++ noti.actions.appControl.mime, ++ noti.actions.appControl.category, ++ noti.actions.appControl.data, ++ noti.actions.appControl.launchMode ++ ); ++ } +} + +function _prepareDetailInfo(noti) { - if (!noti || !noti.textContents || !noti.textContents.detailInfo) { - console.log("Do nothing - detailInfo is NOT present"); - return; - } - var detailInfo = noti.textContents.detailInfo; - if (T.isArray(detailInfo)) { - var _d = []; - for (var i = 0; i < detailInfo.length; ++i) { - _d.push(new tizen.NotificationDetailInfo(detailInfo[i].mainText, - detailInfo[i].subText || null)); ++ if (!noti || !noti.textContents || !noti.textContents.detailInfo) { ++ console.log('Do nothing - detailInfo is NOT present'); ++ return; ++ } ++ var detailInfo = noti.textContents.detailInfo; ++ if (T.isArray(detailInfo)) { ++ var _d = []; ++ for (var i = 0; i < detailInfo.length; ++i) { ++ _d.push( ++ new tizen.NotificationDetailInfo( ++ detailInfo[i].mainText, ++ detailInfo[i].subText || null ++ ) ++ ); ++ } ++ noti.textContents.detailInfo = _d; + } - noti.textContents.detailInfo = _d; - } +} + - AlarmManager.prototype.getAlarmNotification = function () { ++AlarmManager.prototype.getAlarmNotification = function() { + var args = AV.validateMethod(arguments, [ + { - name : 'id', - type : AV.Types.STRING, ++ name: 'id', ++ type: AV.Types.STRING + } + ]); + - var result = native.callSync('AlarmManager_getAlarmNotification', {id: Number(args.id)}); ++ var result = native.callSync('AlarmManager_getAlarmNotification', { ++ id: Number(args.id) ++ }); + + if (native.isFailure(result)) { + throw native.getErrorObject(result); + } else { + var noti = native.getResultObject(result); + _prepareAppControl(noti); + _prepareDetailInfo(noti); + return new tizen.UserNotification(noti.userType, noti.title, noti); } }; @@@ -286,13 -183,11 +306,12 @@@ AlarmManager.prototype.getAll = functio } else { var data = native.getResultObject(result); var md = []; + _warningLogs.disallow(); - data.forEach(function (i) { - if ('AlarmRelative'=== i.type) { + data.forEach(function(i) { + if ('AlarmRelative' === i.type) { md.push(new tizen.AlarmRelative(i.delay, i.period, InternalData_(i))); } else { - var date = new Date(i.year, i.month, i.day, - i.hour, i.min, i.sec); + var date = new Date(i.year, i.month, i.day, i.hour, i.min, i.sec); md.push(new tizen.AlarmAbsolute(date, i.second, InternalData_(i))); } }); @@@ -413,15 -313,11 +438,18 @@@ tizen.AlarmAbsolute = function(date, se if (T.isDate(date)) { m_date = date; if (arguments.length >= 2) { - if(T.isArray(second)){ + if (T.isArray(second)) { m_daysOfWeek = second; } else { - if(!T.isNullOrUndefined(second)){ + if (!T.isNullOrUndefined(second)) { m_period = Converter.toLong(second); - if(_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated){ - privUtils_.warn("This Constructor is deprecated since Tizen 4.0." + - " Please consider using other constructors or other type of an alarm."); ++ if (_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated) { ++ privUtils_.warn( ++ 'This Constructor is deprecated since Tizen 4.0.' + ++ ' Please consider using other constructors or ' + ++ 'other type of an alarm.' ++ ); + } } } } @@@ -445,18 -341,9 +473,24 @@@ }, period: { get: function() { - if(_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated){ - privUtils_.warn('Since Tizen 4.0 constructor AlarmAbsolute(Date date, long period) ' + - 'is deprecated, thus period attribute should not be used.'); ++ if (_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated) { ++ privUtils_.warn( ++ 'Since Tizen 4.0 constructor AlarmAbsolute(Date date, ' + ++ 'long period) is deprecated, thus period attribute should ' + ++ 'not be used.' ++ ); + } return m_period; }, set: function(v) { - if(_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated){ - privUtils_.warn('Since Tizen 4.0 constructor AlarmAbsolute(Date date, long period) ' + - 'is deprecated, thus period attribute should not be used.'); ++ if (_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated) { ++ privUtils_.warn( ++ 'Since Tizen 4.0 constructor AlarmAbsolute(Date date, ' + ++ 'long period) is deprecated, thus period attribute should ' + ++ 'not be used.' ++ ); + } + if (_edit.canEdit && v) { m_period = Converter.toLong(v.period); } @@@ -497,45 -386,5 +533,45 @@@ tizen.AlarmAbsolute.prototype.getNextSc } }; +// Singleton to check on which profile plugins are executed +var ProfileAlarm = (function() { + var m_profile = null; + function ProfileAlarm() { - if (m_profile == null) { - m_profile = privUtils_.checkProfile(); - } - Object.defineProperties(this, { - profile: { - get: function() { - return m_profile; - }, - set: function() {}, - enumerable: true - } - }) - }; ++ if (m_profile == null) { ++ m_profile = privUtils_.checkProfile(); ++ } ++ Object.defineProperties(this, { ++ profile: { ++ get: function() { ++ return m_profile; ++ }, ++ set: function() {}, ++ enumerable: true ++ } ++ }); ++ } + + var instance; + return { + getInstance: function() { + if (instance == null) { + instance = new ProfileAlarm(); + // Hide the constructor so the returned objected can't be new'd... + instance.constructor = null; + } + return instance; + } - }; ++ }; +})(); + +var _profile = ProfileAlarm.getInstance().profile; + +// Notifications feature are available on mobile and wearable profile +if (_profile != 'mobile' && _profile != 'wearable') { + delete AlarmManager.prototype.addAlarmNotification; + delete AlarmManager.prototype.getAlarmNotification; + isAlarmAbsolutePeriodDeprecated = false; +} + //exports ////////////////////////////////////////////////////////////// exports = new AlarmManager(); diff --cc src/application/application_api.js index 3b53fc11,6613b4b5..70586eef --- a/src/application/application_api.js +++ b/src/application/application_api.js @@@ -22,15 -22,10 +22,15 @@@ var privUtils_ = xwalk.utils var native = new xwalk.utils.NativeManager(extension); var ApplicationControlLaunchMode = { - SINGLE: 'SINGLE', - GROUP: 'GROUP' + SINGLE: 'SINGLE', + GROUP: 'GROUP' }; +var ApplicationUsageMode = { - RECENTLY: 'RECENTLY', - FREQUENTLY: 'FREQUENTLY' ++ RECENTLY: 'RECENTLY', ++ FREQUENTLY: 'FREQUENTLY' +}; + // TODO: Please uncomment below lines when system events is ready //var SystemEvent = { // BATTERY_CHARGER_STATUS: 'BATTERY_CHARGER_STATUS', @@@ -472,216 -479,69 +484,233 @@@ ApplicationManager.prototype.getAppShar }; ApplicationManager.prototype.getAppMetaData = function() { - var args = AV.validateMethod(arguments, [ - { - name : 'id', - type : AV.Types.STRING, - optional : true, - nullable : true - } - ]); - - var callArgs = {}; - - if (args.has.id) { - callArgs.id = args.id; - } - - var result = native.callSync('ApplicationManager_getAppMetaData', callArgs); - - if (native.isFailure(result)) { - throw native.getErrorObject(result); - } else { - var metaData = native.getResultObject(result); - var md = []; - metaData.forEach(function (i) { - md.push(new ApplicationMetaData(i)); - }); - return md; - } + var args = AV.validateMethod(arguments, [ + { + name: 'id', + type: AV.Types.STRING, + optional: true, + nullable: true + } + ]); + + var callArgs = {}; + + if (args.has.id) { + callArgs.id = args.id; + } + + var result = native.callSync('ApplicationManager_getAppMetaData', callArgs); + + if (native.isFailure(result)) { + throw native.getErrorObject(result); + } else { + var metaData = native.getResultObject(result); + var md = []; + metaData.forEach(function(i) { + md.push(new ApplicationMetaData(i)); + }); + return md; + } }; +ApplicationManager.prototype.getBatteryUsageInfo = function() { - var args = AV.validateMethod(arguments, [ - { - name: 'successCallback', - type: AV.Types.FUNCTION - }, - { - name: 'errorCallback', - type: AV.Types.FUNCTION, - optional: true, - nullable: true - }, - { - name: 'days', - type: AV.Types.LONG, - optional: true, - nullable: true - }, - { - name: 'limit', - type: AV.Types.LONG, - optional: true, - nullable: true - }]); - - var callArgs = {}; - - if (!T.isNullOrUndefined(args.days)) { - callArgs.days = args.days; - } - - if (!T.isNullOrUndefined(args.limit)) { - callArgs.limit = args.limit; - } - - var callback = function(result) { ++ var args = AV.validateMethod(arguments, [ ++ { ++ name: 'successCallback', ++ type: AV.Types.FUNCTION ++ }, ++ { ++ name: 'errorCallback', ++ type: AV.Types.FUNCTION, ++ optional: true, ++ nullable: true ++ }, ++ { ++ name: 'days', ++ type: AV.Types.LONG, ++ optional: true, ++ nullable: true ++ }, ++ { ++ name: 'limit', ++ type: AV.Types.LONG, ++ optional: true, ++ nullable: true ++ } ++ ]); ++ ++ var callArgs = {}; ++ ++ if (!T.isNullOrUndefined(args.days)) { ++ callArgs.days = args.days; ++ } ++ ++ if (!T.isNullOrUndefined(args.limit)) { ++ callArgs.limit = args.limit; ++ } ++ ++ var callback = function(result) { ++ if (native.isFailure(result)) { ++ native.callIfPossible(args.errorCallback, native.getErrorObject(result)); ++ } else { ++ var data = native.getResultObject(result); ++ var resultArray = []; ++ data.forEach(function(i) { ++ resultArray.push(new ApplicationBatteryUsage(i)); ++ }); ++ args.successCallback(resultArray); ++ } ++ }; ++ ++ var result = native.call( ++ 'ApplicationManager_getBatteryUsageInfo', ++ callArgs, ++ callback ++ ); + if (native.isFailure(result)) { - native.callIfPossible(args.errorCallback, native.getErrorObject(result)); - } else { - var data = native.getResultObject(result); - var resultArray = []; - data.forEach(function (i) { - resultArray.push(new ApplicationBatteryUsage(i)); - }); - args.successCallback(resultArray); - } - }; - - var result = native.call('ApplicationManager_getBatteryUsageInfo', callArgs, callback); - if (native.isFailure(result)) { - throw native.getErrorObject(result); - } ++ throw native.getErrorObject(result); ++ } +}; + +ApplicationManager.prototype.getAppsUsageInfo = function() { - var args = AV.validateMethod(arguments, [ - { - name: 'successCallback', - type: AV.Types.FUNCTION - }, - { - name: 'errorCallback', - type: AV.Types.FUNCTION, - optional: true, - nullable: true - }, - { - name: 'mode', - type: AV.Types.ENUM, - values: T.getValues(ApplicationUsageMode), - optional: true, - nullable: true - }, - { - name: 'filter', - type: AV.Types.DICTIONARY, - optional: true, - nullable: true - }, - { - name: 'limit', - type: AV.Types.LONG, - optional: true, - nullable: true - }]); - - var callArgs = {}; - - if (!T.isNullOrUndefined(args.mode)) { - callArgs.mode = args.mode; - } - - if (!T.isNullOrUndefined(args.filter) && typeof args.filter !== 'object') { - setTimeout(function() { - native.callIfPossible(args.errorCallback, - new WebAPIException(WebAPIException.INVALID_VALUES_ERR, - 'filter must be an object.')); - }, 0); - return; - } - - callArgs.filter = {}; - if (!T.isNullOrUndefined(args.filter)) { - var filter = args.filter; - if (!T.isNullOrUndefined(filter.timeSpan)) { - callArgs.filter.timeSpan = Converter.toLong(filter.timeSpan); - } else { - if (!T.isNullOrUndefined(filter.startTime)) { - if (filter.startTime instanceof Date) { - callArgs.filter.startTime = filter.startTime.getTime() / 1000; - } else { - throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, - 'startTime given with invalid type.'); ++ var args = AV.validateMethod(arguments, [ ++ { ++ name: 'successCallback', ++ type: AV.Types.FUNCTION ++ }, ++ { ++ name: 'errorCallback', ++ type: AV.Types.FUNCTION, ++ optional: true, ++ nullable: true ++ }, ++ { ++ name: 'mode', ++ type: AV.Types.ENUM, ++ values: T.getValues(ApplicationUsageMode), ++ optional: true, ++ nullable: true ++ }, ++ { ++ name: 'filter', ++ type: AV.Types.DICTIONARY, ++ optional: true, ++ nullable: true ++ }, ++ { ++ name: 'limit', ++ type: AV.Types.LONG, ++ optional: true, ++ nullable: true + } - } ++ ]); + - if (!T.isNullOrUndefined(filter.endTime)) { - if (filter.endTime instanceof Date) { - callArgs.filter.endTime = filter.endTime.getTime() / 1000; ++ var callArgs = {}; ++ ++ if (!T.isNullOrUndefined(args.mode)) { ++ callArgs.mode = args.mode; ++ } ++ ++ if (!T.isNullOrUndefined(args.filter) && typeof args.filter !== 'object') { ++ setTimeout(function() { ++ native.callIfPossible( ++ args.errorCallback, ++ new WebAPIException( ++ WebAPIException.INVALID_VALUES_ERR, ++ 'filter must be an object.' ++ ) ++ ); ++ }, 0); ++ return; ++ } ++ ++ callArgs.filter = {}; ++ if (!T.isNullOrUndefined(args.filter)) { ++ var filter = args.filter; ++ if (!T.isNullOrUndefined(filter.timeSpan)) { ++ callArgs.filter.timeSpan = Converter.toLong(filter.timeSpan); + } else { - throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, - 'endTime given with invalid type.'); ++ if (!T.isNullOrUndefined(filter.startTime)) { ++ if (filter.startTime instanceof Date) { ++ callArgs.filter.startTime = filter.startTime.getTime() / 1000; ++ } else { ++ throw new WebAPIException( ++ WebAPIException.TYPE_MISMATCH_ERR, ++ 'startTime given with invalid type.' ++ ); ++ } ++ } ++ ++ if (!T.isNullOrUndefined(filter.endTime)) { ++ if (filter.endTime instanceof Date) { ++ callArgs.filter.endTime = filter.endTime.getTime() / 1000; ++ } else { ++ throw new WebAPIException( ++ WebAPIException.TYPE_MISMATCH_ERR, ++ 'endTime given with invalid type.' ++ ); ++ } ++ } + } - } + } - } + - if (!T.isNullOrUndefined(args.limit)) { - callArgs.limit = args.limit; - } ++ if (!T.isNullOrUndefined(args.limit)) { ++ callArgs.limit = args.limit; ++ } + - var callback = function(result) { ++ var callback = function(result) { ++ if (native.isFailure(result)) { ++ native.callIfPossible(args.errorCallback, native.getErrorObject(result)); ++ } else { ++ var data = native.getResultObject(result); ++ var resultArray = []; ++ data.forEach(function(i) { ++ resultArray.push(new ApplicationUsage(i)); ++ }); ++ args.successCallback(resultArray); ++ } ++ }; ++ ++ var result = native.call('ApplicationManager_getAppsUsageInfo', callArgs, callback); + if (native.isFailure(result)) { - native.callIfPossible(args.errorCallback, native.getErrorObject(result)); - } else { - var data = native.getResultObject(result); - var resultArray = []; - data.forEach(function(i) { - resultArray.push(new ApplicationUsage(i)); - }); - args.successCallback(resultArray); - } - }; - - var result = native.call('ApplicationManager_getAppsUsageInfo', callArgs, callback); - if (native.isFailure(result)) { - throw native.getErrorObject(result); - } ++ throw native.getErrorObject(result); ++ } +}; + function ListenerManager(native, listenerName) { - this.listeners = {}; - this.nextId = 1; - this.nativeSet = false; - this.native = native; - this.listenerName = listenerName; - }; + this.listeners = {}; + this.nextId = 1; + this.nativeSet = false; + this.native = native; + this.listenerName = listenerName; + } ListenerManager.prototype.onListenerCalled = function(msg) { - var d = null; + var d = null; - switch (msg.action) { - case 'oninstalled': - case 'onupdated': - d = new ApplicationInformation(msg.data); - break; + switch (msg.action) { + case 'oninstalled': + case 'onupdated': + d = new ApplicationInformation(msg.data); + break; - case 'onuninstalled': - d = msg.data; - break; + case 'onuninstalled': + d = msg.data; + break; - default: - privUtils_.log('Unknown mode: ' + msg.action); - return; - } + default: + privUtils_.log('Unknown mode: ' + msg.action); + return; + } - for (var watchId in this.listeners) { - if (this.listeners.hasOwnProperty(watchId) && this.listeners[watchId][msg.action]) { - this.listeners[watchId][msg.action](d); + for (var watchId in this.listeners) { + if ( + this.listeners.hasOwnProperty(watchId) && + this.listeners[watchId][msg.action] + ) { + this.listeners[watchId][msg.action](d); + } } - } }; ListenerManager.prototype.addListener = function(callback) { @@@ -735,123 -601,22 +770,136 @@@ ApplicationManager.prototype.addAppInfo }; ApplicationManager.prototype.removeAppInfoEventListener = function() { - privUtils_.warn('DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be removed from next release. ' - + 'Use tizen.package.unsetPackageInfoEventListener() instead.'); - - var args = AV.validateMethod(arguments, [ - { - name : 'watchId', - type : AV.Types.LONG - } - ]); + privUtils_.warn( + 'DEPRECATION WARNING: removeAppInfoEventListener() is deprecated ' + + 'and will be removed from next release. ' + + 'Use tizen.package.unsetPackageInfoEventListener() instead.' + ); + + var args = AV.validateMethod(arguments, [ + { + name: 'watchId', + type: AV.Types.LONG + } + ]); - applicationEventListener.removeListener(args.watchId); + applicationEventListener.removeListener(args.watchId); }; +function StatusListenerManager(native, listenerName) { - this.listeners = {}; - this.listenersCount = 0; - this.nextId = 1; - this.nativeSet = false; - this.native = native; - this.listenerName = listenerName; - }; ++ this.listeners = {}; ++ this.listenersCount = 0; ++ this.nextId = 1; ++ this.nativeSet = false; ++ this.native = native; ++ this.listenerName = listenerName; ++} + +StatusListenerManager.prototype.onListenerCalled = function(msg) { - var statusType = msg.statusType; - var app_id = msg.appId; - - for (var watchId in this.listeners) { - if (this.listeners.hasOwnProperty(watchId)) { - var listener = this.listeners[watchId]; - if (!listener.appId || listener.appId === app_id) { - listener.callback(app_id, statusType); - } ++ var statusType = msg.statusType; ++ var app_id = msg.appId; ++ ++ for (var watchId in this.listeners) { ++ if (this.listeners.hasOwnProperty(watchId)) { ++ var listener = this.listeners[watchId]; ++ if (!listener.appId || listener.appId === app_id) { ++ listener.callback(app_id, statusType); ++ } ++ } + } - } +}; + +StatusListenerManager.prototype.addListener = function(callback, appId) { - if (!this.nativeSet) { - var result = this.native.callSync('ApplicationManager_addAppStatusChangeListener'); - if (this.native.isFailure(result)) { - throw this.native.getErrorObject(result); - } ++ if (!this.nativeSet) { ++ var result = this.native.callSync( ++ 'ApplicationManager_addAppStatusChangeListener' ++ ); ++ if (this.native.isFailure(result)) { ++ throw this.native.getErrorObject(result); ++ } + - this.native.addListener(this.listenerName, this.onListenerCalled.bind(this)); - this.nativeSet = true; - } ++ this.native.addListener(this.listenerName, this.onListenerCalled.bind(this)); ++ this.nativeSet = true; ++ } + - var listener = { - 'callback' : callback, - 'appId' : appId - }; ++ var listener = { ++ callback: callback, ++ appId: appId ++ }; + - var id = this.nextId++; - this.listeners[id] = listener; - this.listenersCount++; ++ var id = this.nextId++; ++ this.listeners[id] = listener; ++ this.listenersCount++; + - return id; ++ return id; +}; + +StatusListenerManager.prototype.removeListener = function(watchId) { - if (this.listeners.hasOwnProperty(watchId)) { - if (this.listenersCount > 1) { - delete this.listeners[watchId]; - this.listenersCount--; - return; - } ++ if (this.listeners.hasOwnProperty(watchId)) { ++ if (this.listenersCount > 1) { ++ delete this.listeners[watchId]; ++ this.listenersCount--; ++ return; ++ } + - if (this.nativeSet) { - var result = this.native.callSync('ApplicationManager_removeStatusChangeListener'); - if (this.native.isFailure(result)) { - throw this.native.getErrorObject(result); - } ++ if (this.nativeSet) { ++ var result = this.native.callSync( ++ 'ApplicationManager_removeStatusChangeListener' ++ ); ++ if (this.native.isFailure(result)) { ++ throw this.native.getErrorObject(result); ++ } + - delete this.listeners[watchId]; - this.listenersCount--; ++ delete this.listeners[watchId]; ++ this.listenersCount--; + - this.native.removeListener(this.listenerName); - this.nativeSet = false; ++ this.native.removeListener(this.listenerName); ++ this.nativeSet = false; ++ } + } - } +}; + +var APP_STATUS_CHANGE_LISTENER = 'AppStatusChangeListener'; - var appStatusChangeListener = new StatusListenerManager(native, APP_STATUS_CHANGE_LISTENER); ++var appStatusChangeListener = new StatusListenerManager( ++ native, ++ APP_STATUS_CHANGE_LISTENER ++); + +ApplicationManager.prototype.addAppStatusChangeListener = function() { - var args = AV.validateMethod(arguments, [ - { - name : 'statusChangeListener', - type : AV.Types.FUNCTION, - }, - { - name : 'appId', - type : AV.Types.STRING, - optional : true, - nullable : true - } - ]); - - if (args.appId !== undefined && args.appId !== null && !args.appId.length) { - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Application id is empty'); - } - - return appStatusChangeListener.addListener(args.statusChangeListener, args.appId); ++ var args = AV.validateMethod(arguments, [ ++ { ++ name: 'statusChangeListener', ++ type: AV.Types.FUNCTION ++ }, ++ { ++ name: 'appId', ++ type: AV.Types.STRING, ++ optional: true, ++ nullable: true ++ } ++ ]); ++ ++ if (args.appId !== undefined && args.appId !== null && !args.appId.length) { ++ throw new WebAPIException( ++ WebAPIException.INVALID_VALUES_ERR, ++ 'Application id is empty' ++ ); ++ } ++ ++ return appStatusChangeListener.addListener(args.statusChangeListener, args.appId); +}; + +ApplicationManager.prototype.removeAppStatusChangeListener = function() { - var args = AV.validateMethod(arguments, [ - { - name : 'watchId', - type : AV.Types.LONG - } - ]); - - appStatusChangeListener.removeListener(args.watchId); ++ var args = AV.validateMethod(arguments, [ ++ { ++ name: 'watchId', ++ type: AV.Types.LONG ++ } ++ ]); ++ ++ appStatusChangeListener.removeListener(args.watchId); +}; + // class Application //////////////////////////////////////////////////// function Application(data) { @@@ -1352,77 -1121,35 +1404,77 @@@ RequestedApplicationControl.prototype.r // class ApplicationCertificate //////////////////////////////////////////////////// function ApplicationCertificate(data) { - Object.defineProperties(this, { - type : { - value : data.type, - writable : false, - enumerable : true - }, - value : { - value : data.value, - writable : false, - enumerable : true - } - }); + Object.defineProperties(this, { + type: { + value: data.type, + writable: false, + enumerable: true + }, + value: { + value: data.value, + writable: false, + enumerable: true + } + }); } -// class ApplicationMetaData //////////////////////////////////////////////////// +// class ApplicationMetaData /////////////////////////////////////////////////////// function ApplicationMetaData(data) { - Object.defineProperties(this, { - key : { - value : data.key, - writable : false, - enumerable : true - }, - value : { - value : data.value, - writable : false, - enumerable : true - } - }); + Object.defineProperties(this, { + key: { + value: data.key, + writable: false, + enumerable: true + }, + value: { + value: data.value, + writable: false, + enumerable: true + } + }); } +//class ApplicationBatteryUsage //////////////////////////////////////////////////// +function ApplicationBatteryUsage(data) { - Object.defineProperties(this, { - appId : { - value : data.appId, - writable : false, - enumerable : true - }, - batteryUsage : { - value : data.batteryUsage, - writable : false, - enumerable : true - } - }); ++ Object.defineProperties(this, { ++ appId: { ++ value: data.appId, ++ writable: false, ++ enumerable: true ++ }, ++ batteryUsage: { ++ value: data.batteryUsage, ++ writable: false, ++ enumerable: true ++ } ++ }); +} + +//class ApplicationUsage //////////////////////////////////////////////////////// +function ApplicationUsage(data) { - Object.defineProperties(this, { - appId : { - value : data.appId, - writable : false, - enumerable : true - }, - totalCount : { - value : data.totalCount, - writable : false, - enumerable : true - }, - totalDuration : { - value : data.totalDuration, - writable : false, - enumerable : true - }, - lastTime : { - value : new Date(data.lastTime * 1000), - writable : false, - enumerable : true - } - }); ++ Object.defineProperties(this, { ++ appId: { ++ value: data.appId, ++ writable: false, ++ enumerable: true ++ }, ++ totalCount: { ++ value: data.totalCount, ++ writable: false, ++ enumerable: true ++ }, ++ totalDuration: { ++ value: data.totalDuration, ++ writable: false, ++ enumerable: true ++ }, ++ lastTime: { ++ value: new Date(data.lastTime * 1000), ++ writable: false, ++ enumerable: true ++ } ++ }); +} + // exports //////////////////////////////////////////////////// exports = new ApplicationManager(); diff --cc src/datacontrol/datacontrol_api.js index 5de955ec,c92902de..94bf83b9 --- a/src/datacontrol/datacontrol_api.js +++ b/src/datacontrol/datacontrol_api.js @@@ -14,568 -14,501 +14,663 @@@ * limitations under the License. */ -tizen.debug = extension; - -var JSON_ = xwalk.JSON; var validator_ = xwalk.utils.validator; +var converter_ = xwalk.utils.converter; var types_ = validator_.Types; +var type_ = xwalk.utils.type; +var native_ = new xwalk.utils.NativeManager(extension); -var callbackId = 0; -var callbacks = {}; +var DATA_CONTROL_MANAGER_LISTENER_ID = 'DataControlManagerChangeCallback'; -extension.setMessageListener(function(json) { - var result = JSON_.parse(json); - var callback = callbacks[result['callbackId']]; - setTimeout(function() { - callback(result); - delete callbacks[result['callbackId']]; - }, 0); -}); +var DataType = { - 'MAP': 'MAP', - 'SQL': 'SQL' ++ MAP: 'MAP', ++ SQL: 'SQL' +}; -function nextCallbackId() { - return callbackId++; -} +var DataControlListenersManager = (function() { ++ function changeEvent(event) { ++ var successCallback; - function changeEvent(event) { - var successCallback; - - if (DataType.SQL === event.type.substr(0,3)) { - if (type_.isEmptyObject(this._SQLDataControlCbMap)) { - return; - } - for (var listenerId in this._SQLDataControlCbMap) { - if (this._SQLDataControlCbMap.hasOwnProperty(listenerId)) { - if (this._SQLDataControlCbMap[listenerId].providerId === event.providerId && - this._SQLDataControlCbMap[listenerId].dataId === event.dataId) { - successCallback = this._SQLDataControlCbMap[listenerId].changeCallback; - if (type_.isFunction(successCallback)) { - successCallback(event.type, {columns: event.columns, values: event.values}); -function callNative(cmd, args) { - var json = { cmd: cmd, args: args }; - var argjson = JSON_.stringify(json); - var resultString = extension.internal.sendSyncMessage(argjson); - var result = JSON_.parse(resultString); ++ if (DataType.SQL === event.type.substr(0, 3)) { ++ if (type_.isEmptyObject(this._SQLDataControlCbMap)) { ++ return; + } - } - } - } - } else { - if (type_.isEmptyObject(this._MAPDataControlCbMap)) { - return; - } - for (var listenerId in this._MAPDataControlCbMap) { - if (this._MAPDataControlCbMap.hasOwnProperty(listenerId)) { - if (this._MAPDataControlCbMap[listenerId].providerId === event.providerId && - this._MAPDataControlCbMap[listenerId].dataId === event.dataId) { - successCallback = this._MAPDataControlCbMap[listenerId].changeCallback; - if (type_.isFunction(successCallback)) { - successCallback(event.type, {columns: event.columns, values: event.values}); ++ for (var listenerId in this._SQLDataControlCbMap) { ++ if (this._SQLDataControlCbMap.hasOwnProperty(listenerId)) { ++ if ( ++ this._SQLDataControlCbMap[listenerId].providerId === ++ event.providerId && ++ this._SQLDataControlCbMap[listenerId].dataId === event.dataId ++ ) { ++ successCallback = this._SQLDataControlCbMap[listenerId] ++ .changeCallback; ++ if (type_.isFunction(successCallback)) { ++ successCallback(event.type, { ++ columns: event.columns, ++ values: event.values ++ }); ++ } ++ } ++ } ++ } ++ } else { ++ if (type_.isEmptyObject(this._MAPDataControlCbMap)) { ++ return; ++ } ++ for (var listenerId in this._MAPDataControlCbMap) { ++ if (this._MAPDataControlCbMap.hasOwnProperty(listenerId)) { ++ if ( ++ this._MAPDataControlCbMap[listenerId].providerId === ++ event.providerId && ++ this._MAPDataControlCbMap[listenerId].dataId === event.dataId ++ ) { ++ successCallback = this._MAPDataControlCbMap[listenerId] ++ .changeCallback; ++ if (type_.isFunction(successCallback)) { ++ successCallback(event.type, { ++ columns: event.columns, ++ values: event.values ++ }); ++ } ++ } ++ } + } - } + } - } + } - } - function _DataControlListenerManager() { - this._SQLDataControlCbMap = {}; - this._MAPDataControlCbMap = {}; - this.lastListenerId = 0; - this.changeEvent = changeEvent.bind(this); - } - - _DataControlListenerManager.prototype.addChangeListener = function(type, providerId, dataId, changeCallback, errorCallback) { - var _realWatchId = 0; - if (DataType.SQL === type) { - for (var i in this._SQLDataControlCbMap) { - if (this._SQLDataControlCbMap.hasOwnProperty(i) && - this._SQLDataControlCbMap[i].providerId === providerId && - this._SQLDataControlCbMap[i].dataId === dataId) { - _realWatchId = this._SQLDataControlCbMap[i].realWatchId; - } - } - } else { - for (var i in this._MAPDataControlCbMap) { - if (this._MAPDataControlCbMap.hasOwnProperty(i) && - this._MAPDataControlCbMap[i].providerId === providerId && - this._MAPDataControlCbMap[i].dataId === dataId) { - _realWatchId = this._MAPDataControlCbMap[i].realWatchId; - } - } - if (typeof result !== 'object') { - throw new WebAPIException(WebAPIException.UNKNOWN_ERR); ++ function _DataControlListenerManager() { ++ this._SQLDataControlCbMap = {}; ++ this._MAPDataControlCbMap = {}; ++ this.lastListenerId = 0; ++ this.changeEvent = changeEvent.bind(this); } - if (!_realWatchId) { - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(errorCallback, native_.getErrorObject(result)); - return; - if (result['status'] == 'success') { - if (result['result']) { - return result['result']; ++ _DataControlListenerManager.prototype.addChangeListener = function( ++ type, ++ providerId, ++ dataId, ++ changeCallback, ++ errorCallback ++ ) { ++ var _realWatchId = 0; ++ if (DataType.SQL === type) { ++ for (var i in this._SQLDataControlCbMap) { ++ if ( ++ this._SQLDataControlCbMap.hasOwnProperty(i) && ++ this._SQLDataControlCbMap[i].providerId === providerId && ++ this._SQLDataControlCbMap[i].dataId === dataId ++ ) { ++ _realWatchId = this._SQLDataControlCbMap[i].realWatchId; ++ } ++ } ++ } else { ++ for (var i in this._MAPDataControlCbMap) { ++ if ( ++ this._MAPDataControlCbMap.hasOwnProperty(i) && ++ this._MAPDataControlCbMap[i].providerId === providerId && ++ this._MAPDataControlCbMap[i].dataId === dataId ++ ) { ++ _realWatchId = this._MAPDataControlCbMap[i].realWatchId; ++ } ++ } + } - }; - var result = - native_.call('DataControlConsumerObject_addChangeListener', { - providerId: providerId, - dataId: dataId, - type: type - }, callback); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } else { - result = native_.getResultObject(result); - _realWatchId = converter_.toLong(result.watchId, true); - } - if (type_.isEmptyObject(this._SQLDataControlCbMap) && - type_.isEmptyObject(this._MAPDataControlCbMap)) { - native_.addListener(DATA_CONTROL_MANAGER_LISTENER_ID, this.changeEvent); - } - } + - if (DataType.SQL === type) { - this._SQLDataControlCbMap[++this.lastListenerId] = {'providerId': providerId, - 'dataId': dataId, - 'changeCallback': changeCallback, - 'realWatchId': _realWatchId}; - } else { - this._MAPDataControlCbMap[++this.lastListenerId] = {'providerId': providerId, - 'dataId': dataId, - 'changeCallback': changeCallback, - 'realWatchId': _realWatchId}; - } - - return this.lastListenerId; - }; - - _DataControlListenerManager.prototype.removeChangeListener = function(type, providerId, dataId, listenerId) { - var _realWatchId = 0; - if (DataType.SQL === type && - !type_.isUndefined(this._SQLDataControlCbMap[listenerId])) { - _realWatchId = this._SQLDataControlCbMap[listenerId].realWatchId; - delete this._SQLDataControlCbMap[listenerId]; - for (var i in this._SQLDataControlCbMap) { - if (this._SQLDataControlCbMap.hasOwnProperty(i) && - this._SQLDataControlCbMap[i].realWatchId === _realWatchId) { - return; ++ if (!_realWatchId) { ++ var callback = function(result) { ++ if (native_.isFailure(result)) { ++ native_.callIfPossible(errorCallback, native_.getErrorObject(result)); ++ return; ++ } ++ }; ++ var result = native_.call( ++ 'DataControlConsumerObject_addChangeListener', ++ { ++ providerId: providerId, ++ dataId: dataId, ++ type: type ++ }, ++ callback ++ ); ++ ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } else { ++ result = native_.getResultObject(result); ++ _realWatchId = converter_.toLong(result.watchId, true); ++ } ++ if ( ++ type_.isEmptyObject(this._SQLDataControlCbMap) && ++ type_.isEmptyObject(this._MAPDataControlCbMap) ++ ) { ++ native_.addListener(DATA_CONTROL_MANAGER_LISTENER_ID, this.changeEvent); ++ } } - } - } else if (DataType.MAP === type && - !type_.isUndefined(this._MAPDataControlCbMap[listenerId])) { - _realWatchId = this._MAPDataControlCbMap[listenerId].realWatchId; - delete this._MAPDataControlCbMap[listenerId]; - for (var i in this._MAPDataControlCbMap) { - if (this._MAPDataControlCbMap.hasOwnProperty(i) && - this._MAPDataControlCbMap[i].realWatchId === _realWatchId) { - return; - return true; - } else if (result['status'] == 'error') { - var err = result['error']; - if (err) { - throw new WebAPIException(err); ++ ++ if (DataType.SQL === type) { ++ this._SQLDataControlCbMap[++this.lastListenerId] = { ++ providerId: providerId, ++ dataId: dataId, ++ changeCallback: changeCallback, ++ realWatchId: _realWatchId ++ }; ++ } else { ++ this._MAPDataControlCbMap[++this.lastListenerId] = { ++ providerId: providerId, ++ dataId: dataId, ++ changeCallback: changeCallback, ++ realWatchId: _realWatchId ++ }; } - } - } else { - console.log('Type invalid or listener was not added'); - return; - return false; -- } -} - if (0 != _realWatchId) { - native_.call('DataControlConsumerObject_removeChangeListener',{ - watchId: _realWatchId, - }); -function callNativeWithCallback(cmd, args, callback) { - if (callback) { - var id = nextCallbackId(); - args['callbackId'] = id; - callbacks[id] = callback; - } ++ return this.lastListenerId; ++ }; + - return callNative(cmd, args); -} ++ _DataControlListenerManager.prototype.removeChangeListener = function( ++ type, ++ providerId, ++ dataId, ++ listenerId ++ ) { ++ var _realWatchId = 0; ++ if ( ++ DataType.SQL === type && ++ !type_.isUndefined(this._SQLDataControlCbMap[listenerId]) ++ ) { ++ _realWatchId = this._SQLDataControlCbMap[listenerId].realWatchId; ++ delete this._SQLDataControlCbMap[listenerId]; ++ for (var i in this._SQLDataControlCbMap) { ++ if ( ++ this._SQLDataControlCbMap.hasOwnProperty(i) && ++ this._SQLDataControlCbMap[i].realWatchId === _realWatchId ++ ) { ++ return; ++ } ++ } ++ } else if ( ++ DataType.MAP === type && ++ !type_.isUndefined(this._MAPDataControlCbMap[listenerId]) ++ ) { ++ _realWatchId = this._MAPDataControlCbMap[listenerId].realWatchId; ++ delete this._MAPDataControlCbMap[listenerId]; ++ for (var i in this._MAPDataControlCbMap) { ++ if ( ++ this._MAPDataControlCbMap.hasOwnProperty(i) && ++ this._MAPDataControlCbMap[i].realWatchId === _realWatchId ++ ) { ++ return; ++ } ++ } ++ } else { ++ console.log('Type invalid or listener was not added'); ++ return; ++ } + - if (type_.isEmptyObject(this._SQLDataControlCbMap) && - type_.isEmptyObject(this._MAPDataControlCbMap)) { - native_.removeListener(DATA_CONTROL_MANAGER_LISTENER_ID); - } - } - }; ++ if (0 != _realWatchId) { ++ native_.call('DataControlConsumerObject_removeChangeListener', { ++ watchId: _realWatchId ++ }); + - return _DataControlListenerManager; ++ if ( ++ type_.isEmptyObject(this._SQLDataControlCbMap) && ++ type_.isEmptyObject(this._MAPDataControlCbMap) ++ ) { ++ native_.removeListener(DATA_CONTROL_MANAGER_LISTENER_ID); ++ } ++ } ++ }; + ++ return _DataControlListenerManager; +})(); + +var listenersManager = new DataControlListenersManager(); function SetReadOnlyProperty(obj, n, v) { - Object.defineProperty(obj, n, {value: v, writable: false}); + Object.defineProperty(obj, n, { value: v, writable: false }); } -var DataType = { - MAP: 'MAP', - SQL: 'SQL' -}; - function DataControlManager() { - // constructor of DataControlManager + // constructor of DataControlManager } var privUtils_ = xwalk.utils; var getDataControlConsumer = function(providerId, dataId, type) { - privUtils_.checkPrivilegeAccess(privUtils_.privilege.DATACONTROL_CONSUMER); - var args = validator_.validateArgs(arguments, [ - {'name': 'providerId', 'type': types_.STRING}, - {'name': 'dataId', 'type': types_.STRING}, - {'name': 'type', 'type': types_.ENUM, 'values': [DataType.SQL, DataType.MAP]} - ]); - - var returnObject = null; - if (DataType.SQL === type) { - returnObject = new SQLDataControlConsumer(); - } else if (DataType.MAP == type) { - returnObject = new MappedDataControlConsumer(); - } - - SetReadOnlyProperty(returnObject, 'type', args.type); // read only property - SetReadOnlyProperty(returnObject, 'providerId', args.providerId); // read only property - SetReadOnlyProperty(returnObject, 'dataId', args.dataId); // read only property - - return returnObject; - }; + privUtils_.checkPrivilegeAccess(privUtils_.privilege.DATACONTROL_CONSUMER); + var args = validator_.validateArgs(arguments, [ + { name: 'providerId', type: types_.STRING }, + { name: 'dataId', type: types_.STRING }, - { name: 'type', type: types_.ENUM, values: ['MAP', 'SQL'] } ++ { name: 'type', type: types_.ENUM, values: [DataType.SQL, DataType.MAP] } + ]); + + var returnObject = null; - if (type === 'SQL') { ++ if (DataType.SQL === type) { + returnObject = new SQLDataControlConsumer(); - } else if (type === 'MAP') { ++ } else if (DataType.MAP == type) { + returnObject = new MappedDataControlConsumer(); + } - SetReadOnlyProperty(returnObject, 'type', args.type); // read only property ++ ++ // read only property ++ SetReadOnlyProperty(returnObject, 'type', args.type); + // read only property + SetReadOnlyProperty(returnObject, 'providerId', args.providerId); - SetReadOnlyProperty(returnObject, 'dataId', args.dataId); // read only property ++ // read only property ++ SetReadOnlyProperty(returnObject, 'dataId', args.dataId); + return returnObject; + }; DataControlManager.prototype.getDataControlConsumer = function(providerId, dataId, type) { - return getDataControlConsumer.apply(null, arguments); + return getDataControlConsumer.apply(null, arguments); }; function DataControlConsumerObject() { - // constructor of DataControlConsumerObject + // constructor of DataControlConsumerObject } +DataControlConsumerObject.prototype.addChangeListener = function() { - var args = validator_.validateArgs(arguments, [ - {'name': 'dataChangeCallback', 'type': types_.FUNCTION, optional: false, - nullable: false}, - {'name': 'errorCallback', 'type': types_.FUNCTION, optional: true, nullable: true} - ]); - - var type = DataType.SQL; - if (this instanceof MappedDataControlConsumer) { - type = DataType.MAP; - } - - return listenersManager.addChangeListener(type, this.providerId, this.dataId, - args.dataChangeCallback, args.errorCallback); ++ var args = validator_.validateArgs(arguments, [ ++ { ++ name: 'dataChangeCallback', ++ type: types_.FUNCTION, ++ optional: false, ++ nullable: false ++ }, ++ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } ++ ]); ++ ++ var type = DataType.SQL; ++ if (this instanceof MappedDataControlConsumer) { ++ type = DataType.MAP; ++ } ++ ++ return listenersManager.addChangeListener( ++ type, ++ this.providerId, ++ this.dataId, ++ args.dataChangeCallback, ++ args.errorCallback ++ ); +}; + +DataControlConsumerObject.prototype.removeChangeListener = function() { - var args = validator_.validateArgs(arguments, [ - {'name': 'watchId', 'type': types_.LONG} - ]); ++ var args = validator_.validateArgs(arguments, [ ++ { name: 'watchId', type: types_.LONG } ++ ]); + - var type = DataType.SQL; - if (this instanceof MappedDataControlConsumer) { - type = DataType.MAP; - } ++ var type = DataType.SQL; ++ if (this instanceof MappedDataControlConsumer) { ++ type = DataType.MAP; ++ } + - listenersManager.removeChangeListener(type, this.providerId, this.dataId, args.watchId); ++ listenersManager.removeChangeListener( ++ type, ++ this.providerId, ++ this.dataId, ++ args.watchId ++ ); +}; + function SQLDataControlConsumer() { - // constructor of SQLDataControlConsumer + // constructor of SQLDataControlConsumer } SQLDataControlConsumer.prototype = new DataControlConsumerObject(); SQLDataControlConsumer.prototype.constructor = SQLDataControlConsumer; -SQLDataControlConsumer.prototype.insert = function(reqId, insertionData) { +SQLDataControlConsumer.prototype.insert = function() { - var args = validator_.validateArgs(arguments, [ - {'name': 'reqId', 'type': types_.LONG}, - {'name': 'insertionData', 'type': types_.DICTIONARY}, - {'name': 'successCallback', 'type': types_.FUNCTION, optional: true, nullable: true}, - {'name': 'errorCallback', 'type': types_.FUNCTION, optional: true, nullable: true} - ]); - - // doing conversion of all elements to string - var ins = validator_.validateArgs([args.insertionData.columns, args.insertionData.values], [ - {name : 'columns', type : types_.ARRAY, values : types_.STRING}, - {name : 'values', type : types_.ARRAY, values : types_.STRING} - ]); - - var nativeParam = { - 'providerId': this.providerId, - 'dataId': this.dataId, - 'reqId': args.reqId, - 'insertionData': args.insertionData - }; - - var syncResult = - native_.call('SQLDataControlConsumer_insert', nativeParam, function(result) { - if (result.status == 'success') { - if (args.successCallback) { - args.successCallback(result['requestId'], result['result']); + var args = validator_.validateArgs(arguments, [ + { name: 'reqId', type: types_.LONG }, + { name: 'insertionData', type: types_.DICTIONARY }, + { + name: 'successCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + // doing conversion of all elements to string + var ins = validator_.validateArgs( + [args.insertionData.columns, args.insertionData.values], + [ + { name: 'columns', type: types_.ARRAY, values: types_.STRING }, + { name: 'values', type: types_.ARRAY, values: types_.STRING } + ] + ); + + var nativeParam = { + providerId: this.providerId, + dataId: this.dataId, + reqId: args.reqId, + insertionData: args.insertionData + }; - try { - var syncResult = callNativeWithCallback( - 'SQLDataControlConsumer_insert', - nativeParam, - function(result) { - if (result.status == 'success') { - if (args.successCallback) { - args.successCallback(result['requestId'], result['result']); - } - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); - } - } ++ ++ var syncResult = native_.call('SQLDataControlConsumer_insert', nativeParam, function( ++ result ++ ) { ++ if (result.status == 'success') { ++ if (args.successCallback) { ++ args.successCallback(result['requestId'], result['result']); ++ } + } - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); ++ if (result.status == 'error') { ++ if (args.errorCallback) { ++ var err = result['result']; ++ var e = new WebAPIException(err.name, err.message); ++ args.errorCallback(result['requestId'], e); + } - ); - } catch (e) { - throw e; + } - } + }); + - if (native_.isFailure(syncResult)) { - throw native_.getErrorObject(syncResult); - } ++ if (native_.isFailure(syncResult)) { ++ throw native_.getErrorObject(syncResult); + } }; -SQLDataControlConsumer.prototype.update = function(reqId, updateData, where) { +SQLDataControlConsumer.prototype.update = function() { - var args = validator_.validateArgs(arguments, [ - {'name': 'reqId', 'type': types_.LONG}, - {'name': 'updateData', 'type': types_.DICTIONARY}, - {'name': 'where', 'type': types_.STRING}, - {'name': 'successCallback', 'type': types_.FUNCTION, optional: true, nullable: true}, - {'name': 'errorCallback', 'type': types_.FUNCTION, optional: true, nullable: true} - ]); - - var nativeParam = { - 'providerId': this.providerId, - 'dataId': this.dataId, - 'reqId': args.reqId, - 'where': args.where, - 'updateData': args.updateData - }; - - var syncResult = - native_.call('SQLDataControlConsumer_update', nativeParam, function(result) { - if (result.status == 'success') { - if (args.successCallback) { - args.successCallback(result['requestId']); + var args = validator_.validateArgs(arguments, [ + { name: 'reqId', type: types_.LONG }, + { name: 'updateData', type: types_.DICTIONARY }, + { name: 'where', type: types_.STRING }, + { + name: 'successCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var nativeParam = { + providerId: this.providerId, + dataId: this.dataId, + reqId: args.reqId, + where: args.where, + updateData: args.updateData + }; - try { - var syncResult = callNativeWithCallback( - 'SQLDataControlConsumer_update', - nativeParam, - function(result) { - if (result.status == 'success') { - if (args.successCallback) { - args.successCallback(result['requestId']); - } - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); - } - } ++ ++ var syncResult = native_.call('SQLDataControlConsumer_update', nativeParam, function( ++ result ++ ) { ++ if (result.status == 'success') { ++ if (args.successCallback) { ++ args.successCallback(result['requestId']); + } - ); - } catch (e) { - throw e; + } - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); ++ if (result.status == 'error') { ++ if (args.errorCallback) { ++ var err = result['result']; ++ var e = new WebAPIException(err.name, err.message); ++ args.errorCallback(result['requestId'], e); ++ } + } - } + }); + - if (native_.isFailure(syncResult)) { - throw native_.getErrorObject(syncResult); - } ++ if (native_.isFailure(syncResult)) { ++ throw native_.getErrorObject(syncResult); + } }; -SQLDataControlConsumer.prototype.remove = function(reqId, where) { +SQLDataControlConsumer.prototype.remove = function() { - var args = validator_.validateArgs(arguments, [ - {'name': 'reqId', 'type': types_.LONG}, - {'name': 'where', 'type': types_.STRING}, - {'name': 'successCallback', 'type': types_.FUNCTION, optional: true, nullable: true}, - {'name': 'errorCallback', 'type': types_.FUNCTION, optional: true, nullable: true} - ]); - - var nativeParam = { - 'providerId': this.providerId, - 'dataId': this.dataId, - 'reqId': args.reqId, - 'where': args.where - }; - - var syncResult = - native_.call('SQLDataControlConsumer_remove', nativeParam, function(result) { - if (result.status == 'success') { - if (args.successCallback) { - args.successCallback(result['requestId']); + var args = validator_.validateArgs(arguments, [ + { name: 'reqId', type: types_.LONG }, + { name: 'where', type: types_.STRING }, + { + name: 'successCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var nativeParam = { + providerId: this.providerId, + dataId: this.dataId, + reqId: args.reqId, + where: args.where + }; - try { - var syncResult = callNativeWithCallback( - 'SQLDataControlConsumer_remove', - nativeParam, - function(result) { - if (result.status == 'success') { - if (args.successCallback) { - args.successCallback(result['requestId']); - } - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); - } - } ++ ++ var syncResult = native_.call('SQLDataControlConsumer_remove', nativeParam, function( ++ result ++ ) { ++ if (result.status == 'success') { ++ if (args.successCallback) { ++ args.successCallback(result['requestId']); + } - ); - } catch (e) { - throw e; + } - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); ++ if (result.status == 'error') { ++ if (args.errorCallback) { ++ var err = result['result']; ++ var e = new WebAPIException(err.name, err.message); ++ args.errorCallback(result['requestId'], e); ++ } + } - } + }); + - if (native_.isFailure(syncResult)) { - throw native_.getErrorObject(syncResult); - } - ++ if (native_.isFailure(syncResult)) { ++ throw native_.getErrorObject(syncResult); + } }; -SQLDataControlConsumer.prototype.select = function( - reqId, - columns, - where, - successCallback -) { +SQLDataControlConsumer.prototype.select = function() { - var args = validator_.validateArgs(arguments, [ - {'name': 'reqId', 'type': types_.LONG}, - {'name': 'columns', 'type': types_.ARRAY}, - {'name': 'where', 'type': types_.STRING}, - {'name': 'successCallback', 'type': types_.FUNCTION}, - {'name': 'errorCallback', 'type': types_.FUNCTION, optional: true, nullable: true}, - {'name': 'page', 'type': types_.LONG, optional: true, nullable: true}, - {'name': 'maxNumberPerPage', 'type': types_.LONG, optional: true, nullable: true}, - {'name': 'order', 'type': types_.STRING, optional: true, nullable: true} - ]); - - var nativeParam = { - 'providerId': this.providerId, - 'dataId': this.dataId, - 'reqId': args.reqId, - 'columns': args.columns, - 'where': args.where - }; - if (args['page']) { - nativeParam['page'] = args.page; - } - if (args['maxNumberPerPage']) { - nativeParam['maxNumberPerPage'] = args.maxNumberPerPage; - } - if (args['order']) { - nativeParam['order'] = args.order; - } - - var syncResult = - native_.call('SQLDataControlConsumer_select', nativeParam, function(result) { - if (result.status == 'success') { - args.successCallback(result['result'], result['requestId']); - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); + var args = validator_.validateArgs(arguments, [ + { name: 'reqId', type: types_.LONG }, + { name: 'columns', type: types_.ARRAY }, + { name: 'where', type: types_.STRING }, + { name: 'successCallback', type: types_.FUNCTION }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - }, ++ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }, + { name: 'page', type: types_.LONG, optional: true, nullable: true }, - { - name: 'maxNumberPerPage', - type: types_.LONG, - optional: true, - nullable: true - }, ++ { name: 'maxNumberPerPage', type: types_.LONG, optional: true, nullable: true }, + { name: 'order', type: types_.STRING, optional: true, nullable: true } + ]); + + var nativeParam = { + providerId: this.providerId, + dataId: this.dataId, + reqId: args.reqId, + columns: args.columns, + where: args.where + }; + if (args['page']) { + nativeParam['page'] = args.page; + } + if (args['maxNumberPerPage']) { + nativeParam['maxNumberPerPage'] = args.maxNumberPerPage; + } + if (args['order']) { + nativeParam['order'] = args.order; + } + - try { - var syncResult = callNativeWithCallback( - 'SQLDataControlConsumer_select', - nativeParam, - function(result) { - if (result.status == 'success') { - args.successCallback(result['result'], result['requestId']); - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); - } - } ++ var syncResult = native_.call('SQLDataControlConsumer_select', nativeParam, function( ++ result ++ ) { ++ if (result.status == 'success') { ++ args.successCallback(result['result'], result['requestId']); ++ } ++ if (result.status == 'error') { ++ if (args.errorCallback) { ++ var err = result['result']; ++ var e = new WebAPIException(err.name, err.message); ++ args.errorCallback(result['requestId'], e); + } - ); - // if you need synchronous result from native function using 'syncResult'. - } catch (e) { - throw e; + } - } + }); + - if (native_.isFailure(syncResult)) { - throw native_.getErrorObject(syncResult); - } ++ if (native_.isFailure(syncResult)) { ++ throw native_.getErrorObject(syncResult); + } }; - function MappedDataControlConsumer() { - // constructor of MappedDataControlConsumer + // constructor of MappedDataControlConsumer } MappedDataControlConsumer.prototype = new DataControlConsumerObject(); MappedDataControlConsumer.prototype.constructor = MappedDataControlConsumer; -MappedDataControlConsumer.prototype.addValue = function(reqId, key, value) { +MappedDataControlConsumer.prototype.addValue = function() { - var args = validator_.validateArgs(arguments, [ - {'name': 'reqId', 'type': types_.LONG}, - {'name': 'key', 'type': types_.STRING}, - {'name': 'value', 'type': types_.STRING}, - {'name': 'successCallback', 'type': types_.FUNCTION, optional: true, nullable: true}, - {'name': 'errorCallback', 'type': types_.FUNCTION, optional: true, nullable: true} - ]); - - var nativeParam = { - 'providerId': this.providerId, - 'dataId': this.dataId, - 'reqId': args.reqId, - 'key': args.key, - 'value': args.value - }; - - var syncResult = - native_.call('MappedDataControlConsumer_addValue', nativeParam, function(result) { - if (result.status == 'success') { - if (args.successCallback) { - args.successCallback(result['requestId']); - } - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); + var args = validator_.validateArgs(arguments, [ + { name: 'reqId', type: types_.LONG }, + { name: 'key', type: types_.STRING }, + { name: 'value', type: types_.STRING }, + { + name: 'successCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } ++ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var nativeParam = { + providerId: this.providerId, + dataId: this.dataId, + reqId: args.reqId, + key: args.key, + value: args.value + }; - try { - var syncResult = callNativeWithCallback( - 'MappedDataControlConsumer_addValue', - nativeParam, - function(result) { - if (result.status == 'success') { - if (args.successCallback) { - args.successCallback(result['requestId']); - } ++ ++ var syncResult = native_.call( ++ 'MappedDataControlConsumer_addValue', ++ nativeParam, ++ function(result) { ++ if (result.status == 'success') { ++ if (args.successCallback) { ++ args.successCallback(result['requestId']); + } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); - } ++ } ++ if (result.status == 'error') { ++ if (args.errorCallback) { ++ var err = result['result']; ++ var e = new WebAPIException(err.name, err.message); ++ args.errorCallback(result['requestId'], e); + } + } - ); - } catch (e) { - throw e; + } - } - }); - - if (native_.isFailure(syncResult)) { - throw native_.getErrorObject(syncResult); - } ++ ); + ++ if (native_.isFailure(syncResult)) { ++ throw native_.getErrorObject(syncResult); + } }; -MappedDataControlConsumer.prototype.removeValue = function( - reqId, - key, - value, - successCallback -) { +MappedDataControlConsumer.prototype.removeValue = function() { - var args = validator_.validateArgs(arguments, [ - {'name': 'reqId', 'type': types_.LONG}, - {'name': 'key', 'type': types_.STRING}, - {'name': 'value', 'type': types_.STRING}, - {'name': 'successCallback', 'type': types_.FUNCTION}, - {'name': 'errorCallback', 'type': types_.FUNCTION, optional: true, nullable: true} - ]); - - var nativeParam = { - 'providerId': this.providerId, - 'dataId': this.dataId, - 'reqId': args.reqId, - 'key': args.key, - 'value': args.value - }; - - var syncResult = - native_.call('MappedDataControlConsumer_removeValue', nativeParam, function(result) { - if (result.status == 'success') { - args.successCallback(result['requestId']); - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); + var args = validator_.validateArgs(arguments, [ + { name: 'reqId', type: types_.LONG }, + { name: 'key', type: types_.STRING }, + { name: 'value', type: types_.STRING }, + { name: 'successCallback', type: types_.FUNCTION }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var nativeParam = { + providerId: this.providerId, + dataId: this.dataId, + reqId: args.reqId, + key: args.key, + value: args.value + }; - try { - var syncResult = callNativeWithCallback( - 'MappedDataControlConsumer_removeValue', - nativeParam, - function(result) { - if (result.status == 'success') { - args.successCallback(result['requestId']); - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); - } ++ ++ var syncResult = native_.call( ++ 'MappedDataControlConsumer_removeValue', ++ nativeParam, ++ function(result) { ++ if (result.status == 'success') { ++ args.successCallback(result['requestId']); ++ } ++ if (result.status == 'error') { ++ if (args.errorCallback) { ++ var err = result['result']; ++ var e = new WebAPIException(err.name, err.message); ++ args.errorCallback(result['requestId'], e); + } + } - ); - } catch (e) { - throw e; + } - } - }); - - if (native_.isFailure(syncResult)) { - throw native_.getErrorObject(syncResult); - } ++ ); + ++ if (native_.isFailure(syncResult)) { ++ throw native_.getErrorObject(syncResult); + } }; -MappedDataControlConsumer.prototype.getValue = function(reqId, key, successCallback) { +MappedDataControlConsumer.prototype.getValue = function() { - var args = validator_.validateArgs(arguments, [ - {'name': 'reqId', 'type': types_.LONG}, - {'name': 'key', 'type': types_.STRING}, - {'name': 'successCallback', 'type': types_.FUNCTION}, - {'name': 'errorCallback', 'type': types_.FUNCTION, optional: true, nullable: true} - ]); - - var nativeParam = { - 'providerId': this.providerId, - 'dataId': this.dataId, - 'reqId': args.reqId, - 'key': args.key - }; - - var syncResult = - native_.call('MappedDataControlConsumer_getValue', nativeParam, function(result) { - if (result.status == 'success') { - args.successCallback(result['result'], result['requestId']); - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); + var args = validator_.validateArgs(arguments, [ + { name: 'reqId', type: types_.LONG }, + { name: 'key', type: types_.STRING }, + { name: 'successCallback', type: types_.FUNCTION }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var nativeParam = { + providerId: this.providerId, + dataId: this.dataId, + reqId: args.reqId, + key: args.key + }; - try { - var syncResult = callNativeWithCallback( - 'MappedDataControlConsumer_getValue', - nativeParam, - function(result) { - if (result.status == 'success') { - args.successCallback(result['result'], result['requestId']); - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); - } ++ ++ var syncResult = native_.call( ++ 'MappedDataControlConsumer_getValue', ++ nativeParam, ++ function(result) { ++ if (result.status == 'success') { ++ args.successCallback(result['result'], result['requestId']); ++ } ++ if (result.status == 'error') { ++ if (args.errorCallback) { ++ var err = result['result']; ++ var e = new WebAPIException(err.name, err.message); ++ args.errorCallback(result['requestId'], e); + } + } - ); - } catch (e) { - throw e; + } - } - }); - - if (native_.isFailure(syncResult)) { - throw native_.getErrorObject(syncResult); - } ++ ); + ++ if (native_.isFailure(syncResult)) { ++ throw native_.getErrorObject(syncResult); + } }; -MappedDataControlConsumer.prototype.updateValue = function( - reqId, - key, - oldValue, - newValue, - successCallback -) { +MappedDataControlConsumer.prototype.updateValue = function() { - var args = validator_.validateArgs(arguments, [ - {'name': 'reqId', 'type': types_.LONG}, - {'name': 'key', 'type': types_.STRING}, - {'name': 'oldValue', 'type': types_.STRING}, - {'name': 'newValue', 'type': types_.STRING}, - {'name': 'successCallback', 'type': types_.FUNCTION}, - {'name': 'errorCallback', 'type': types_.FUNCTION, optional: true, nullable: true} - ]); - - var nativeParam = { - 'providerId': this.providerId, - 'dataId': this.dataId, - 'reqId': args.reqId, - 'key': args.key, - 'oldValue': args.oldValue, - 'newValue': args.newValue - }; - - var syncResult = - native_.call('MappedDataControlConsumer_updateValue', nativeParam, function(result) { - if (result.status == 'success') { - args.successCallback(result['requestId']); - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); + var args = validator_.validateArgs(arguments, [ + { name: 'reqId', type: types_.LONG }, + { name: 'key', type: types_.STRING }, + { name: 'oldValue', type: types_.STRING }, + { name: 'newValue', type: types_.STRING }, + { name: 'successCallback', type: types_.FUNCTION }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var nativeParam = { + providerId: this.providerId, + dataId: this.dataId, + reqId: args.reqId, + key: args.key, + oldValue: args.oldValue, + newValue: args.newValue + }; - try { - var syncResult = callNativeWithCallback( - 'MappedDataControlConsumer_updateValue', - nativeParam, - function(result) { - if (result.status == 'success') { - args.successCallback(result['requestId']); - } - if (result.status == 'error') { - if (args.errorCallback) { - var err = result['result']; - var e = new WebAPIException(err.name, err.message); - args.errorCallback(result['requestId'], e); - } ++ ++ var syncResult = native_.call( ++ 'MappedDataControlConsumer_updateValue', ++ nativeParam, ++ function(result) { ++ if (result.status == 'success') { ++ args.successCallback(result['requestId']); ++ } ++ if (result.status == 'error') { ++ if (args.errorCallback) { ++ var err = result['result']; ++ var e = new WebAPIException(err.name, err.message); ++ args.errorCallback(result['requestId'], e); + } + } - ); - } catch (e) { - throw e; + } - } - }); - - if (native_.isFailure(syncResult)) { - throw native_.getErrorObject(syncResult); - } ++ ); + ++ if (native_.isFailure(syncResult)) { ++ throw native_.getErrorObject(syncResult); + } }; exports = new DataControlManager(); diff --cc src/download/download_api.js index c689ed2c,a1388d41..20536eab --- a/src/download/download_api.js +++ b/src/download/download_api.js @@@ -26,47 -25,79 +26,46 @@@ var downloadId = 0 var callbacks = {}; var requests = {}; -extension.setMessageListener(function(json) { - var result = JSON_.parse(json); - var callback = callbacks[result.callbackId]; - //privUtils_.log("PostMessage received: " + result.status); +function DownloadManagerChangeCallback(result) { - var callback = callbacks[result.downloadId]; - - if (!callback) { - privUtils_.log('Ignoring unknown callback: ' + result.downloadId); - return; - } - setTimeout(function() { - if (result.status == 'progress') { - if (callback.onprogress) { - var receivedSize = result.receivedSize; - var totalSize = result.totalSize; - callback.onprogress(result.downloadId, receivedSize, totalSize); - } - } else if (result.status == 'paused') { - if (callback.onpaused) { - callback.onpaused(result.downloadId); - } - } else if (result.status == 'canceled') { - if (callback.oncanceled) { - callback.oncanceled(result.downloadId); - delete callbacks[result.downloadId]; - } - } else if (result.status == 'completed') { - if (callback.oncompleted) { - var fullPath = result.fullPath; - callback.oncompleted(result.downloadId, fullPath); - delete callbacks[result.downloadId]; - } - } else if (result.status == 'error') { - if (callback.onfailed) { - callback.onfailed(result.downloadId, - new WebAPIException(result.error)); - delete callbacks[result.downloadId]; - } ++ var callback = callbacks[result.downloadId]; + + if (!callback) { - privUtils_.log('Ignoring unknown callback: ' + result.callbackId); ++ privUtils_.log('Ignoring unknown callback: ' + result.downloadId); + return; } - }, 0); + setTimeout(function() { + if (result.status == 'progress') { + if (callback.onprogress) { + var receivedSize = result.receivedSize; + var totalSize = result.totalSize; - callback.onprogress(result.callbackId, receivedSize, totalSize); ++ callback.onprogress(result.downloadId, receivedSize, totalSize); + } + } else if (result.status == 'paused') { + if (callback.onpaused) { - callback.onpaused(result.callbackId); ++ callback.onpaused(result.downloadId); + } + } else if (result.status == 'canceled') { + if (callback.oncanceled) { - callback.oncanceled(result.callbackId); ++ callback.oncanceled(result.downloadId); ++ delete callbacks[result.downloadId]; + } + } else if (result.status == 'completed') { + if (callback.oncompleted) { + var fullPath = result.fullPath; - callback.oncompleted(result.callbackId, fullPath); ++ callback.oncompleted(result.downloadId, fullPath); ++ delete callbacks[result.downloadId]; + } + } else if (result.status == 'error') { + if (callback.onfailed) { - callback.onfailed(result.callbackId, new WebAPIException(result.error)); ++ callback.onfailed(result.downloadId, new WebAPIException(result.error)); ++ delete callbacks[result.downloadId]; + } + } + }, 0); -}); - -function nextCallbackId() { - return ++callbackId; } -function callNative(cmd, args) { - var json = { cmd: cmd, args: args }; - var argjson = JSON_.stringify(json); - var resultString = extension.internal.sendSyncMessage(argjson); - var result = JSON_.parse(resultString); - - if (typeof result !== 'object') { - throw new WebAPIException(WebAPIException.UNKNOWN_ERR); - } - - if (result.status == 'success') { - if (result.result) { - return result.result; - } - return true; - } else if (result.status == 'error') { - var err = result.error; - if (err) { - throw new WebAPIException(err); - } - return false; - } -} - -function callNativeWithCallback(cmd, args, callback) { - if (callback) { - var id = nextCallbackId(); - args.callbackId = id; - callbacks[id] = callback; - } - - return callNative(cmd, args); +function nextDownloadId() { - return ++downloadId; ++ return ++downloadId; } function SetReadOnlyProperty(obj, n, v) { @@@ -162,120 -192,134 +160,136 @@@ function DownloadManager() } DownloadManager.prototype.start = function() { - var args = validator_.validateArgs(arguments, [ - {'name' : 'downloadRequest', 'type': types_.PLATFORM_OBJECT, 'values': tizen.DownloadRequest}, - {'name' : 'downloadCallback', 'type': types_.LISTENER, - 'values' : ['onprogress', 'onpaused', 'oncanceled', 'oncompleted', 'onfailed'], - optional: true, nullable: true} - ]); - - var nativeParam = { - 'url': args.downloadRequest.url, - 'destination': args.downloadRequest.destination, - 'fileName': args.downloadRequest.fileName, - 'networkType': args.downloadRequest.networkType, - 'httpHeader': args.downloadRequest.httpHeader, - 'downloadId': nextDownloadId() - }; - - if (args.downloadCallback) { - this.setListener(nativeParam.downloadId, args.downloadCallback); - } - - var result = native_.callSync('DownloadManager_start', nativeParam); - - if (native_.isFailure(result)) { - if ('NetworkError' === result.error.name) { - return -1; + var args = validator_.validateArgs(arguments, [ + { + name: 'downloadRequest', + type: types_.PLATFORM_OBJECT, + values: tizen.DownloadRequest + }, + { + name: 'downloadCallback', + type: types_.LISTENER, + values: ['onprogress', 'onpaused', 'oncanceled', 'oncompleted', 'onfailed'], + optional: true, + nullable: true + } + ]); + + var nativeParam = { + url: args.downloadRequest.url, + destination: args.downloadRequest.destination, + fileName: args.downloadRequest.fileName, + networkType: args.downloadRequest.networkType, + httpHeader: args.downloadRequest.httpHeader, - callbackId: nextCallbackId() ++ downloadId: nextDownloadId() + }; + + if (args.downloadCallback) { - this.setListener(nativeParam.callbackId, args.downloadCallback); ++ this.setListener(nativeParam.downloadId, args.downloadCallback); + } + - try { - callNative('DownloadManager_start', nativeParam); - } catch (e) { - if ('NetworkError' === e.name) { ++ var result = native_.callSync('DownloadManager_start', nativeParam); ++ ++ if (native_.isFailure(result)) { ++ if ('NetworkError' === result.error.name) { + return -1; + } - throw e; ++ throw native_.getErrorObject(result); } - throw native_.getErrorObject(result); - } - requests[nativeParam.downloadId] = args.downloadRequest; - requests[nativeParam.callbackId] = args.downloadRequest; ++ requests[nativeParam.downloadId] = args.downloadRequest; - return nativeParam.downloadId; - return nativeParam.callbackId; ++ return nativeParam.downloadId; }; DownloadManager.prototype.cancel = function() { - var args = validator_.validateArgs(arguments, [ - {name: 'downloadId', type: types_.LONG, 'nullable': false, 'optional': false} - ]); + var args = validator_.validateArgs(arguments, [ + { name: 'downloadId', type: types_.LONG, nullable: false, optional: false } + ]); - var nativeParam = { - 'downloadId': args.downloadId - }; + var nativeParam = { + downloadId: args.downloadId + }; - if (typeof requests[args.downloadId] === 'undefined') - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, - 'the identifier does not match any download operation in progress'); + if (typeof requests[args.downloadId] === 'undefined') + throw new WebAPIException( + WebAPIException.INVALID_VALUES_ERR, + 'the identifier does not match any download operation in progress' + ); - var result = native_.callSync('DownloadManager_cancel', nativeParam); - try { - callNative('DownloadManager_cancel', nativeParam); - } catch (e) { - throw e; ++ var result = native_.callSync('DownloadManager_cancel', nativeParam); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); + } }; DownloadManager.prototype.pause = function() { - var args = validator_.validateArgs(arguments, [ - {'name': 'downloadId', 'type': types_.LONG, 'nullable': false, 'optional': false} - ]); + var args = validator_.validateArgs(arguments, [ + { name: 'downloadId', type: types_.LONG, nullable: false, optional: false } + ]); - var nativeParam = { - 'downloadId': args.downloadId - }; + var nativeParam = { + downloadId: args.downloadId + }; - if (typeof requests[args.downloadId] === 'undefined') - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, - 'the identifier does not match any download operation in progress'); + if (typeof requests[args.downloadId] === 'undefined') + throw new WebAPIException( + WebAPIException.INVALID_VALUES_ERR, + 'the identifier does not match any download operation in progress' + ); - var result = native_.callSync('DownloadManager_pause', nativeParam); - try { - callNative('DownloadManager_pause', nativeParam); - } catch (e) { - throw e; ++ var result = native_.callSync('DownloadManager_pause', nativeParam); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); + } }; DownloadManager.prototype.resume = function() { - var args = validator_.validateArgs(arguments, [ - {'name' : 'downloadId', 'type': types_.LONG, 'nullable': false, 'optional': false} - ]); + var args = validator_.validateArgs(arguments, [ + { name: 'downloadId', type: types_.LONG, nullable: false, optional: false } + ]); - var nativeParam = { - 'downloadId': args.downloadId - }; + var nativeParam = { + downloadId: args.downloadId + }; - if (typeof requests[args.downloadId] === 'undefined') - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, - 'the identifier does not match any download operation in progress'); + if (typeof requests[args.downloadId] === 'undefined') + throw new WebAPIException( + WebAPIException.INVALID_VALUES_ERR, + 'the identifier does not match any download operation in progress' + ); - var result = native_.callSync('DownloadManager_resume', nativeParam); - try { - callNative('DownloadManager_resume', nativeParam); - } catch (e) { - throw e; ++ var result = native_.callSync('DownloadManager_resume', nativeParam); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); + } }; DownloadManager.prototype.getState = function() { - var args = validator_.validateArgs(arguments, [ - {'name' : 'downloadId', 'type': types_.LONG, 'nullable': false, 'optional': false} - ]); - - var nativeParam = { - 'downloadId': args.downloadId - }; - - if (typeof requests[args.downloadId] === 'undefined') - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, - 'the identifier does not match any download operation in progress'); - - var result = native_.callSync('DownloadManager_getState', nativeParam); - - if (native_.isSuccess(result)) { - return native_.getResultObject(result); - } else { - throw native_.getErrorObject(result); - } + var args = validator_.validateArgs(arguments, [ + { name: 'downloadId', type: types_.LONG, nullable: false, optional: false } + ]); + + var nativeParam = { + downloadId: args.downloadId + }; + + if (typeof requests[args.downloadId] === 'undefined') + throw new WebAPIException( + WebAPIException.INVALID_VALUES_ERR, + 'the identifier does not match any download operation in progress' + ); + - try { - return callNative('DownloadManager_getState', nativeParam); - } catch (e) { - throw e; ++ var result = native_.callSync('DownloadManager_getState', nativeParam); ++ ++ if (native_.isSuccess(result)) { ++ return native_.getResultObject(result); ++ } else { ++ throw native_.getErrorObject(result); + } }; DownloadManager.prototype.getDownloadRequest = function() { @@@ -291,38 -337,38 +307,43 @@@ }; DownloadManager.prototype.getMIMEType = function() { - var args = validator_.validateArgs(arguments, [ - {'name' : 'downloadId', 'type': types_.LONG, 'nullable': false, 'optional': false} - ]); - - var nativeParam = { - 'downloadId': args.downloadId - }; - - if (typeof requests[args.downloadId] === 'undefined') - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, - 'the identifier does not match any download operation in progress'); - - var result = native_.callSync('DownloadManager_getMIMEType', nativeParam); - - if (native_.isSuccess(result)) { - return native_.getResultObject(result); - } else { - throw native_.getErrorObject(result); - } + var args = validator_.validateArgs(arguments, [ + { name: 'downloadId', type: types_.LONG, nullable: false, optional: false } + ]); + + var nativeParam = { + downloadId: args.downloadId + }; + + if (typeof requests[args.downloadId] === 'undefined') + throw new WebAPIException( + WebAPIException.INVALID_VALUES_ERR, + 'the identifier does not match any download operation in progress' + ); + - try { - return callNative('DownloadManager_getMIMEType', nativeParam); - } catch (e) { - throw e; ++ var result = native_.callSync('DownloadManager_getMIMEType', nativeParam); ++ ++ if (native_.isSuccess(result)) { ++ return native_.getResultObject(result); ++ } else { ++ throw native_.getErrorObject(result); + } }; DownloadManager.prototype.setListener = function() { - var args = validator_.validateArgs(arguments, [ - {'name' : 'downloadId', 'type': types_.LONG}, - {'name' : 'downloadCallback', 'type': types_.LISTENER, - 'values' : ['onprogress', 'onpaused', 'oncanceled', 'oncompleted', 'onfailed']} - ]); - - if (!native_.isListenerSet(DOWNLOAD_MANAGER_LISTENER_ID)) { - native_.addListener(DOWNLOAD_MANAGER_LISTENER_ID, DownloadManagerChangeCallback); - } - callbacks[args.downloadId] = args.downloadCallback; + var args = validator_.validateArgs(arguments, [ + { name: 'downloadId', type: types_.LONG }, + { + name: 'downloadCallback', + type: types_.LISTENER, + values: ['onprogress', 'onpaused', 'oncanceled', 'oncompleted', 'onfailed'] + } + ]); + ++ if (!native_.isListenerSet(DOWNLOAD_MANAGER_LISTENER_ID)) { ++ native_.addListener(DOWNLOAD_MANAGER_LISTENER_ID, DownloadManagerChangeCallback); ++ } + callbacks[args.downloadId] = args.downloadCallback; }; - exports = new DownloadManager(); + exports = new DownloadManager(); diff --cc src/filesystem/js/file_stream.js index 92194a13,a81ead30..abc389d1 --- a/src/filesystem/js/file_stream.js +++ b/src/filesystem/js/file_stream.js @@@ -104,23 -102,30 +102,23 @@@ function _checkWriteAccess(mode) } /* returns array of numbers */ - function string_to_array( str ) { - var output = []; - var len = str.length; - for( var i = 0; i < len; i++ ) { - output.push( str.charCodeAt(i) ); - } - return output; -function string_to_binary(str) { ++function string_to_array(str) { + var output = []; + var len = str.length; - var c; + for (var i = 0; i < len; i++) { - // decode unicode codepoint U+0100 as zero byte - c = str.charCodeAt(i); - output.push(c == 0x100 ? 0 : c); ++ output.push(str.charCodeAt(i)); + } + return output; } /* receives array of numbers, returns string */ - function array_to_string( data ) { - var output = ""; - var len = data.length; - for( var i = 0; i < len; i++ ) { - output += String.fromCharCode(data[i] & 0xFF); // conversion to octet - } - return output; -function binary_to_string(data) { ++function array_to_string(data) { + var output = ''; + var len = data.length; - // endecode zero byte as unicode codepoint U+0100 - var zero = String.fromCharCode(0x100); - var b; + for (var i = 0; i < len; i++) { - b = data[i] & 0xff; // conversion to octet - output += b == 0 ? zero : String.fromCharCode(b); ++ output += String.fromCharCode(data[i] & 0xff); // conversion to octet + } + return output; } function read() { @@@ -181,144 -192,138 +185,154 @@@ FileStream.prototype.read = function() }; function readBytes() { - var args = validator_.validateArgs(arguments, [ - { - name: 'byteCount', - type: types_.LONG - } - ]); + var args = validator_.validateArgs(arguments, [ + { + name: 'byteCount', + type: types_.LONG + } + ]); - _checkClosed(this); - _checkReadAccess(this._mode); + _checkClosed(this); + _checkReadAccess(this._mode); - if (args.byteCount <= 0) { - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, - 'Argument "byteCount" must be greater than 0'); - } + if (args.byteCount <= 0) { + throw new WebAPIException( + WebAPIException.INVALID_VALUES_ERR, + 'Argument "byteCount" must be greater than 0' + ); + } - var _count = this.bytesAvailable; + var _count = this.bytesAvailable; - var data = { - location: commonFS_.toRealPath(this._file.fullPath), - offset: this.position || 0, - length: (args.byteCount > _count ? _count : args.byteCount) - }; + var data = { + location: commonFS_.toRealPath(this._file.fullPath), + offset: this.position || 0, + length: args.byteCount > _count ? _count : args.byteCount + }; - var result = native_.callSync('File_readBytes', data); - if (native_.isFailure(result)) { - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Could not read'); - } + var result = native_.callSync('File_readBytes', data); + if (native_.isFailure(result)) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Could not read'); + } - var decoded = string_to_array( native_.getResultObject(result) ); - var decoded = string_to_binary(native_.getResultObject(result)); ++ var decoded = string_to_array(native_.getResultObject(result)); - if (decoded.length) { - can_change_size = true; - this.position += decoded.length; - can_change_size = false; - } else { - this.position += 1; // Set EOF - } + if (decoded.length) { + can_change_size = true; + this.position += decoded.length; + can_change_size = false; + } else { + this.position += 1; // Set EOF + } - return decoded; - }; + return decoded; + } FileStream.prototype.readBytes = function() { - return readBytes.apply(this, arguments); + return readBytes.apply(this, arguments); }; FileStream.prototype.readBase64 = function() { - return base64_encode(readBytes.apply(this, arguments)); - } + return base64_encode(readBytes.apply(this, arguments)); + }; - function check_characters_outside_latin1( str ) { - var len = str.length; - for( var i = 0; i < len; ++i ) { - if( str.charCodeAt(i) > 255 ) { - throw new WebAPIException(WebAPIException.IO_ERR, 'Invalid character at '+i+': '+str.charAt(i)+' (not ISO-8859-1)'); ++function check_characters_outside_latin1(str) { ++ var len = str.length; ++ for (var i = 0; i < len; ++i) { ++ if (str.charCodeAt(i) > 255) { ++ throw new WebAPIException( ++ WebAPIException.IO_ERR, ++ 'Invalid character at ' + i + ': ' + str.charAt(i) + ' (not ISO-8859-1)' ++ ); ++ } + } - } +} + function write() { - var args = validator_.validateArgs(arguments, [ - { - name: 'stringData', - type: types_.STRING + var args = validator_.validateArgs(arguments, [ + { + name: 'stringData', + type: types_.STRING + } + ]); + + _checkClosed(this); + _checkWriteAccess(this._mode); + + if (!arguments.length) { + throw new WebAPIException( + WebAPIException.NOT_FOUND_ERR, + 'Argument "stringData" missing' + ); + } + + var data = { + location: commonFS_.toRealPath(this._file.fullPath), + encoding: this._encoding, + offset: this.position, + data: args.stringData, + rewrite: this._rewrite + }; + ++ if (data.encoding == 'iso-8859-1') { ++ check_characters_outside_latin1(data.data); + } - ]); - - _checkClosed(this); - _checkWriteAccess(this._mode); - - if (!arguments.length) { - throw new WebAPIException(WebAPIException.NOT_FOUND_ERR, - 'Argument "stringData" missing'); - } - - var data = { - location: commonFS_.toRealPath(this._file.fullPath), - encoding: this._encoding, - offset: this.position, - data: args.stringData, - rewrite: this._rewrite - }; - - if( data.encoding == "iso-8859-1") { - check_characters_outside_latin1(data.data); - } - - var result = native_.callSync('File_writeString', data); - - if (native_.isFailure(result)) { - throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write'); - } - can_change_size = true; - this.position = this.position + args.stringData.length; - can_change_size = false; - this._rewrite = false; - }; ++ + var result = native_.callSync('File_writeString', data); + + if (native_.isFailure(result)) { + throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write'); + } + can_change_size = true; + this.position = this.position + args.stringData.length; + can_change_size = false; + this._rewrite = false; + } FileStream.prototype.write = function() { - write.apply(this, arguments); + write.apply(this, arguments); }; function writeBytes() { - var args = validator_.validateArgs(arguments, [ - { - name: 'byteData', - type: types_.ARRAY, - values: undefined /* was types_.OCTET, but checking moved to array_to_string for performance */ + var args = validator_.validateArgs(arguments, [ + { + name: 'byteData', + type: types_.ARRAY, - values: undefined /* was types_.OCTET, but checking moved - to binary_to_string for performance */ ++ values: undefined /* was types_.OCTET, but checking moved to ++ array_to_string for performance */ + } + ]); + + _checkClosed(this); + _checkWriteAccess(this._mode); + + if (!arguments.length) { + throw new WebAPIException( + WebAPIException.TYPE_MISMATCH_ERR, + 'Argument "byteData" missing' + ); } - ]); - - _checkClosed(this); - _checkWriteAccess(this._mode); - - if (!arguments.length) { - throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, - 'Argument "byteData" missing'); - } - - var data = { - location: commonFS_.toRealPath(this._file.fullPath), - offset: this.position, - data: array_to_string(args.byteData), - rewrite: this._rewrite, - }; - - var result = native_.callSync('File_writeBytes', data); - - if (native_.isFailure(result)) { - throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write'); - } - can_change_size = true; - this.position = this.position + args.byteData.length; - can_change_size = false; - this._rewrite = false; - }; + + var data = { + location: commonFS_.toRealPath(this._file.fullPath), + offset: this.position, - data: binary_to_string(args.byteData), ++ data: array_to_string(args.byteData), + rewrite: this._rewrite + }; + + var result = native_.callSync('File_writeBytes', data); + + if (native_.isFailure(result)) { + throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write'); + } + can_change_size = true; + this.position = this.position + args.byteData.length; + can_change_size = false; + this._rewrite = false; + } FileStream.prototype.writeBytes = function() { - writeBytes.apply(this, arguments); + writeBytes.apply(this, arguments); }; function writeBase64() { diff --cc src/humanactivitymonitor/humanactivitymonitor_api.js index 01da87cf,50f78562..4f635f48 --- a/src/humanactivitymonitor/humanactivitymonitor_api.js +++ b/src/humanactivitymonitor/humanactivitymonitor_api.js @@@ -74,43 -74,31 +74,43 @@@ var ActivityAccuracy = }; var SleepStatus = { - ASLEEP: 'ASLEEP', - AWAKE: 'AWAKE' + ASLEEP: 'ASLEEP', + AWAKE: 'AWAKE' }; +var GestureType = { - GESTURE_DOUBLE_TAP : 'GESTURE_DOUBLE_TAP', - GESTURE_MOVE_TO_EAR : 'GESTURE_MOVE_TO_EAR', - GESTURE_NO_MOVE : 'GESTURE_NO_MOVE', - GESTURE_PICK_UP : 'GESTURE_PICK_UP', - GESTURE_SHAKE : 'GESTURE_SHAKE', - GESTURE_SNAP : 'GESTURE_SNAP', - GESTURE_TILT : 'GESTURE_TILT', - GESTURE_TURN_FACE_DOWN : 'GESTURE_TURN_FACE_DOWN', - GESTURE_WRIST_UP : 'GESTURE_WRIST_UP', ++ GESTURE_DOUBLE_TAP: 'GESTURE_DOUBLE_TAP', ++ GESTURE_MOVE_TO_EAR: 'GESTURE_MOVE_TO_EAR', ++ GESTURE_NO_MOVE: 'GESTURE_NO_MOVE', ++ GESTURE_PICK_UP: 'GESTURE_PICK_UP', ++ GESTURE_SHAKE: 'GESTURE_SHAKE', ++ GESTURE_SNAP: 'GESTURE_SNAP', ++ GESTURE_TILT: 'GESTURE_TILT', ++ GESTURE_TURN_FACE_DOWN: 'GESTURE_TURN_FACE_DOWN', ++ GESTURE_WRIST_UP: 'GESTURE_WRIST_UP' +}; + function convertActivityData(type, data) { - switch (type) { + switch (type) { case HumanActivityType.PEDOMETER: - return new HumanActivityPedometerData(data); + return new HumanActivityPedometerData(data); case ACCUMULATIVE_PEDOMETER_DATA: - return new HumanActivityAccumulativePedometerData(data); + return new HumanActivityAccumulativePedometerData(data); case HumanActivityType.WRIST_UP: - return null; + return null; case HumanActivityType.HRM: - return new HumanActivityHRMData(data); + return new HumanActivityHRMData(data); case HumanActivityType.GPS: - var gpsInfo = []; - for (var i = 0, max = data.gpsInfo.length; i < max; i++) { - gpsInfo.push(new HumanActivityGPSInfo(data.gpsInfo[i])); - } - return new HumanActivityGPSInfoArray(gpsInfo); + var gpsInfo = []; + for (var i = 0, max = data.gpsInfo.length; i < max; i++) { + gpsInfo.push(new HumanActivityGPSInfo(data.gpsInfo[i])); + } + return new HumanActivityGPSInfoArray(gpsInfo); case HumanActivityType.SLEEP_MONITOR: - return new HumanActivitySleepMonitorData(data); + return new HumanActivitySleepMonitorData(data); default: - utils_.error('Uknown human activity type: ' + type); - } + utils_.error('Uknown human activity type: ' + type); + } } function createRecorderData(func, data) { @@@ -219,25 -234,16 +246,16 @@@ HumanActivityMonitorManager.prototype.g }; function startListener(listenerId, listener, method, data) { - if (!native_.isListenerSet(listenerId)) { - var result = native_.callSync(method, data); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + if (!native_.isListenerSet(listenerId)) { + var result = native_.callSync(method, data); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } } - } - // always set the listener, if it's another call to startListener() overwrite the old one - native_.addListener(listenerId, listener); - // always set the listener, if it's another call to startListener() - // overwrite the old one ++ // always set the listener ++ //if it's another call to startListener() overwrite the old one + native_.addListener(listenerId, listener); } function checkPrivilegesForMethod(method, type) { @@@ -287,107 -295,122 +307,138 @@@ function GPSCallback(result) } HumanActivityMonitorManager.prototype.start = function(type, changedCallback) { - var args = validator_.validateArgs(arguments, [ - {name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityType)}, - {name: 'changedCallback', type: types_.FUNCTION, optional: true, nullable: true}, - {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}, - {name: 'options', type : types_.DICTIONARY, optional : true, nullable : true} - ]); - - if (HumanActivityType.WRIST_UP === args.type) { - utils_.warn('DEPRECATION WARNING: HumanActivityType.WRIST_UP is deprecated since Tizen 4.0. ' - + 'Use GestureType and addGestureRecognitionListener to monitor WRIST_UP gesture'); - } - - var listenerId = 'HumanActivityMonitor_' + args.type; - var optionsAttributes = ["callbackInterval", "sampleInterval"], options = args.options || {}; - - var callbackInterval = null, sampleInterval = null; - - switch (args.type) { - case HumanActivityType.GPS: - callbackInterval = !type_.isNullOrUndefined(options[optionsAttributes[0]]) ? - options[optionsAttributes[0]] : 150000; - sampleInterval = !type_.isNullOrUndefined(options[optionsAttributes[1]]) ? - options[optionsAttributes[1]] : 1000; - break; - case HumanActivityType.HRM: - callbackInterval = !type_.isNullOrUndefined(options[optionsAttributes[0]]) ? - options[optionsAttributes[0]] : 100; - if (callbackInterval < 10 || callbackInterval > 1000) { - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, - 'callbackInterval is out of range'); - } - break; - } - - var listener = null; - switch (args.type) { + var args = validator_.validateArgs(arguments, [ + { name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityType) }, + { + name: 'changedCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }, + { name: 'options', type: types_.DICTIONARY, optional: true, nullable: true } + ]); + ++ if (HumanActivityType.WRIST_UP === args.type) { ++ utils_.warn( ++ 'DEPRECATION WARNING: HumanActivityType.WRIST_UP is deprecated since ' + ++ 'Tizen 4.0. Use GestureType and addGestureRecognitionListener to ' + ++ 'monitor WRIST_UP gesture' ++ ); ++ } ++ + var listenerId = 'HumanActivityMonitor_' + args.type; + var optionsAttributes = ['callbackInterval', 'sampleInterval'], + options = args.options || {}; + + var callbackInterval = null, + sampleInterval = null; + + switch (args.type) { + case HumanActivityType.GPS: + callbackInterval = !type_.isNullOrUndefined(options[optionsAttributes[0]]) + ? options[optionsAttributes[0]] + : 150000; + sampleInterval = !type_.isNullOrUndefined(options[optionsAttributes[1]]) + ? options[optionsAttributes[1]] + : 1000; + break; + case HumanActivityType.HRM: + callbackInterval = !type_.isNullOrUndefined(options[optionsAttributes[0]]) + ? options[optionsAttributes[0]] + : 100; + if (callbackInterval < 10 || callbackInterval > 1000) { + throw new WebAPIException( + WebAPIException.INVALID_VALUES_ERR, + 'callbackInterval is out of range' + ); + } + break; + } + + var listener = null; + switch (args.type) { case HumanActivityType.PEDOMETER: - listener = pedometerCallback; - break; + listener = pedometerCallback; + break; case HumanActivityType.GPS: - listener = GPSCallback; - break; + listener = GPSCallback; + break; default: - listener = function(result) { - native_.callIfPossible(args.changedCallback, convertActivityData(args.type, result)); - }; - } - - utils_.log("callbackInterval = " + callbackInterval + ", sampleInterval = " + sampleInterval); - startListener(listenerId, - listener, - 'HumanActivityMonitorManager_start', - { type: args.type, - listenerId: listenerId, - callbackInterval: callbackInterval, - sampleInterval: sampleInterval - } - ); - - if (HumanActivityType.PEDOMETER === args.type) { - pedometerListener = args.changedCallback; - } - - if (HumanActivityType.GPS === args.type) { - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - } else { - native_.callIfPossible(args.changedCallback, convertActivityData(args.type, result)); - } - }; + listener = function(result) { + native_.callIfPossible( + args.changedCallback, + convertActivityData(args.type, result) + ); + }; + } + + utils_.log( + 'callbackInterval = ' + callbackInterval + ', sampleInterval = ' + sampleInterval + ); + startListener(listenerId, listener, 'HumanActivityMonitorManager_start', { + type: args.type, + listenerId: listenerId, + callbackInterval: callbackInterval, + sampleInterval: sampleInterval + }); + + if (HumanActivityType.PEDOMETER === args.type) { + pedometerListener = args.changedCallback; + } - GPSListener = callback; - } + if (HumanActivityType.GPS === args.type) { + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible( + args.errorCallback, + native_.getErrorObject(result) + ); + } else { + native_.callIfPossible( + args.changedCallback, + convertActivityData(args.type, result) + ); + } + }; + + GPSListener = callback; + } }; HumanActivityMonitorManager.prototype.stop = function(type) { - var args = validator_.validateArgs(arguments, [ - {name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityType)} - ]); - - if (HumanActivityType.WRIST_UP === args.type) { - utils_.warn('DEPRECATION WARNING: HumanActivityType.WRIST_UP is deprecated since Tizen 4.0. ' - + 'Use GestureType and addGestureRecognitionListener to monitor WRIST_UP gesture'); - } - - if (HumanActivityType.PEDOMETER === args.type) { - stopListener('HumanActivityMonitor_PEDOMETER', - 'HumanActivityMonitorManager_stop', - { type: HumanActivityType.PEDOMETER }, - pedometerListener && !accumulativePedometerListener); - pedometerListener = null; - } else { - stopListener('HumanActivityMonitor_' + args.type, - 'HumanActivityMonitorManager_stop', - { type: args.type }, true); - } - - if (HumanActivityType.GPS === args.type) { - GPSListener = null; - } + var args = validator_.validateArgs(arguments, [ + { name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityType) } + ]); + ++ if (HumanActivityType.WRIST_UP === args.type) { ++ utils_.warn( ++ 'DEPRECATION WARNING: HumanActivityType.WRIST_UP is deprecated since ' + ++ 'Tizen 4.0. Use GestureType and addGestureRecognitionListener to ' + ++ 'monitor WRIST_UP gesture' ++ ); ++ } ++ + if (HumanActivityType.PEDOMETER === args.type) { + stopListener( + 'HumanActivityMonitor_PEDOMETER', + 'HumanActivityMonitorManager_stop', + { type: HumanActivityType.PEDOMETER }, + pedometerListener && !accumulativePedometerListener + ); + pedometerListener = null; + } else { + stopListener( + 'HumanActivityMonitor_' + args.type, + 'HumanActivityMonitorManager_stop', + { type: args.type }, + true + ); + } + + if (HumanActivityType.GPS === args.type) { + GPSListener = null; + } }; HumanActivityMonitorManager.prototype.setAccumulativePedometerListener = function() { @@@ -493,221 -532,85 +560,262 @@@ HumanActivityMonitorManager.prototype.s }; HumanActivityMonitorManager.prototype.readRecorderData = function() { - var args = validator_.validateArgs(arguments, [ - {name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityRecorderType)}, - {name: 'query', type : types_.DICTIONARY, optional: false, nullable: true}, - {name: 'successCallback', type: types_.FUNCTION}, - {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} - ]); - - var callArgs = {}; - - if (args.query) { - if ((args.query.startTime && MIN_QUERY_TIME > args.query.startTime) || - (args.query.endTime && MIN_QUERY_TIME > args.query.endTime) || - (args.query.anchorTime && MIN_QUERY_TIME > args.query.anchorTime) || - (args.query.interval && MIN_QUERY_INTERVAL > args.query.interval) || - (args.query.startTime && args.query.endTime && args.query.startTime > args.query.endTime)) { - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Invalid query value'); - } - } - - callArgs.options = args.options; - callArgs.type = args.type; - callArgs.query = args.query; - - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - } else { - var array = convertActivityRecorderData(args.type, native_.getResultObject(result)); - args.successCallback(array); + var args = validator_.validateArgs(arguments, [ + { + name: 'type', + type: types_.ENUM, + values: Object.keys(HumanActivityRecorderType) + }, + { name: 'query', type: types_.DICTIONARY, optional: false, nullable: true }, + { name: 'successCallback', type: types_.FUNCTION }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var callArgs = {}; + + if (args.query) { + if ( + (args.query.startTime && MIN_QUERY_TIME > args.query.startTime) || + (args.query.endTime && MIN_QUERY_TIME > args.query.endTime) || + (args.query.anchorTime && MIN_QUERY_TIME > args.query.anchorTime) || + (args.query.interval && MIN_QUERY_INTERVAL > args.query.interval) || + (args.query.startTime && + args.query.endTime && + args.query.startTime > args.query.endTime) + ) { + throw new WebAPIException( + WebAPIException.INVALID_VALUES_ERR, + 'Invalid query value' + ); + } } - }; - var result = native_.call('HumanActivityMonitorManager_readRecorderData', callArgs, callback); + callArgs.options = args.options; + callArgs.type = args.type; + callArgs.query = args.query; + + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + } else { + var array = convertActivityRecorderData( + args.type, + native_.getResultObject(result) + ); + args.successCallback(array); + } + }; + + var result = native_.call( + 'HumanActivityMonitorManager_readRecorderData', + callArgs, + callback + ); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } }; +HumanActivityMonitorManager.prototype.isGestureSupported = function() { - var args = validator_.validateMethod(arguments, [{ - name : 'type', - type: types_.ENUM, - values: Object.keys(GestureType) - } - ]); - - var callArgs = {}; - callArgs.type = args.type; - - var result = native_.callSync('GestureManager_isGestureSupported', callArgs); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } - - return native_.getResultObject(result); ++ var args = validator_.validateMethod(arguments, [ ++ { ++ name: 'type', ++ type: types_.ENUM, ++ values: Object.keys(GestureType) ++ } ++ ]); ++ ++ var callArgs = {}; ++ callArgs.type = args.type; ++ ++ var result = native_.callSync('GestureManager_isGestureSupported', callArgs); ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } ++ ++ return native_.getResultObject(result); +}; + +function GestureListenerManager(native, listenerName) { - this.listeners = {}; - //below maps keep information about number of registered listeners for the specific type - //there are two maps as one keeps information about listeners which should be always called - //and one keeps information about number of the listeners which should be called only - //if power-saving mode is off - this.typeCountMapDefault = {}; - this.typeCountMapAlwaysOn = {}; - this.nextId = 1; - this.nativeSet = false; - this.native = native; - this.listenerName = listenerName; - for (var type in GestureType) { - this.typeCountMapDefault[type] = this.typeCountMapAlwaysOn[type] = 0; - } - }; ++ this.listeners = {}; ++ //below maps keep information about number of registered listeners for the specific ++ //type there are two maps as one keeps information about listeners which should be ++ //always called and one keeps information about number of the listeners which should ++ //be called only if power-saving mode is off ++ this.typeCountMapDefault = {}; ++ this.typeCountMapAlwaysOn = {}; ++ this.nextId = 1; ++ this.nativeSet = false; ++ this.native = native; ++ this.listenerName = listenerName; ++ for (var type in GestureType) { ++ this.typeCountMapDefault[type] = this.typeCountMapAlwaysOn[type] = 0; ++ } ++} + +GestureListenerManager.prototype.onListenerCalled = function(msg) { - var d = undefined; - var result = undefined; - var alwaysOn = msg.alwaysOn; - switch (msg.action) { ++ var d = undefined; ++ var result = undefined; ++ var alwaysOn = msg.alwaysOn; ++ switch (msg.action) { + case 'ondetect': - d = new GestureData(this.native.getResultObject(msg)); - break; ++ d = new GestureData(this.native.getResultObject(msg)); ++ break; + case 'onerror': - d = this.native.getErrorObject(msg); - break; ++ d = this.native.getErrorObject(msg); ++ break; + default: - utils_.log('Unknown mode: ' + msg.action); - return; - } ++ utils_.log('Unknown mode: ' + msg.action); ++ return; ++ } + - for (var watchId in this.listeners) { - if (this.listeners.hasOwnProperty(watchId)) { - var listener = this.listeners[watchId]; - var call = alwaysOn ? listener.alwaysOn : true; - if (call && listener[msg.action]) { - listener[msg.action](d); - } ++ for (var watchId in this.listeners) { ++ if (this.listeners.hasOwnProperty(watchId)) { ++ var listener = this.listeners[watchId]; ++ var call = alwaysOn ? listener.alwaysOn : true; ++ if (call && listener[msg.action]) { ++ listener[msg.action](d); ++ } ++ } + } - } +}; + - GestureListenerManager.prototype.addListener = function(successCb, errorCb, type, alwaysOn) { - var listener = { - 'type' : type, - 'alwaysOn' : converter_.toBoolean(alwaysOn), - 'ondetect' : successCb, - 'onerror' : errorCb - }; ++GestureListenerManager.prototype.addListener = function( ++ successCb, ++ errorCb, ++ type, ++ alwaysOn ++) { ++ var listener = { ++ type: type, ++ alwaysOn: converter_.toBoolean(alwaysOn), ++ ondetect: successCb, ++ onerror: errorCb ++ }; + - var typeCountMap = alwaysOn ? this.typeCountMapAlwaysOn : this.typeCountMapDefault; - if (typeCountMap[type] === 0) { - var result = this.native.callSync('GestureManager_addGestureRecognitionListener', listener); - if (this.native.isFailure(result)) { - throw this.native.getErrorObject(result); ++ var typeCountMap = alwaysOn ? this.typeCountMapAlwaysOn : this.typeCountMapDefault; ++ if (typeCountMap[type] === 0) { ++ var result = this.native.callSync( ++ 'GestureManager_addGestureRecognitionListener', ++ listener ++ ); ++ if (this.native.isFailure(result)) { ++ throw this.native.getErrorObject(result); ++ } + } - } + - typeCountMap[type]++; - var id = this.nextId++; - this.listeners[id] = listener; ++ typeCountMap[type]++; ++ var id = this.nextId++; ++ this.listeners[id] = listener; + - if (!this.nativeSet) { - this.native.addListener(this.listenerName, this.onListenerCalled.bind(this)); - this.nativeSet = true; - } ++ if (!this.nativeSet) { ++ this.native.addListener(this.listenerName, this.onListenerCalled.bind(this)); ++ this.nativeSet = true; ++ } + - return id; ++ return id; +}; + +GestureListenerManager.prototype.removeListener = function(watchId) { - if (this.listeners.hasOwnProperty(watchId)) { - var listener = this.listeners[watchId]; - var typeCountMap = listener.alwaysOn ? this.typeCountMapAlwaysOn : this.typeCountMapDefault; - - if (typeCountMap[listener.type] === 1) { - var result = this.native.callSync('GestureManager_removeGestureRecognitionListener', listener); - if (this.native.isFailure(result)) { - throw this.native.getErrorObject(result); ++ if (this.listeners.hasOwnProperty(watchId)) { ++ var listener = this.listeners[watchId]; ++ var typeCountMap = listener.alwaysOn ++ ? this.typeCountMapAlwaysOn ++ : this.typeCountMapDefault; ++ ++ if (typeCountMap[listener.type] === 1) { ++ var result = this.native.callSync( ++ 'GestureManager_removeGestureRecognitionListener', ++ listener ++ ); ++ if (this.native.isFailure(result)) { ++ throw this.native.getErrorObject(result); ++ } + } - } + - delete this.listeners[watchId]; - typeCountMap[listener.type]--; - } ++ delete this.listeners[watchId]; ++ typeCountMap[listener.type]--; ++ } + - if (this.nativeSet && type_.isEmptyObject(this.listeners)) { - this.native.removeListener(this.listenerName); - this.nativeSet = false; - } ++ if (this.nativeSet && type_.isEmptyObject(this.listeners)) { ++ this.native.removeListener(this.listenerName); ++ this.nativeSet = false; ++ } +}; + +var GESTURE_RECOGNITION_LISTENER = 'GestureRecognitionListener'; - var gestureRecognitionListener = new GestureListenerManager(native_, GESTURE_RECOGNITION_LISTENER); ++var gestureRecognitionListener = new GestureListenerManager( ++ native_, ++ GESTURE_RECOGNITION_LISTENER ++); + +HumanActivityMonitorManager.prototype.addGestureRecognitionListener = function() { - var args = validator_.validateMethod(arguments, [{ - name : 'type', - type: types_.ENUM, - values: Object.keys(GestureType) - }, - { - name : 'eventCallback', - type : types_.FUNCTION - }, - { - name : 'errorCallback', - type : types_.FUNCTION, - optional: true, - nullable: true - }, - { - name : 'alwaysOn', - type : types_.BOOLEAN, - optional : true, - nullable : true - }]); - - return gestureRecognitionListener.addListener(args.eventCallback, args.errorCallback, args.type, args.alwaysOn); ++ var args = validator_.validateMethod(arguments, [ ++ { ++ name: 'type', ++ type: types_.ENUM, ++ values: Object.keys(GestureType) ++ }, ++ { ++ name: 'eventCallback', ++ type: types_.FUNCTION ++ }, ++ { ++ name: 'errorCallback', ++ type: types_.FUNCTION, ++ optional: true, ++ nullable: true ++ }, ++ { ++ name: 'alwaysOn', ++ type: types_.BOOLEAN, ++ optional: true, ++ nullable: true ++ } ++ ]); ++ ++ return gestureRecognitionListener.addListener( ++ args.eventCallback, ++ args.errorCallback, ++ args.type, ++ args.alwaysOn ++ ); +}; + +HumanActivityMonitorManager.prototype.removeGestureRecognitionListener = function() { - var args = validator_.validateMethod(arguments, [{ - name : 'watchId', - type : types_.LONG, - }]); ++ var args = validator_.validateMethod(arguments, [ ++ { ++ name: 'watchId', ++ type: types_.LONG ++ } ++ ]); + - gestureRecognitionListener.removeListener(args.watchId); ++ gestureRecognitionListener.removeListener(args.watchId); +}; + function StepDifference(data) { - SetReadOnlyProperty(this, 'stepCountDifference', data.stepCountDifference); - SetReadOnlyProperty(this, 'timestamp', data.timestamp); - } - - - function HumanActivityData() { + SetReadOnlyProperty(this, 'stepCountDifference', data.stepCountDifference); + SetReadOnlyProperty(this, 'timestamp', data.timestamp); } + function HumanActivityData() {} function HumanActivityPedometerData(data) { - SetReadOnlyProperty(this, 'stepStatus', data.stepStatus); - SetReadOnlyProperty(this, 'speed', data.speed); - SetReadOnlyProperty(this, 'walkingFrequency', data.walkingFrequency); - SetReadOnlyProperty(this, 'cumulativeDistance', data.cumulativeDistance); - SetReadOnlyProperty(this, 'cumulativeCalorie', data.cumulativeCalorie); - SetReadOnlyProperty(this, 'cumulativeTotalStepCount', data.cumulativeTotalStepCount); - SetReadOnlyProperty(this, 'cumulativeWalkStepCount', data.cumulativeWalkStepCount); - SetReadOnlyProperty(this, 'cumulativeRunStepCount', data.cumulativeRunStepCount); - - var steps = []; - for (var i = 0; i < data.stepCountDifferences.length; ++i) { - steps.push(new StepDifference(data.stepCountDifferences[i])); - } - SetReadOnlyProperty(this, 'stepCountDifferences', steps); + SetReadOnlyProperty(this, 'stepStatus', data.stepStatus); + SetReadOnlyProperty(this, 'speed', data.speed); + SetReadOnlyProperty(this, 'walkingFrequency', data.walkingFrequency); + SetReadOnlyProperty(this, 'cumulativeDistance', data.cumulativeDistance); + SetReadOnlyProperty(this, 'cumulativeCalorie', data.cumulativeCalorie); + SetReadOnlyProperty(this, 'cumulativeTotalStepCount', data.cumulativeTotalStepCount); + SetReadOnlyProperty(this, 'cumulativeWalkStepCount', data.cumulativeWalkStepCount); + SetReadOnlyProperty(this, 'cumulativeRunStepCount', data.cumulativeRunStepCount); + + var steps = []; + for (var i = 0; i < data.stepCountDifferences.length; ++i) { + steps.push(new StepDifference(data.stepCountDifferences[i])); + } + SetReadOnlyProperty(this, 'stepCountDifferences', steps); } HumanActivityPedometerData.prototype = new HumanActivityData(); @@@ -811,32 -723,20 +928,36 @@@ function HumanActivityRecorderSleepMoni } HumanActivityRecorderSleepMonitorData.prototype = new HumanActivityRecorderData(); - HumanActivityRecorderSleepMonitorData.prototype.constructor = HumanActivityRecorderSleepMonitorData; + // prettier-ignore + HumanActivityRecorderSleepMonitorData.prototype.constructor = + HumanActivityRecorderSleepMonitorData; function HumanActivityRecorderPressureData(data) { - HumanActivityRecorderData.call(this, data); - SetReadOnlyProperty(this, 'max', data.max); - SetReadOnlyProperty(this, 'min', data.min); - SetReadOnlyProperty(this, 'average', data.average); + HumanActivityRecorderData.call(this, data); + SetReadOnlyProperty(this, 'max', data.max); + SetReadOnlyProperty(this, 'min', data.min); + SetReadOnlyProperty(this, 'average', data.average); } +function GestureData(data) { - if (data) { - SetReadOnlyProperty(this, 'type', data.type); - SetReadOnlyProperty(this, 'event', data.event); - SetReadOnlyProperty(this, 'timestamp', data.timestamp); - - if (data.type === 'GESTURE_TILT') { - SetReadOnlyProperty(this, 'x', data.x); - SetReadOnlyProperty(this, 'y', data.y); - } else { - SetReadOnlyProperty(this, 'x', null); - SetReadOnlyProperty(this, 'y', null); ++ if (data) { ++ SetReadOnlyProperty(this, 'type', data.type); ++ SetReadOnlyProperty(this, 'event', data.event); ++ SetReadOnlyProperty(this, 'timestamp', data.timestamp); ++ ++ if (data.type === 'GESTURE_TILT') { ++ SetReadOnlyProperty(this, 'x', data.x); ++ SetReadOnlyProperty(this, 'y', data.y); ++ } else { ++ SetReadOnlyProperty(this, 'x', null); ++ SetReadOnlyProperty(this, 'y', null); ++ } + } - } +} + HumanActivityRecorderPressureData.prototype = new HumanActivityRecorderData(); - HumanActivityRecorderPressureData.prototype.constructor = HumanActivityRecorderPressureData; + // prettier-ignore + HumanActivityRecorderPressureData.prototype.constructor = + HumanActivityRecorderPressureData; exports = new HumanActivityMonitorManager(); diff --cc src/mediacontroller/mediacontroller_api.js index ac7f36ca,04ca640b..be155e55 --- a/src/mediacontroller/mediacontroller_api.js +++ b/src/mediacontroller/mediacontroller_api.js @@@ -23,15 -23,24 +23,15 @@@ var validator_ = utils_.validator var types_ = validator_.Types; var native_ = new xwalk.utils.NativeManager(extension); -// TODO(r.galka) CAPI have no dedicated methods for position/shuffle/repeat change. -// It should be updated when new version of CAPI will be available. -// For now implementation is using internal commands. -var internal_commands_ = { - sendPlaybackPosition: '__internal_sendPlaybackPosition', - sendShuffleMode: '__internal_sendShuffleMode', - sendRepeatMode: '__internal_sendRepeatMode' -}; - function ListenerManager(native, listenerName, handle) { - this.listeners = {}; - this.listenerNameToIds = {}; - this.listenerIdToName = {}; - this.nextId = 1; - this.nativeSet = false; - this.native = native; - this.listenerName = listenerName; - this.handle = handle || function(msg, listener, watchId) {}; + this.listeners = {}; + this.listenerNameToIds = {}; + this.listenerIdToName = {}; + this.nextId = 1; + this.nativeSet = false; + this.native = native; + this.listenerName = listenerName; + this.handle = handle || function(msg, listener, watchId) {}; } ListenerManager.prototype.addListener = function(callback) { @@@ -409,327 -496,405 +487,383 @@@ MediaControllerServer.prototype.updateP }; MediaControllerServer.prototype.updateShuffleMode = function(mode) { - var args = validator_.validateArgs(arguments, [ - {name: 'mode', type: types_.BOOLEAN} - ]); - - var data = { - mode: args.mode - }; - - var result = native_.callSync('MediaControllerServer_updateShuffleMode', data); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } - - edit_.allow(); - this.playbackInfo.shuffleMode = args.mode; - edit_.disallow(); - }; - - MediaControllerServer.prototype.updateRepeatMode = function(mode) { - var args = validator_.validateArgs(arguments, [ - {name: 'mode', type: types_.BOOLEAN} - ]); + var args = validator_.validateArgs(arguments, [ + { name: 'mode', type: types_.BOOLEAN } + ]); - var data = { - mode: args.mode - }; + var data = { + mode: args.mode + }; - var result = native_.callSync('MediaControllerServer_updateRepeatMode', data); + var result = native_.callSync('MediaControllerServer_updateShuffleMode', data); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } - - edit_.allow(); - this.playbackInfo.repeatMode = args.mode; - edit_.disallow(); - }; - - MediaControllerServer.prototype.updateMetadata = function(metadata) { - var args = validator_.validateArgs(arguments, [ - {name: 'metadata', type: types_.PLATFORM_OBJECT, values: MediaControllerMetadata} - ]); - - var data = { - metadata: args.metadata - }; - - var result = native_.callSync('MediaControllerServer_updateMetadata', data); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } - - edit_.allow(); - this.playbackInfo.metadata = args.metadata; - edit_.disallow(); - }; - - MediaControllerServer.prototype.addChangeRequestPlaybackInfoListener = function(listener) { - var args = validator_.validateArgs(arguments, [{ - name: 'listener', - type: types_.LISTENER, - values: [ - 'onplaybackstaterequest', - 'onplaybackpositionrequest', - 'onshufflemoderequest', - 'onrepeatmoderequest' - ] - }]); - - if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) { - var result = native_.callSync('MediaControllerServer_addChangeRequestPlaybackInfoListener', { - listenerId: ServerPlaybackInfoListener.listenerName - }); if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + throw native_.getErrorObject(result); } - } - return ServerPlaybackInfoListener.addListener(args.listener); + edit_.allow(); + this.playbackInfo.shuffleMode = args.mode; + edit_.disallow(); }; - MediaControllerServer.prototype.removeChangeRequestPlaybackInfoListener = function(watchId) { - var args = validator_.validateArgs(arguments, [ - {name: 'watchId', type: types_.LONG} - ]); + MediaControllerServer.prototype.updateRepeatMode = function(mode) { + var args = validator_.validateArgs(arguments, [ + { name: 'mode', type: types_.BOOLEAN } + ]); - ServerPlaybackInfoListener.removeListener(args.watchId); + var data = { + mode: args.mode + }; - if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) { - native_.callSync('MediaControllerServer_removeCommandListener'); - } - }; + var result = native_.callSync('MediaControllerServer_updateRepeatMode', data); - MediaControllerServer.prototype.addCommandListener = function(listener) { - var args = validator_.validateArgs(arguments, [ - {name: 'listener', type: types_.FUNCTION} - ]); - - if (type_.isEmptyObject(ServerCommandListener.listeners)) { - var result = native_.callSync('MediaControllerServer_addCommandListener', { - listenerId: ServerCommandListener.listenerName - }); if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + throw native_.getErrorObject(result); } - } - return ServerCommandListener.addListener(args.listener); - }; - - MediaControllerServer.prototype.removeCommandListener = function(watchId) { - var args = validator_.validateArgs(arguments, [ - {name: 'watchId', type: types_.LONG} - ]); - - ServerCommandListener.removeListener(args.watchId); - - if (type_.isEmptyObject(ServerCommandListener.listeners)) { - native_.callSync('MediaControllerServer_removeCommandListener'); - } + edit_.allow(); + this.playbackInfo.repeatMode = args.mode; + edit_.disallow(); }; + MediaControllerServer.prototype.updateMetadata = function(metadata) { + var args = validator_.validateArgs(arguments, [ + { + name: 'metadata', + type: types_.PLATFORM_OBJECT, + values: MediaControllerMetadata + } + ]); - function MediaControllerClient() {} + var data = { + metadata: args.metadata + }; - MediaControllerClient.prototype.findServers = function(successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - {name: 'successCallback', type: types_.FUNCTION}, - {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} - ]); + var result = native_.callSync('MediaControllerServer_updateMetadata', data); - var callback = function(result) { if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - return; + throw native_.getErrorObject(result); } - var info = []; - var data = native_.getResultObject(result); - for (var i = 0; i < data.length; i++) { - info.push(new MediaControllerServerInfo(data[i])); + + edit_.allow(); + this.playbackInfo.metadata = args.metadata; + edit_.disallow(); + }; + + MediaControllerServer.prototype.addChangeRequestPlaybackInfoListener = function( + listener + ) { + var args = validator_.validateArgs(arguments, [ + { + name: 'listener', + type: types_.LISTENER, + values: [ + 'onplaybackstaterequest', + 'onplaybackpositionrequest', + 'onshufflemoderequest', + 'onrepeatmoderequest' + ] + } + ]); + + if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) { + var result = native_.callSync( + 'MediaControllerServer_addChangeRequestPlaybackInfoListener', + { + listenerId: ServerPlaybackInfoListener.listenerName + } + ); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } } - native_.callIfPossible(args.successCallback, info); - }; - native_.call('MediaControllerClient_findServers', {}, callback); + return ServerPlaybackInfoListener.addListener(args.listener); }; - MediaControllerClient.prototype.getLatestServerInfo = function() { - - var result = native_.callSync('MediaControllerClient_getLatestServerInfo', {}); + MediaControllerServer.prototype.removeChangeRequestPlaybackInfoListener = function( + watchId + ) { + var args = validator_.validateArgs(arguments, [ + { name: 'watchId', type: types_.LONG } + ]); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } + ServerPlaybackInfoListener.removeListener(args.watchId); - var serverInfo = native_.getResultObject(result); - if (serverInfo) { - if ('NONE' === serverInfo.state) { - serverInfo.state = 'INACTIVE'; + if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) { + native_.callSync('MediaControllerServer_removeCommandListener'); } - serverInfo = new MediaControllerServerInfo(serverInfo); - } - return serverInfo; }; + MediaControllerServer.prototype.addCommandListener = function(listener) { + var args = validator_.validateArgs(arguments, [ + { name: 'listener', type: types_.FUNCTION } + ]); - function MediaControllerServerInfo(data) { - Object.defineProperties(this, { - name: { - value: data.name, - writable: false, - enumerable: true - }, - state: { - value: data.state, - writable: false, - enumerable: true - }, - playbackInfo: { - get: function () { - var result = native_.callSync('MediaControllerClient_getPlaybackInfo', {name: this.name}); + if (type_.isEmptyObject(ServerCommandListener.listeners)) { + var result = native_.callSync('MediaControllerServer_addCommandListener', { + listenerId: ServerCommandListener.listenerName + }); if (native_.isFailure(result)) { - throw new native_.getErrorObject(result); + throw native_.getErrorObject(result); } - edit_.allow(); - var data = native_.getResultObject(result); - var playbackInfo = new MediaControllerPlaybackInfo(data); - edit_.disallow(); - - return playbackInfo; - }.bind(this), - set: function() {}, - enumerable: true } - }); - } + return ServerCommandListener.addListener(args.listener); + }; - MediaControllerServerInfo.prototype.sendPlaybackState = function(state, successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - {name: 'state', type: types_.ENUM, values: Object.keys(MediaControllerPlaybackState)}, - {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true}, - {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} - ]); + MediaControllerServer.prototype.removeCommandListener = function(watchId) { + var args = validator_.validateArgs(arguments, [ + { name: 'watchId', type: types_.LONG } + ]); - var data = { - name: this.name, - state: args.state - }; + ServerCommandListener.removeListener(args.watchId); - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - return; + if (type_.isEmptyObject(ServerCommandListener.listeners)) { + native_.callSync('MediaControllerServer_removeCommandListener'); } - native_.callIfPossible(args.successCallback); - }; - - native_.call('MediaControllerServerInfo_sendPlaybackState', data, callback); }; - MediaControllerServerInfo.prototype.sendPlaybackPosition = function(position, successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - {name: 'position', type: types_.LONG_LONG}, - {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true}, - {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} - ]); - - if (args.position < 0) { - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR); - } + function MediaControllerClient() {} - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - return; - } - native_.callIfPossible(args.successCallback); - }; + MediaControllerClient.prototype.findServers = function(successCallback, errorCallback) { + var args = validator_.validateArgs(arguments, [ + { name: 'successCallback', type: types_.FUNCTION }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); - var data = { - position: args.position, - name: this.name - }; + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + return; + } + var info = []; + var data = native_.getResultObject(result); + for (var i = 0; i < data.length; i++) { + info.push(new MediaControllerServerInfo(data[i])); + } + native_.callIfPossible(args.successCallback, info); + }; - native_.call('MediaControllerServerInfo_sendPlaybackPosition', data, callback); + native_.call('MediaControllerClient_findServers', {}, callback); }; - MediaControllerServerInfo.prototype.sendShuffleMode = function(mode, successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - {name: 'mode', type: types_.BOOLEAN}, - {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true}, - {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} - ]); + MediaControllerClient.prototype.getLatestServerInfo = function() { + var result = native_.callSync('MediaControllerClient_getLatestServerInfo', {}); - var callback = function(result) { if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - return; + throw native_.getErrorObject(result); } - native_.callIfPossible(args.successCallback); - }; - var data = { - mode: args.mode, - name: this.name - }; - native_.call('MediaControllerServerInfo_sendShuffleMode', data, callback); + var serverInfo = native_.getResultObject(result); + if (serverInfo) { + if ('NONE' === serverInfo.state) { + serverInfo.state = 'INACTIVE'; + } + serverInfo = new MediaControllerServerInfo(serverInfo); + } + return serverInfo; }; - MediaControllerServerInfo.prototype.sendRepeatMode = function(mode, successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - {name: 'mode', type: types_.BOOLEAN}, - {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true}, - {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} - ]); + function MediaControllerServerInfo(data) { + Object.defineProperties(this, { + name: { + value: data.name, + writable: false, + enumerable: true + }, + state: { + value: data.state, + writable: false, + enumerable: true + }, + playbackInfo: { + get: function() { + var result = native_.callSync('MediaControllerClient_getPlaybackInfo', { + name: this.name + }); + if (native_.isFailure(result)) { + throw new native_.getErrorObject(result); + } + edit_.allow(); + var data = native_.getResultObject(result); + var playbackInfo = new MediaControllerPlaybackInfo(data); + edit_.disallow(); + + return playbackInfo; + }.bind(this), + set: function() {}, + enumerable: true + } + }); + } - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - return; - } - native_.callIfPossible(args.successCallback); - }; - - var data = { - mode: args.mode, - name: this.name - }; - native_.call('MediaControllerServerInfo_sendRepeatMode', data, callback); - }; - - MediaControllerServerInfo.prototype.sendCommand = function(command, data, successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - {name: 'command', type: types_.STRING}, - {name: 'data', type: types_.DICTIONARY}, - {name: 'successCallback', type: types_.FUNCTION}, - {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} - ]); - - var nativeData = { - command: args.command, - data: args.data, - name: this.name - }; - - var replyId = ReplyCommandListener.addListener(successCallback); - - nativeData.replyId = replyId; - nativeData.listenerId = ReplyCommandListener.listenerName; - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - return; + MediaControllerServerInfo.prototype.sendPlaybackState = function( + state, + successCallback, + errorCallback + ) { + var args = validator_.validateArgs(arguments, [ + { + name: 'state', + type: types_.ENUM, + values: Object.keys(MediaControllerPlaybackState) + }, + { + name: 'successCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } ++ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var data = { + name: this.name, + state: args.state + }; + + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + return; + } + native_.callIfPossible(args.successCallback); + }; + + native_.call('MediaControllerServerInfo_sendPlaybackState', data, callback); + }; + + MediaControllerServerInfo.prototype.sendPlaybackPosition = function( + position, + successCallback, + errorCallback + ) { + var args = validator_.validateArgs(arguments, [ + { name: 'position', type: types_.LONG_LONG }, + { + name: 'successCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + if (args.position < 0) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR); } - args.successCallback(native_.getResultObject(result)); - }; - native_.call('MediaControllerServerInfo_sendCommand', nativeData, callback); + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + return; + } + native_.callIfPossible(args.successCallback); + }; + + var data = { - position: args.position ++ position: args.position, ++ name: this.name + }; + - sendDefinedCommand( - this.name, - internal_commands_.sendPlaybackPosition, - data, - callback - ); ++ native_.call('MediaControllerServerInfo_sendPlaybackPosition', data, callback); + }; + + MediaControllerServerInfo.prototype.sendShuffleMode = function( + mode, + successCallback, + errorCallback + ) { + var args = validator_.validateArgs(arguments, [ + { name: 'mode', type: types_.BOOLEAN }, + { + name: 'successCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + return; + } + native_.callIfPossible(args.successCallback); + }; + + var data = { - mode: args.mode ++ mode: args.mode, ++ name: this.name + }; - sendDefinedCommand(this.name, internal_commands_.sendShuffleMode, data, callback); ++ native_.call('MediaControllerServerInfo_sendShuffleMode', data, callback); + }; + + MediaControllerServerInfo.prototype.sendRepeatMode = function( + mode, + successCallback, + errorCallback + ) { + var args = validator_.validateArgs(arguments, [ + { name: 'mode', type: types_.BOOLEAN }, + { + name: 'successCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + return; + } + native_.callIfPossible(args.successCallback); + }; + + var data = { - mode: args.mode ++ mode: args.mode, ++ name: this.name + }; - sendDefinedCommand(this.name, internal_commands_.sendRepeatMode, data, callback); ++ native_.call('MediaControllerServerInfo_sendRepeatMode', data, callback); + }; + -function sendDefinedCommand(name_, command_, data_, callback_) { - var nativeData = { - command: command_, - data: data_, - name: name_ - }; - - var replyId = ReplyCommandListener.addListener(callback_); - - nativeData.replyId = replyId; - nativeData.listenerId = ReplyCommandListener.listenerName; - - native_.call('MediaControllerServerInfo_sendCommand', nativeData, callback_); -} - + MediaControllerServerInfo.prototype.sendCommand = function( + command, + data, + successCallback, + errorCallback + ) { + var args = validator_.validateArgs(arguments, [ + { name: 'command', type: types_.STRING }, + { name: 'data', type: types_.DICTIONARY }, + { name: 'successCallback', type: types_.FUNCTION }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var nativeData = { + command: args.command, + data: args.data, + name: this.name + }; + + var replyId = ReplyCommandListener.addListener(successCallback); + + nativeData.replyId = replyId; + nativeData.listenerId = ReplyCommandListener.listenerName; + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + return; + } + args.successCallback(native_.getResultObject(result)); + }; + + native_.call('MediaControllerServerInfo_sendCommand', nativeData, callback); }; MediaControllerServerInfo.prototype.addServerStatusChangeListener = function(listener) { diff --cc src/nfc/nfc_api.js index dc1e25a7,d8e95534..5eef7c29 --- a/src/nfc/nfc_api.js +++ b/src/nfc/nfc_api.js @@@ -137,12 -136,23 +136,24 @@@ var TRANSACTION_EVENT_ESE_LISTENER = 'T var TRANSACTION_EVENT_UICC_LISTENER = 'TransactionEventListener_UICC'; var HCE_EVENT_LISTENER = 'HCEEventListener'; var TAG_LISTENER = 'TagListener'; - var cardEmulationModeListener = new ListenerManager(native_, CARD_EMULATION_MODE_LISTENER); - var activeSecureElementChangeListener = new ListenerManager(native_, ACTIVE_SECURE_ELEMENT_LISTENER); - var transactionEventListenerEse = new ListenerManager(native_, TRANSACTION_EVENT_ESE_LISTENER); - var transactionEventListenerUicc = new ListenerManager(native_, TRANSACTION_EVENT_UICC_LISTENER); + var cardEmulationModeListener = new ListenerManager( + native_, + CARD_EMULATION_MODE_LISTENER + ); + var activeSecureElementChangeListener = new ListenerManager( + native_, + ACTIVE_SECURE_ELEMENT_LISTENER + ); + var transactionEventListenerEse = new ListenerManager( + native_, + TRANSACTION_EVENT_ESE_LISTENER + ); + var transactionEventListenerUicc = new ListenerManager( + native_, + TRANSACTION_EVENT_UICC_LISTENER + ); var HCEEventListener = new ListenerManager(native_, HCE_EVENT_LISTENER); +var isWebkitVisibilityChangeListenerSet = false; //////////////////NFCManager ///////////////// @@@ -190,123 -196,124 +197,124 @@@ NFCManager.prototype.setExclusiveMode //////////////////NFCAdapter ///////////////// function NFCAdapter() { - function poweredGetter() { - var ret = native_.callSync('NFCAdapter_getPowered'); + function poweredGetter() { + var ret = native_.callSync('NFCAdapter_getPowered'); + + if (native_.isFailure(ret)) { + return false; + } - if (native_.isFailure(ret)) { - return false; + return native_.getResultObject(ret); } - return native_.getResultObject(ret); - } + function cardEmulationModeGetter() { + var result = native_.callSync('NFCAdapter_cardEmulationModeGetter'); - function cardEmulationModeGetter() { - var result = native_.callSync('NFCAdapter_cardEmulationModeGetter'); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + return native_.getResultObject(result); } - return native_.getResultObject(result); - } + function cardEmulationModeSetter(cem) { + var args = validator_.validateArgs(arguments, [ + { name: 'emulationMode', type: types_.STRING } + ]); - function cardEmulationModeSetter(cem) { + var result = native_.callSync('NFCAdapter_cardEmulationModeSetter', { + emulationMode: args.emulationMode + }); - var args = validator_.validateArgs(arguments, [ - {name: 'emulationMode', type: types_.STRING} - ]); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } + return; + } - var result = native_.callSync( - 'NFCAdapter_cardEmulationModeSetter', - { 'emulationMode': args.emulationMode} - ); + function activeSecureElementGetter() { + var result = native_.callSync('NFCAdapter_activeSecureElementGetter'); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } + + return native_.getResultObject(result); } - return; - } - function activeSecureElementGetter() { + function activeSecureElementSetter(ase) { + var args = validator_.validateArgs(arguments, [ + { name: 'secureElement', type: types_.STRING } + ]); - var result = native_.callSync('NFCAdapter_activeSecureElementGetter'); + var result = native_.callSync('NFCAdapter_activeSecureElementSetter', { + secureElement: args.secureElement + }); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } + return; } - return native_.getResultObject(result); - } + Object.defineProperties(this, { + powered: { enumerable: true, set: function() {}, get: poweredGetter }, + cardEmulationMode: { + enumerable: true, + set: cardEmulationModeSetter, + get: cardEmulationModeGetter + }, + activeSecureElement: { + enumerable: true, + set: activeSecureElementSetter, + get: activeSecureElementGetter + } + }); + } - function activeSecureElementSetter(ase) { + NFCAdapter.prototype.setPowered = function() { + privUtils_.warn( - 'DEPRECATION WARNING: setPowered() is deprecated ' + - 'and will be removed from next release. Let the user ' + - 'turn NFC on/off through the Settings application instead.' ++ 'DEPRECATION WARNING: setPowered() is deprecated and ' + ++ 'will be removed from next release. Let the user turn NFC on/off ' + ++ 'through the Settings application instead.' + ); var args = validator_.validateArgs(arguments, [ - {name: 'secureElement', type: types_.STRING} + { + name: 'powered', + type: types_.BOOLEAN + }, + { + name: 'successCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + }, + { + name: 'errorCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + } ]); - var result = native_.callSync( - 'NFCAdapter_activeSecureElementSetter', - { 'secureElement': args.secureElement} - ); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } - return; - } - - Object.defineProperties(this, { - powered: {enumerable: true, - set: function() {}, - get: poweredGetter - }, - cardEmulationMode: {enumerable: true, - set: cardEmulationModeSetter, - get: cardEmulationModeGetter - }, - activeSecureElement: {enumerable: true, - set: activeSecureElementSetter, - get: activeSecureElementGetter - } - }); - } + var result = native_.call( + 'NFCAdapter_setPowered', + { + powered: args.powered + }, + function(result) { + if (native_.isFailure(result)) { + args.errorCallback(result.error); + } else { + args.successCallback(); + } + } + ); - NFCAdapter.prototype.setPowered = function() { - privUtils_.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. Let the user turn NFC on/off ' - + 'through the Settings application instead.'); - - var args = validator_.validateArgs(arguments, [ - { - name: 'powered', - type: types_.BOOLEAN - }, - { - name: 'successCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - }, - { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - } - ]); - - var result = native_.call('NFCAdapter_setPowered', { - powered: args.powered - }, function(result) { if (native_.isFailure(result)) { - args.errorCallback(result.error); - } else { - args.successCallback(); + throw native_.getErrorObject(result); } - }); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } }; function setTagListener() { @@@ -839,152 -871,133 +872,178 @@@ NFCAdapter.prototype.unregisterAID = fu }; function AIDData(data) { - Object.defineProperties(this, { - type: { - value: data.type, - writable: false, - enumerable: true - }, - aid: { - value: data.aid || [], - writable: false, - enumerable: true - }, - readOnly: { - value: data.readOnly || false, - writable: false, - enumerable: true - } - }); + Object.defineProperties(this, { + type: { + value: data.type, + writable: false, + enumerable: true + }, + aid: { + value: data.aid || [], + writable: false, + enumerable: true + }, + readOnly: { + value: data.readOnly || false, + writable: false, + enumerable: true + } + }); } - NFCAdapter.prototype.getAIDsForCategory = function(type, category, successCallback, errorCallback) { - - var args = validator_.validateArgs(arguments, [{ - name: 'type', - type: types_.ENUM, - values: type_.getValues(SecureElementType) - }, { - name: 'category', - type: types_.ENUM, - values: Object.keys(CardEmulationCategoryType) - }, { - name: 'successCallback', - type: types_.FUNCTION - }, { - name: 'errorCallback', - type: types_.FUNCTION, - optional: true, - nullable: true - }]); - - if (arguments.length < 3) { - throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR); - } - - var data = { - type: args.type, - category: args.category - }; - - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - return; - } - var aids = []; - var r = native_.getResultObject(result); - for (var i = 0; i < r.length; i++) { - aids.push(new AIDData(r[i])); + NFCAdapter.prototype.getAIDsForCategory = function( + type, + category, + successCallback, + errorCallback + ) { + var args = validator_.validateArgs(arguments, [ + { + name: 'type', + type: types_.ENUM, + values: type_.getValues(SecureElementType) + }, + { + name: 'category', + type: types_.ENUM, + values: Object.keys(CardEmulationCategoryType) + }, + { + name: 'successCallback', + type: types_.FUNCTION + }, + { + name: 'errorCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + } + ]); + + if (arguments.length < 3) { + throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR); } - native_.callIfPossible(args.successCallback, aids); - }; - var result = native_.call('NFCAdapter_getAIDsForCategory', data, callback); + var data = { + type: args.type, + category: args.category + }; - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + return; + } + var aids = []; + var r = native_.getResultObject(result); + for (var i = 0; i < r.length; i++) { + aids.push(new AIDData(r[i])); + } + native_.callIfPossible(args.successCallback, aids); + }; + + var result = native_.call('NFCAdapter_getAIDsForCategory', data, callback); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } }; +function WebkitVisibilityChangeListener() { - var result; - if (true === privUtils_.global.document.hidden) { - result = native_.call('NFCAdapter_unsetPreferredApp'); - } else if (false === privUtils_.global.document.hidden) { - result = native_.call('NFCAdapter_setPreferredApp'); - } - - if (native_.isFailure(result)) { - privUtils_.log('Failed to (un)set: ' + result.error.message); - } ++ var result; ++ if (true === privUtils_.global.document.hidden) { ++ result = native_.call('NFCAdapter_unsetPreferredApp'); ++ } else if (false === privUtils_.global.document.hidden) { ++ result = native_.call('NFCAdapter_setPreferredApp'); ++ } ++ ++ if (native_.isFailure(result)) { ++ privUtils_.log('Failed to (un)set: ' + result.error.message); ++ } +} + +NFCAdapter.prototype.setPreferredApp = function() { - var result = native_.call('NFCAdapter_setPreferredApp'); ++ var result = native_.call('NFCAdapter_setPreferredApp'); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } else { - if (false === isWebkitVisibilityChangeListenerSet) { - privUtils_.global.document.addEventListener("webkitvisibilitychange", WebkitVisibilityChangeListener); - isWebkitVisibilityChangeListenerSet = true; ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } else { ++ if (false === isWebkitVisibilityChangeListenerSet) { ++ privUtils_.global.document.addEventListener( ++ 'webkitvisibilitychange', ++ WebkitVisibilityChangeListener ++ ); ++ isWebkitVisibilityChangeListenerSet = true; ++ } + } - } +}; + +NFCAdapter.prototype.unsetPreferredApp = function() { - var result = native_.call('NFCAdapter_unsetPreferredApp'); ++ var result = native_.call('NFCAdapter_unsetPreferredApp'); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } else { - if (true === isWebkitVisibilityChangeListenerSet) { - privUtils_.global.document.removeEventListener("webkitvisibilitychange", WebkitVisibilityChangeListener); - isWebkitVisibilityChangeListenerSet = false; ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } else { ++ if (true === isWebkitVisibilityChangeListenerSet) { ++ privUtils_.global.document.removeEventListener( ++ 'webkitvisibilitychange', ++ WebkitVisibilityChangeListener ++ ); ++ isWebkitVisibilityChangeListenerSet = false; ++ } + } - } +}; + function InternalRecordData(tnf, type, payload, id) { - this.tnf = tnf; - this.type = type; - this.payload = payload; - this.id = id; - }; + this.tnf = tnf; + this.type = type; + this.payload = payload; + this.id = id; + } var toRecordsArray = function(array) { - var result = []; - if (type_.isNullOrUndefined(array) || !type_.isArray(array)) { - return result; - } + var result = []; + if (type_.isNullOrUndefined(array) || !type_.isArray(array)) { + return result; + } - for (var i = 0; i < array.length; i++) { - var data = new InternalRecordData(array[i].tnf, array[i].type, array[i].payload, array[i].id); + for (var i = 0; i < array.length; i++) { + var data = new InternalRecordData( + array[i].tnf, + array[i].type, + array[i].payload, + array[i].id + ); - if (array[i].recordType == 'Record') { - result.push(new tizen.NDEFRecord(data.tnf, data.type, data.payload, data.id)); - continue; - } + if (array[i].recordType == 'Record') { + result.push(new tizen.NDEFRecord(data.tnf, data.type, data.payload, data.id)); + continue; + } - if (array[i].recordType == 'RecordText') { - result.push(new tizen.NDEFRecordText(array[i].text, array[i].languageCode, - array[i].encoding, data)); - continue; - } + if (array[i].recordType == 'RecordText') { + result.push( + new tizen.NDEFRecordText( + array[i].text, + array[i].languageCode, + array[i].encoding, + data + ) + ); + continue; + } - if (array[i].recordType == 'RecordURI') { - result.push(new tizen.NDEFRecordURI(array[i].uri, data)); - continue; - } + if (array[i].recordType == 'RecordURI') { + result.push(new tizen.NDEFRecordURI(array[i].uri, data)); + continue; + } - if (array[i].recordType == 'RecordMedia') { - result.push(new tizen.NDEFRecordMedia(array[i].mimeType, null, data)); - continue; + if (array[i].recordType == 'RecordMedia') { + result.push(new tizen.NDEFRecordMedia(array[i].mimeType, null, data)); + continue; + } } - } - return result; + return result; }; //////////////////NFCTag ///////////////// diff --cc src/notification/notification_api.js index 8e186f1e,252e7559..6679ab3c --- a/src/notification/notification_api.js +++ b/src/notification/notification_api.js @@@ -63,22 -63,15 +63,22 @@@ var NotificationType = }; var StatusNotificationType = { - SIMPLE: 'SIMPLE', - THUMBNAIL: 'THUMBNAIL', - ONGOING: 'ONGOING', - PROGRESS: 'PROGRESS' + SIMPLE: 'SIMPLE', + THUMBNAIL: 'THUMBNAIL', + ONGOING: 'ONGOING', + PROGRESS: 'PROGRESS' }; +var UserNotificationType = { - SIMPLE: 'SIMPLE', - THUMBNAIL: 'THUMBNAIL', - ONGOING: 'ONGOING', - PROGRESS: 'PROGRESS' ++ SIMPLE: 'SIMPLE', ++ THUMBNAIL: 'THUMBNAIL', ++ ONGOING: 'ONGOING', ++ PROGRESS: 'PROGRESS' +}; + var NotificationProgressType = { - PERCENTAGE: 'PERCENTAGE', - BYTE: 'BYTE' + PERCENTAGE: 'PERCENTAGE', + BYTE: 'BYTE' }; var LEDCustomFlags = { @@@ -88,63 -81,50 +88,68 @@@ function NotificationManager() {} - NotificationManager.prototype.post = function(notification) { - var args = validator_.validateArgs(arguments, [ - {name: 'notification', type: types_.PLATFORM_OBJECT, values: Notification} - ]); + var args = validator_.validateArgs(arguments, [ - { name: 'notification', type: types_.PLATFORM_OBJECT, values: StatusNotification } ++ { name: 'notification', type: types_.PLATFORM_OBJECT, values: Notification } + ]); + ++ if (args.notification instanceof tizen.StatusNotification) { ++ utils_.warn( ++ 'DEPRECATION WARNING: StatusNotification is deprecated since Tizen 4.0. ' + ++ 'Use UserNotification instead.' ++ ); ++ } + - if (args.notification instanceof tizen.StatusNotification) { - utils_.warn('DEPRECATION WARNING: StatusNotification is deprecated since Tizen 4.0. Use UserNotification instead.'); - } + var data = { ++ //add marker for UserNotification implementation ++ newImpl: args.notification instanceof tizen.UserNotification, + notification: args.notification + }; - var data = { - //add marker for UserNotification implementation - newImpl: (args.notification instanceof tizen.UserNotification), - notification: args.notification - }; - - var result = native_.callSync('NotificationManager_post', data); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } - - _edit.allow(); - var d = native_.getResultObject(result); - notification.id = d.id; - notification.postedTime = new Date(d.postedTime) || new Date(); - notification.type = d.type || NotificationType.STATUS; - _edit.disallow(); + var result = native_.callSync('NotificationManager_post', data); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } + + _edit.allow(); + var d = native_.getResultObject(result); + notification.id = d.id; + notification.postedTime = new Date(d.postedTime) || new Date(); + notification.type = d.type || NotificationType.STATUS; + _edit.disallow(); }; NotificationManager.prototype.update = function(notification) { - var args = validator_.validateArgs(arguments, [ - {name: 'notification', type: types_.PLATFORM_OBJECT, values: Notification} - ]); - - if (!arguments.length) { - throw new WebAPIException(WebAPIException.NOT_FOUND_ERR); - } - if (!args.notification.id) { - throw new WebAPIException(WebAPIException.UNKNOWN_ERR); - } - - if (args.notification instanceof tizen.StatusNotification) { - utils_.warn('DEPRECATION WARNING: StatusNotification is deprecated since Tizen 4.0. Use UserNotification instead.'); - } - - var data = { - //add marker for UserNotification implementation - newImpl: (args.notification instanceof tizen.UserNotification), - notification: args.notification - }; + var args = validator_.validateArgs(arguments, [ - { name: 'notification', type: types_.PLATFORM_OBJECT, values: StatusNotification } ++ { name: 'notification', type: types_.PLATFORM_OBJECT, values: Notification } + ]); + + if (!arguments.length) { + throw new WebAPIException(WebAPIException.NOT_FOUND_ERR); + } + if (!args.notification.id) { + throw new WebAPIException(WebAPIException.UNKNOWN_ERR); + } - var result = native_.callSync('NotificationManager_update', data); ++ if (args.notification instanceof tizen.StatusNotification) { ++ utils_.warn( ++ 'DEPRECATION WARNING: StatusNotification is deprecated since Tizen 4.0. ' + ++ 'Use UserNotification instead.' ++ ); ++ } + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } + var data = { ++ //add marker for UserNotification implementation ++ newImpl: args.notification instanceof tizen.UserNotification, + notification: args.notification + }; + + var result = native_.callSync('NotificationManager_update', data); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } }; NotificationManager.prototype.remove = function(id) { @@@ -176,108 -154,50 +179,110 @@@ NotificationManager.prototype.removeAl }; NotificationManager.prototype.get = function(id) { - var args = validator_.validateArgs(arguments, [ - {name: 'id', type: types_.STRING} - ]); + var args = validator_.validateArgs(arguments, [{ name: 'id', type: types_.STRING }]); - utils_.warn('DEPRECATION WARNING: get() is deprecated since Tizen 4.0. Use getNotification() instead.'); ++ utils_.warn( ++ 'DEPRECATION WARNING: get() is deprecated since Tizen 4.0. ' + ++ 'Use getNotification() instead.' ++ ); + - if (!arguments.length) { - throw new WebAPIException(WebAPIException.NOT_FOUND_ERR); - } + if (!arguments.length) { + throw new WebAPIException(WebAPIException.NOT_FOUND_ERR); + } - var data = { - id: args.id - }; + var data = { + id: args.id + }; - var result = native_.callSync('NotificationManager_get', data); + var result = native_.callSync('NotificationManager_get', data); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } - var n = native_.getResultObject(result); + var n = native_.getResultObject(result); - _edit.allow(); - var returnObject = new StatusNotification(n.statusType, n.title, n); - _edit.disallow(); + _edit.allow(); + var returnObject = new StatusNotification(n.statusType, n.title, n); + _edit.disallow(); - return returnObject; + return returnObject; }; +NotificationManager.prototype.getNotification = function(id) { - var args = validator_.validateArgs(arguments, [ - {name: 'id', type: types_.STRING} - ]); ++ var args = validator_.validateArgs(arguments, [{ name: 'id', type: types_.STRING }]); + - if (!arguments.length) { - throw new WebAPIException(WebAPIException.NOT_FOUND_ERR); - } ++ if (!arguments.length) { ++ throw new WebAPIException(WebAPIException.NOT_FOUND_ERR); ++ } + - var data = { - //add marker for UserNotification implementation - newImpl: true, - id: args.id - }; ++ var data = { ++ //add marker for UserNotification implementation ++ newImpl: true, ++ id: args.id ++ }; + - var result = native_.callSync('NotificationManager_get', data); ++ var result = native_.callSync('NotificationManager_get', data); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } + - var n = native_.getResultObject(result); ++ var n = native_.getResultObject(result); + - _edit.allow(); - var returnObject = new UserNotification(n.userType, n.title, n); - _edit.disallow(); ++ _edit.allow(); ++ var returnObject = new UserNotification(n.userType, n.title, n); ++ _edit.disallow(); + - return returnObject; ++ return returnObject; +}; + NotificationManager.prototype.getAll = function() { - utils_.warn('DEPRECATION WARNING: getAll() is deprecated since Tizen 4.0. Use getAllNotifications() instead.'); ++ utils_.warn( ++ 'DEPRECATION WARNING: getAll() is deprecated since Tizen 4.0. ' + ++ 'Use getAllNotifications() instead.' ++ ); + - var result = native_.callSync('NotificationManager_getAll', {}); + var result = native_.callSync('NotificationManager_getAll', {}); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } - var n = native_.getResultObject(result); - var notifications = []; + var n = native_.getResultObject(result); + var notifications = []; - _edit.allow(); - for (var i = 0; i < n.length; i++) { - notifications.push(new StatusNotification(n[i].statusType, n[i].title, n[i])); - } - _edit.disallow(); + _edit.allow(); + for (var i = 0; i < n.length; i++) { + notifications.push(new StatusNotification(n[i].statusType, n[i].title, n[i])); + } + _edit.disallow(); - return notifications; + return notifications; }; +NotificationManager.prototype.getAllNotifications = function() { - var result = native_.callSync('NotificationManager_getAll', { - //add marker for UserNotification implementation - newImpl: true ++ var result = native_.callSync('NotificationManager_getAll', { ++ //add marker for UserNotification implementation ++ newImpl: true + }); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } + - var n = native_.getResultObject(result); - var notifications = []; ++ var n = native_.getResultObject(result); ++ var notifications = []; + - _edit.allow(); - for (var i = 0; i < n.length; i++) { - notifications.push(new UserNotification(n[i].userType, n[i].title, n[i])); - } - _edit.disallow(); ++ _edit.allow(); ++ for (var i = 0; i < n.length; i++) { ++ notifications.push(new UserNotification(n[i].userType, n[i].title, n[i])); ++ } ++ _edit.disallow(); + - return notifications; ++ return notifications; +}; + /** * Plays the custom effect of the service LED that is located to the front of a device. * @@@ -311,283 -239,266 +324,310 @@@ NotificationManager.prototype.playLEDCu * Stops the custom effect of the service LED that is located to the front of a device. */ NotificationManager.prototype.stopLEDCustomEffect = function() { - var result = native_.callSync('NotificationManager_stopLEDCustomEffect'); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } + var result = native_.callSync('NotificationManager_stopLEDCustomEffect'); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } }; +NotificationManager.prototype.saveNotificationAsTemplate = function(name, notification) { - var args = validator_.validateArgs(arguments, [ - {name: 'name', type: types_.STRING}, - {name: 'notification', type: types_.PLATFORM_OBJECT, values: Notification} - ]); ++ var args = validator_.validateArgs(arguments, [ ++ { name: 'name', type: types_.STRING }, ++ { name: 'notification', type: types_.PLATFORM_OBJECT, values: Notification } ++ ]); + - //add marker for UserNotification implementation - args.newImpl = (args.notification instanceof tizen.UserNotification); ++ //add marker for UserNotification implementation ++ args.newImpl = args.notification instanceof tizen.UserNotification; + - var result = native_.callSync('NotificationManager_saveNotificationAsTemplate', args); ++ var result = native_.callSync('NotificationManager_saveNotificationAsTemplate', args); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } +}; + +NotificationManager.prototype.createNotificationFromTemplate = function(name) { - var args = validator_.validateArgs(arguments, [ - {name: 'name', type: types_.STRING} - ]); ++ var args = validator_.validateArgs(arguments, [ ++ { name: 'name', type: types_.STRING } ++ ]); + - if (!arguments.length) { - throw new WebAPIException(WebAPIException.NOT_FOUND_ERR); - } ++ if (!arguments.length) { ++ throw new WebAPIException(WebAPIException.NOT_FOUND_ERR); ++ } + - var result = native_.callSync('NotificationManager_createNotificationFromTemplate', args); ++ var result = native_.callSync( ++ 'NotificationManager_createNotificationFromTemplate', ++ args ++ ); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } - var n = native_.getResultObject(result); ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } ++ var n = native_.getResultObject(result); + - _edit.allow(); - var returnObject = new UserNotification(n.userType, n.title, n); - _edit.disallow(); ++ _edit.allow(); ++ var returnObject = new UserNotification(n.userType, n.title, n); ++ _edit.disallow(); + - return returnObject; ++ return returnObject; +}; + +var _checkProgressValue = function(v, _progressType) { - if ((_progressType === NotificationProgressType.PERCENTAGE && (v >= 0 && v <= 100)) - || (_progressType === NotificationProgressType.BYTE && - converter_.toUnsignedLong(v) >= 0)) { - return true; - } - return false; ++ if ( ++ (_progressType === NotificationProgressType.PERCENTAGE && (v >= 0 && v <= 100)) || ++ (_progressType === NotificationProgressType.BYTE && ++ converter_.toUnsignedLong(v) >= 0) ++ ) { ++ return true; ++ } ++ return false; +}; + +var _checkDetailInfo = function(v) { - if (type_.isNull(v)) { - return true; - } - if (!type_.isArray(v)) { - return false; - } - for (var i = 0; i < v.length; ++i) { - if (!(v[i] instanceof tizen.NotificationDetailInfo)) { - return false; ++ if (type_.isNull(v)) { ++ return true; ++ } ++ if (!type_.isArray(v)) { ++ return false; ++ } ++ for (var i = 0; i < v.length; ++i) { ++ if (!(v[i] instanceof tizen.NotificationDetailInfo)) { ++ return false; ++ } + } - } - return true; ++ return true; +}; + +var _setDetailInfo = function(v) { - var _d = []; - for (var i = 0; i < v.length; ++i) { - _d.push(new tizen.NotificationDetailInfo(v[i].mainText, v[i].subText || null)); - } - return _d; ++ var _d = []; ++ for (var i = 0; i < v.length; ++i) { ++ _d.push(new tizen.NotificationDetailInfo(v[i].mainText, v[i].subText || null)); ++ } ++ return _d; +}; + +var _checkStringArray = function(v) { - if (type_.isNull(v)) { - return true; - } - if (!type_.isArray(v)) { - return false; - } - for (var i = 0; i < v.length; ++i) { - if (!type_.isString(v[i])) { - return false; ++ if (type_.isNull(v)) { ++ return true; ++ } ++ if (!type_.isArray(v)) { ++ return false; + } - } - return true; ++ for (var i = 0; i < v.length; ++i) { ++ if (!type_.isString(v[i])) { ++ return false; ++ } ++ } ++ return true; +}; + +var _isHex = function(v) { - return v.length === 7 && v.substr(0, 1) === '#' && (/^([0-9A-Fa-f]{2})+$/).test(v.substr(1, 7)); ++ return ( ++ v.length === 7 && ++ v.substr(0, 1) === '#' && ++ /^([0-9A-Fa-f]{2})+$/.test(v.substr(1, 7)) ++ ); +}; + - function NotificationInitDict(data) { - var _iconPath = null; - var _soundPath = null; - var _vibration = false; - var _appControl = null; - var _appId = null; - var _progressType = NotificationProgressType.PERCENTAGE; - var _progressValue = null; - var _number = null; - var _subIconPath = null; - var _detailInfo = []; - var _ledColor = null; - var _ledOnPeriod = 0; - var _ledOffPeriod = 0; - var _backgroundImagePath = null; - var _thumbnails = []; - - - Object.defineProperties(this, { - iconPath: { - get: function() { - return _iconPath; - }, - set: function(v) { - _iconPath = type_.isString(v) || type_.isNull(v) ? v : _iconPath; - }, - enumerable: true - }, - soundPath: { - get: function() { - return _soundPath; - }, - set: function(v) { - _soundPath = type_.isString(v) || type_.isNull(v) ? v : _soundPath; - }, - enumerable: true - }, - vibration: { - get: function() { - return _vibration; - }, - set: function(v) { - _vibration = type_.isBoolean(v) ? v : _vibration; - }, - enumerable: true - }, - appControl: { - get: function() { - return _appControl; - }, - set: function(v) { - _appControl = _edit.canEdit && v - ? new tizen.ApplicationControl(v.operation, v.uri || null, v.mime || null, v.category - || null, v.data || []) - : v instanceof tizen.ApplicationControl || type_.isNull(v) ? v : _appControl; - }, - enumerable: true - }, - appId: { - get: function() { - return _appId; - }, - set: function(v) { - _appId = type_.isString(v) && !(/\s/.test(v)) || type_.isNull(v) ? v : _appId; - }, - enumerable: true - }, - progressType: { - get: function() { - return _progressType; - }, - set: function(v) { - _progressType = Object.keys(NotificationProgressType).indexOf(v) >= 0 ? v : _progressType; - }, - enumerable: true - }, - progressValue: { - get: function() { - if (null === _progressValue) { - return _progressValue; + var _iconPath = null; + var _soundPath = null; + var _vibration = false; + var _appControl = null; + var _appId = null; + var _progressType = NotificationProgressType.PERCENTAGE; + var _progressValue = null; - var checkProgressValue = function(v) { - if ( - (_progressType === NotificationProgressType.PERCENTAGE && - (v >= 0 && v <= 100)) || - (_progressType === NotificationProgressType.BYTE && - converter_.toUnsignedLong(v) >= 0) - ) { - return true; - } - return false; - }; + var _number = null; + var _subIconPath = null; + var _detailInfo = []; - var checkDetailInfo = function(v) { - if (type_.isNull(v)) { - return true; - } - if (!type_.isArray(v)) { - return false; - } - for (var i = 0; i < v.length; ++i) { - if (!(v[i] instanceof tizen.NotificationDetailInfo)) { - return false; - } - } - return true; - }; - var setDetailInfo = function(v) { - var _d = []; - for (var i = 0; i < v.length; ++i) { - _d.push( - new tizen.NotificationDetailInfo(v[i].mainText, v[i].subText || null) - ); - } - return _d; - }; + var _ledColor = null; - var isHex = function(v) { - return ( - v.length === 7 && - v.substr(0, 1) === '#' && - /^([0-9A-Fa-f]{2})+$/.test(v.substr(1, 7)) - ); - }; + var _ledOnPeriod = 0; + var _ledOffPeriod = 0; + var _backgroundImagePath = null; + var _thumbnails = []; - var checkThumbnails = function(v) { - if (type_.isNull(v)) { - return true; - } - if (!type_.isArray(v)) { - return false; - } - for (var i = 0; i < v.length; ++i) { - if (!type_.isString(v[i])) { - return false; - } - } - return true; - }; + + Object.defineProperties(this, { + iconPath: { + get: function() { + return _iconPath; + }, + set: function(v) { + _iconPath = type_.isString(v) || type_.isNull(v) ? v : _iconPath; + }, + enumerable: true + }, + soundPath: { + get: function() { + return _soundPath; + }, + set: function(v) { + _soundPath = type_.isString(v) || type_.isNull(v) ? v : _soundPath; + }, + enumerable: true + }, + vibration: { + get: function() { + return _vibration; + }, + set: function(v) { + _vibration = type_.isBoolean(v) ? v : _vibration; + }, + enumerable: true + }, + appControl: { + get: function() { + return _appControl; + }, + set: function(v) { + _appControl = + _edit.canEdit && v + ? new tizen.ApplicationControl( + v.operation, + v.uri || null, + v.mime || null, + v.category || null, + v.data || [] + ) + : v instanceof tizen.ApplicationControl || type_.isNull(v) + ? v + : _appControl; + }, + enumerable: true + }, + appId: { + get: function() { + return _appId; + }, + set: function(v) { + _appId = + (type_.isString(v) && !/\s/.test(v)) || type_.isNull(v) ? v : _appId; + }, + enumerable: true + }, + progressType: { + get: function() { + return _progressType; + }, + set: function(v) { + _progressType = + Object.keys(NotificationProgressType).indexOf(v) >= 0 + ? v + : _progressType; + }, + enumerable: true + }, + progressValue: { + get: function() { + if (null === _progressValue) { + return _progressValue; + } + + return _progressType === NotificationProgressType.PERCENTAGE + ? _progressValue * 100 + : _progressValue; + }, + set: function(v) { + if (type_.isNull(v)) { + _progressValue = v; + return; + } - if (checkProgressValue(v)) { ++ if (_checkProgressValue(v, _progressType)) { + _progressValue = + _progressType === NotificationProgressType.PERCENTAGE + ? v / 100 + : converter_.toUnsignedLong(v); + } + }, + enumerable: true + }, + number: { + get: function() { + return _number; + }, + set: function(v) { + _number = type_.isNumber(v) || type_.isNull(v) ? v : _number; + }, + enumerable: true + }, + subIconPath: { + get: function() { + return _subIconPath; + }, + set: function(v) { + _subIconPath = type_.isString(v) || type_.isNull(v) ? v : _subIconPath; + }, + enumerable: true + }, + detailInfo: { + get: function() { + return _detailInfo; + }, + set: function(v) { + _detailInfo = + _edit.canEdit && v - ? setDetailInfo(v) - : checkDetailInfo(v) ++ ? _setDetailInfo(v) ++ : _checkDetailInfo(v) + ? v + : _detailInfo; + }, + enumerable: true + }, + ledColor: { + get: function() { + return _ledColor; + }, + set: function(v) { + _ledColor = - (type_.isString(v) && isHex(v)) || type_.isNull(v) ? v : _ledColor; ++ (type_.isString(v) && _isHex(v)) || type_.isNull(v) ? v : _ledColor; + }, + enumerable: true + }, + ledOnPeriod: { + get: function() { + return _ledOnPeriod; + }, + set: function(v) { + _ledOnPeriod = type_.isNumber(v) ? v : _ledOnPeriod; + }, + enumerable: true + }, + ledOffPeriod: { + get: function() { + return _ledOffPeriod; + }, + set: function(v) { + _ledOffPeriod = type_.isNumber(v) ? v : _ledOffPeriod; + }, + enumerable: true + }, + backgroundImagePath: { + get: function() { + return _backgroundImagePath; + }, + set: function(v) { + _backgroundImagePath = + type_.isString(v) || type_.isNull(v) ? v : _backgroundImagePath; + }, + enumerable: true + }, + thumbnails: { + get: function() { + return _thumbnails; + }, + set: function(v) { - _thumbnails = checkThumbnails(v) ? v : _thumbnails; ++ _thumbnails = _checkStringArray(v) ? v : _thumbnails; + }, + enumerable: true } + }); - return (_progressType === NotificationProgressType.PERCENTAGE) - ? _progressValue * 100 - : _progressValue; - }, - set: function(v) { - if (type_.isNull(v)) { - _progressValue = v; - return; - } - if (_checkProgressValue(v, _progressType)) { - _progressValue = (_progressType === NotificationProgressType.PERCENTAGE) - ? v / 100 - : converter_.toUnsignedLong(v); + if (data instanceof _global.Object) { + for (var prop in data) { + if (this.hasOwnProperty(prop)) { + this[prop] = data[prop]; + } } - }, - enumerable: true - }, - number: { - get: function() { - return _number; - }, - set: function(v) { - _number = type_.isNumber(v) || type_.isNull(v) ? v : _number; - }, - enumerable: true - }, - subIconPath: { - get: function() { - return _subIconPath; - }, - set: function(v) { - _subIconPath = type_.isString(v) || type_.isNull(v) ? v : _subIconPath; - }, - enumerable: true - }, - detailInfo: { - get: function() { - return _detailInfo; - }, - set: function(v) { - _detailInfo = _edit.canEdit && v ? _setDetailInfo(v) : _checkDetailInfo(v) ? v : _detailInfo; - }, - enumerable: true - }, - ledColor: { - get: function() { - return _ledColor; - }, - set: function(v) { - _ledColor = (type_.isString(v) && _isHex(v)) || type_.isNull(v) ? v : _ledColor; - }, - enumerable: true - }, - ledOnPeriod: { - get: function() { - return _ledOnPeriod; - }, - set: function(v) { - _ledOnPeriod = type_.isNumber(v) ? v : _ledOnPeriod; - }, - enumerable: true - }, - ledOffPeriod: { - get: function() { - return _ledOffPeriod; - }, - set: function(v) { - _ledOffPeriod = type_.isNumber(v) ? v : _ledOffPeriod; - }, - enumerable: true - }, - backgroundImagePath: { - get: function() { - return _backgroundImagePath; - }, - set: function(v) { - _backgroundImagePath = type_.isString(v) || type_.isNull(v) ? v : _backgroundImagePath; - }, - enumerable: true - }, - thumbnails: { - get: function() { - return _thumbnails; - }, - set: function(v) { - _thumbnails = _checkStringArray(v) ? v : _thumbnails; - }, - enumerable: true } - }); - - if (data instanceof _global.Object) { - for (var prop in data) { - if (this.hasOwnProperty(prop)) { - this[prop] = data[prop]; - } - } - } } function Notification(data) { @@@ -656,532 -568,65 +697,575 @@@ } function StatusNotification(statusType, title, notificationInitDict) { - validator_.isConstructorCall(this, StatusNotification); - type_.isObject(notificationInitDict) ? - notificationInitDict.title = title : - notificationInitDict = {title: title}; - NotificationInitDict.call(this, notificationInitDict); - Notification.call(this, notificationInitDict); - - utils_.warn('DEPRECATION WARNING: StatusNotification is deprecated since Tizen 4.0. Use UserNotification instead.'); - - var _statusType = (Object.keys(StatusNotificationType)).indexOf(statusType) >= 0 - ? statusType : StatusNotificationType.SIMPLE; - - Object.defineProperties(this, { - statusType: { - get: function() { - return _statusType; - }, - set: function(v) { - _statusType = (Object.keys(StatusNotificationType)).indexOf(v) >= 0 && _edit.canEdit - ? v : _statusType; - }, - enumerable: true - } - }); + validator_.isConstructorCall(this, StatusNotification); + type_.isObject(notificationInitDict) + ? (notificationInitDict.title = title) + : (notificationInitDict = { title: title }); + NotificationInitDict.call(this, notificationInitDict); + Notification.call(this, notificationInitDict); + ++ utils_.warn( ++ 'DEPRECATION WARNING: StatusNotification is deprecated since Tizen 4.0. ' + ++ 'Use UserNotification instead.' ++ ); ++ + var _statusType = + Object.keys(StatusNotificationType).indexOf(statusType) >= 0 + ? statusType + : StatusNotificationType.SIMPLE; + + Object.defineProperties(this, { + statusType: { + get: function() { + return _statusType; + }, + set: function(v) { + _statusType = + Object.keys(StatusNotificationType).indexOf(v) >= 0 && _edit.canEdit + ? v + : _statusType; + }, + enumerable: true + } + }); } StatusNotification.prototype = new Notification(); StatusNotification.prototype.constructor = StatusNotification; function NotificationDetailInfo(mainText, subText) { - validator_.isConstructorCall(this, NotificationDetailInfo); - - var _mainText = type_.isString(mainText) ? mainText : ''; - var _subText = type_.isString(subText) ? subText : null; - - Object.defineProperties(this, { - mainText: { - get: function() { - return _mainText; - }, - set: function(v) { - _mainText = type_.isString(v) ? v : _mainText; - }, - enumerable: true - }, - subText: { - get: function() { - return _subText; - }, - set: function(v) { - _subText = type_.isString(v) ? v : _subText; - }, - enumerable: true - } - }); + validator_.isConstructorCall(this, NotificationDetailInfo); + + var _mainText = type_.isString(mainText) ? mainText : ''; + var _subText = type_.isString(subText) ? subText : null; + + Object.defineProperties(this, { + mainText: { + get: function() { + return _mainText; + }, + set: function(v) { + _mainText = type_.isString(v) ? v : _mainText; + }, + enumerable: true + }, + subText: { + get: function() { + return _subText; + }, + set: function(v) { + _subText = type_.isString(v) ? v : _subText; + }, + enumerable: true + } + }); } +function TextContentsInitDict(data) { - if (!this) return; - var _progressType = NotificationProgressType.PERCENTAGE; - var _progressValue = null; - var _number = null; - var _detailInfo = []; - var _buttonsTexts = []; - var _contentForOff = null; - - Object.defineProperties(this, { - progressType: { - get: function() { - return _progressType; - }, - set: function(v) { - _progressType = Object.keys(NotificationProgressType).indexOf(v) >= 0 ? v : _progressType; - }, - enumerable: true - }, - progressValue: { - get: function() { - if (null === _progressValue) { - return _progressValue; ++ if (!this) return; ++ var _progressType = NotificationProgressType.PERCENTAGE; ++ var _progressValue = null; ++ var _number = null; ++ var _detailInfo = []; ++ var _buttonsTexts = []; ++ var _contentForOff = null; ++ ++ Object.defineProperties(this, { ++ progressType: { ++ get: function() { ++ return _progressType; ++ }, ++ set: function(v) { ++ _progressType = ++ Object.keys(NotificationProgressType).indexOf(v) >= 0 ++ ? v ++ : _progressType; ++ }, ++ enumerable: true ++ }, ++ progressValue: { ++ get: function() { ++ if (null === _progressValue) { ++ return _progressValue; ++ } ++ ++ return _progressType === NotificationProgressType.PERCENTAGE ++ ? _progressValue * 100 ++ : _progressValue; ++ }, ++ set: function(v) { ++ if (type_.isNull(v)) { ++ _progressValue = v; ++ return; ++ } ++ if (_checkProgressValue(v, _progressType)) { ++ _progressValue = ++ _progressType === NotificationProgressType.PERCENTAGE ++ ? v / 100 ++ : converter_.toUnsignedLong(v); ++ } ++ }, ++ enumerable: true ++ }, ++ eventsNumber: { ++ get: function() { ++ return _number; ++ }, ++ set: function(v) { ++ _number = type_.isNumber(v) || type_.isNull(v) ? v : _number; ++ }, ++ enumerable: true ++ }, ++ detailInfo: { ++ get: function() { ++ return _detailInfo; ++ }, ++ set: function(v) { ++ _detailInfo = ++ _edit.canEdit && v ++ ? _setDetailInfo(v) ++ : _checkDetailInfo(v) ++ ? v ++ : _detailInfo; ++ }, ++ enumerable: true ++ }, ++ buttonsTexts: { ++ get: function() { ++ return _buttonsTexts; ++ }, ++ set: function(v) { ++ _buttonsTexts = _checkStringArray(v) ? v : _buttonsTexts; ++ }, ++ enumerable: true ++ }, ++ contentForOff: { ++ get: function() { ++ return _contentForOff; ++ }, ++ set: function(v) { ++ _contentForOff = ++ type_.isString(v) || type_.isNull(v) ? v : _contentForOff; ++ }, ++ enumerable: true + } ++ }); + - return (_progressType === NotificationProgressType.PERCENTAGE) - ? _progressValue * 100 - : _progressValue; - }, - set: function(v) { - if (type_.isNull(v)) { - _progressValue = v; - return; - } - if (_checkProgressValue(v, _progressType)) { - _progressValue = (_progressType === NotificationProgressType.PERCENTAGE) - ? v / 100 - : converter_.toUnsignedLong(v); ++ if (data instanceof _global.Object) { ++ this['progressType'] = data['progressType']; ++ for (var prop in data) { ++ if (this.hasOwnProperty(prop)) { ++ this[prop] = data[prop]; ++ } + } - }, - enumerable: true - }, - eventsNumber: { - get: function() { - return _number; - }, - set: function(v) { - _number = type_.isNumber(v) || type_.isNull(v) ? v : _number; - }, - enumerable: true - }, - detailInfo: { - get: function() { - return _detailInfo; - }, - set: function(v) { - _detailInfo = _edit.canEdit && v ? _setDetailInfo(v) : _checkDetailInfo(v) ? v : _detailInfo; - }, - enumerable: true - }, - buttonsTexts: { - get: function() { - return _buttonsTexts; - }, - set: function(v) { - _buttonsTexts = _checkStringArray(v) ? v : _buttonsTexts; - }, - enumerable: true - }, - contentForOff: { - get: function() { - return _contentForOff; - }, - set: function(v) { - _contentForOff = type_.isString(v) || type_.isNull(v) ? v : _contentForOff; - }, - enumerable: true - } - }); - - if (data instanceof _global.Object) { - this['progressType'] = data['progressType']; - for (var prop in data) { - if (this.hasOwnProperty(prop)) { - this[prop] = data[prop]; - } + } - } +} + +function ImagesInitDict(data) { - if (!this) return; - var _iconPath = null; - var _subIconPath = null; - var _indicatorIconPath = null; - var _lockScreenIconPath = null; - var _buttonIconPaths = []; - var _backgroundImagePath = null; - - Object.defineProperties(this, { - iconPath: { - get: function() { - return _iconPath; - }, - set: function(v) { - _iconPath = type_.isString(v) || type_.isNull(v) ? v : _iconPath; - }, - enumerable: true - }, - subIconPath: { - get: function() { - return _subIconPath; - }, - set: function(v) { - _subIconPath = type_.isString(v) || type_.isNull(v) ? v : _subIconPath; - }, - enumerable: true - }, - indicatorIconPath: { - get: function() { - return _indicatorIconPath; - }, - set: function(v) { - _indicatorIconPath = type_.isString(v) || type_.isNull(v) ? v : _indicatorIconPath; - }, - enumerable: true - }, - lockScreenIconPath: { - get: function() { - return _lockScreenIconPath; - }, - set: function(v) { - _lockScreenIconPath = type_.isString(v) || type_.isNull(v) ? v : _lockScreenIconPath; - }, - enumerable: true - }, - buttonIconPaths: { - get: function() { - return _buttonIconPaths; - }, - set: function(v) { - _buttonIconPaths = _checkStringArray(v) ? v : _buttonIconPaths; - }, - enumerable: true - }, - backgroundImagePath: { - get: function() { - return _backgroundImagePath; - }, - set: function(v) { - _backgroundImagePath = type_.isString(v) || type_.isNull(v) ? v : _backgroundImagePath; - }, - enumerable: true - } - }); ++ if (!this) return; ++ var _iconPath = null; ++ var _subIconPath = null; ++ var _indicatorIconPath = null; ++ var _lockScreenIconPath = null; ++ var _buttonIconPaths = []; ++ var _backgroundImagePath = null; ++ ++ Object.defineProperties(this, { ++ iconPath: { ++ get: function() { ++ return _iconPath; ++ }, ++ set: function(v) { ++ _iconPath = type_.isString(v) || type_.isNull(v) ? v : _iconPath; ++ }, ++ enumerable: true ++ }, ++ subIconPath: { ++ get: function() { ++ return _subIconPath; ++ }, ++ set: function(v) { ++ _subIconPath = type_.isString(v) || type_.isNull(v) ? v : _subIconPath; ++ }, ++ enumerable: true ++ }, ++ indicatorIconPath: { ++ get: function() { ++ return _indicatorIconPath; ++ }, ++ set: function(v) { ++ _indicatorIconPath = ++ type_.isString(v) || type_.isNull(v) ? v : _indicatorIconPath; ++ }, ++ enumerable: true ++ }, ++ lockScreenIconPath: { ++ get: function() { ++ return _lockScreenIconPath; ++ }, ++ set: function(v) { ++ _lockScreenIconPath = ++ type_.isString(v) || type_.isNull(v) ? v : _lockScreenIconPath; ++ }, ++ enumerable: true ++ }, ++ buttonIconPaths: { ++ get: function() { ++ return _buttonIconPaths; ++ }, ++ set: function(v) { ++ _buttonIconPaths = _checkStringArray(v) ? v : _buttonIconPaths; ++ }, ++ enumerable: true ++ }, ++ backgroundImagePath: { ++ get: function() { ++ return _backgroundImagePath; ++ }, ++ set: function(v) { ++ _backgroundImagePath = ++ type_.isString(v) || type_.isNull(v) ? v : _backgroundImagePath; ++ }, ++ enumerable: true ++ } ++ }); + - if (data instanceof _global.Object) { - for (var prop in data) { - if (this.hasOwnProperty(prop)) { - this[prop] = data[prop]; - } ++ if (data instanceof _global.Object) { ++ for (var prop in data) { ++ if (this.hasOwnProperty(prop)) { ++ this[prop] = data[prop]; ++ } ++ } + } - } +} + +function ThumbnailsInitDict(data) { - if (!this) return; - var _lockScreenThumbnailIconPath = null; - var _thumbnailIconPath = null; - var _thumbnails = []; - - Object.defineProperties(this, { - lockScreenThumbnailIconPath: { - get: function() { - return _lockScreenThumbnailIconPath; - }, - set: function(v) { - _lockScreenThumbnailIconPath = type_.isString(v) || type_.isNull(v) ? v : _lockScreenThumbnailIconPath; - }, - enumerable: true - }, - thumbnailIconPath: { - get: function() { - return _thumbnailIconPath; - }, - set: function(v) { - _thumbnailIconPath = type_.isString(v) || type_.isNull(v) ? v : _thumbnailIconPath; - }, - enumerable: true - }, - thumbnails: { - get: function() { - return _thumbnails; - }, - set: function(v) { - _thumbnails = _checkStringArray(v) ? v : _thumbnails; - }, - enumerable: true - } - }); ++ if (!this) return; ++ var _lockScreenThumbnailIconPath = null; ++ var _thumbnailIconPath = null; ++ var _thumbnails = []; ++ ++ Object.defineProperties(this, { ++ lockScreenThumbnailIconPath: { ++ get: function() { ++ return _lockScreenThumbnailIconPath; ++ }, ++ set: function(v) { ++ _lockScreenThumbnailIconPath = ++ type_.isString(v) || type_.isNull(v) ++ ? v ++ : _lockScreenThumbnailIconPath; ++ }, ++ enumerable: true ++ }, ++ thumbnailIconPath: { ++ get: function() { ++ return _thumbnailIconPath; ++ }, ++ set: function(v) { ++ _thumbnailIconPath = ++ type_.isString(v) || type_.isNull(v) ? v : _thumbnailIconPath; ++ }, ++ enumerable: true ++ }, ++ thumbnails: { ++ get: function() { ++ return _thumbnails; ++ }, ++ set: function(v) { ++ _thumbnails = _checkStringArray(v) ? v : _thumbnails; ++ }, ++ enumerable: true ++ } ++ }); + - if (data instanceof _global.Object) { - for (var prop in data) { - if (this.hasOwnProperty(prop)) { - this[prop] = data[prop]; - } ++ if (data instanceof _global.Object) { ++ for (var prop in data) { ++ if (this.hasOwnProperty(prop)) { ++ this[prop] = data[prop]; ++ } ++ } + } - } +} + +function ActionsInitDict(data) { - if (!this) return; - var _soundPath = null; - var _vibration = false; - var _appControl = null; - var _appId = null; - - Object.defineProperties(this, { - soundPath: { - get: function() { - return _soundPath; - }, - set: function(v) { - _soundPath = type_.isString(v) || type_.isNull(v) ? v : _soundPath; - }, - enumerable: true - }, - vibration: { - get: function() { - return _vibration; - }, - set: function(v) { - _vibration = type_.isBoolean(v) ? v : _vibration; - }, - enumerable: true - }, - appControl: { - get: function() { - return _appControl; - }, - set: function(v) { - _appControl = _edit.canEdit && v - ? new tizen.ApplicationControl(v.operation, v.uri || null, v.mime || null, v.category - || null, v.data || []) - : v instanceof tizen.ApplicationControl || type_.isNull(v) ? v : _appControl; - }, - enumerable: true - }, - appId: { - get: function() { - return _appId; - }, - set: function(v) { - _appId = type_.isString(v) && !(/\s/.test(v)) || type_.isNull(v) ? v : _appId; - }, - enumerable: true - } - }); ++ if (!this) return; ++ var _soundPath = null; ++ var _vibration = false; ++ var _appControl = null; ++ var _appId = null; ++ ++ Object.defineProperties(this, { ++ soundPath: { ++ get: function() { ++ return _soundPath; ++ }, ++ set: function(v) { ++ _soundPath = type_.isString(v) || type_.isNull(v) ? v : _soundPath; ++ }, ++ enumerable: true ++ }, ++ vibration: { ++ get: function() { ++ return _vibration; ++ }, ++ set: function(v) { ++ _vibration = type_.isBoolean(v) ? v : _vibration; ++ }, ++ enumerable: true ++ }, ++ appControl: { ++ get: function() { ++ return _appControl; ++ }, ++ set: function(v) { ++ _appControl = ++ _edit.canEdit && v ++ ? new tizen.ApplicationControl( ++ v.operation, ++ v.uri || null, ++ v.mime || null, ++ v.category || null, ++ v.data || [] ++ ) ++ : v instanceof tizen.ApplicationControl || type_.isNull(v) ++ ? v ++ : _appControl; ++ }, ++ enumerable: true ++ }, ++ appId: { ++ get: function() { ++ return _appId; ++ }, ++ set: function(v) { ++ _appId = ++ (type_.isString(v) && !/\s/.test(v)) || type_.isNull(v) ? v : _appId; ++ }, ++ enumerable: true ++ } ++ }); + - if (data instanceof _global.Object) { - for (var prop in data) { - if (this.hasOwnProperty(prop)) { - this[prop] = data[prop]; - } ++ if (data instanceof _global.Object) { ++ for (var prop in data) { ++ if (this.hasOwnProperty(prop)) { ++ this[prop] = data[prop]; ++ } ++ } + } - } +} + +function GroupContentsInitDict(data) { - if (!this) return; - var _groupTitle = null; - var _groupContent = null; - var _groupContentForOff = null; - - Object.defineProperties(this, { - groupTitle: { - get: function() { - return _groupTitle; - }, - set: function(v) { - _groupTitle = type_.isString(v) || type_.isNull(v) ? v : _groupTitle; - }, - enumerable: true - }, - groupContent: { - get: function() { - return _groupContent; - }, - set: function(v) { - _groupContent = type_.isString(v) || type_.isNull(v) ? v : _groupContent; - }, - enumerable: true - }, - groupContentForOff: { - get: function() { - return _groupContentForOff; - }, - set: function(v) { - _groupContentForOff = type_.isString(v) || type_.isNull(v) ? v : _groupContentForOff; - }, - enumerable: true - } - }); ++ if (!this) return; ++ var _groupTitle = null; ++ var _groupContent = null; ++ var _groupContentForOff = null; ++ ++ Object.defineProperties(this, { ++ groupTitle: { ++ get: function() { ++ return _groupTitle; ++ }, ++ set: function(v) { ++ _groupTitle = type_.isString(v) || type_.isNull(v) ? v : _groupTitle; ++ }, ++ enumerable: true ++ }, ++ groupContent: { ++ get: function() { ++ return _groupContent; ++ }, ++ set: function(v) { ++ _groupContent = type_.isString(v) || type_.isNull(v) ? v : _groupContent; ++ }, ++ enumerable: true ++ }, ++ groupContentForOff: { ++ get: function() { ++ return _groupContentForOff; ++ }, ++ set: function(v) { ++ _groupContentForOff = ++ type_.isString(v) || type_.isNull(v) ? v : _groupContentForOff; ++ }, ++ enumerable: true ++ } ++ }); + - if (data instanceof _global.Object) { - for (var prop in data) { - if (this.hasOwnProperty(prop)) { - this[prop] = data[prop]; - } ++ if (data instanceof _global.Object) { ++ for (var prop in data) { ++ if (this.hasOwnProperty(prop)) { ++ this[prop] = data[prop]; ++ } ++ } + } - } +} + +function LedsInitDict(data) { - if (!this) return; - var _ledColor = null; - var _ledOnPeriod = 0; - var _ledOffPeriod = 0; - - Object.defineProperties(this, { - ledColor: { - get: function() { - return _ledColor; - }, - set: function(v) { - _ledColor = (type_.isString(v) && _isHex(v)) || type_.isNull(v) ? v : _ledColor; - }, - enumerable: true - }, - ledOnPeriod: { - get: function() { - return _ledOnPeriod; - }, - set: function(v) { - _ledOnPeriod = type_.isNumber(v) ? v : _ledOnPeriod; - }, - enumerable: true - }, - ledOffPeriod: { - get: function() { - return _ledOffPeriod; - }, - set: function(v) { - _ledOffPeriod = type_.isNumber(v) ? v : _ledOffPeriod; - }, - enumerable: true - } - }); ++ if (!this) return; ++ var _ledColor = null; ++ var _ledOnPeriod = 0; ++ var _ledOffPeriod = 0; ++ ++ Object.defineProperties(this, { ++ ledColor: { ++ get: function() { ++ return _ledColor; ++ }, ++ set: function(v) { ++ _ledColor = ++ (type_.isString(v) && _isHex(v)) || type_.isNull(v) ? v : _ledColor; ++ }, ++ enumerable: true ++ }, ++ ledOnPeriod: { ++ get: function() { ++ return _ledOnPeriod; ++ }, ++ set: function(v) { ++ _ledOnPeriod = type_.isNumber(v) ? v : _ledOnPeriod; ++ }, ++ enumerable: true ++ }, ++ ledOffPeriod: { ++ get: function() { ++ return _ledOffPeriod; ++ }, ++ set: function(v) { ++ _ledOffPeriod = type_.isNumber(v) ? v : _ledOffPeriod; ++ }, ++ enumerable: true ++ } ++ }); + - if (data instanceof _global.Object) { - for (var prop in data) { - if (this.hasOwnProperty(prop)) { - this[prop] = data[prop]; - } ++ if (data instanceof _global.Object) { ++ for (var prop in data) { ++ if (this.hasOwnProperty(prop)) { ++ this[prop] = data[prop]; ++ } ++ } + } - } +} + +function UserNotification(userType, title, notificationGroupedInitDict) { - validator_.isConstructorCall(this, UserNotification); - type_.isObject(notificationGroupedInitDict) ? - notificationGroupedInitDict.title = title : - notificationGroupedInitDict = {title: title}; - UserNotificationInitDict.call(this, notificationGroupedInitDict); - Notification.call(this, notificationGroupedInitDict); - - this.textContents = new TextContentsInitDict(notificationGroupedInitDict.textContents); - this.images = new ImagesInitDict(notificationGroupedInitDict.images); - this.thumbnails = new ThumbnailsInitDict(notificationGroupedInitDict.thumbnails); - this.actions = new ActionsInitDict(notificationGroupedInitDict.actions); - this.leds = new LedsInitDict(notificationGroupedInitDict.leds); - this.groupContents = new GroupContentsInitDict(notificationGroupedInitDict.groupContents); - - var _userType = (Object.keys(UserNotificationType)).indexOf(userType) >= 0 - ? userType : StatusNotificationType.SIMPLE; - - Object.defineProperties(this, { - userType: { - get: function() { - return _userType; - }, - set: function(v) { - _userType = (Object.keys(StatusNotificationType)).indexOf(v) >= 0 && _edit.canEdit - ? v : _userType; - }, - enumerable: true - } - }); ++ validator_.isConstructorCall(this, UserNotification); ++ type_.isObject(notificationGroupedInitDict) ++ ? (notificationGroupedInitDict.title = title) ++ : (notificationGroupedInitDict = { title: title }); ++ UserNotificationInitDict.call(this, notificationGroupedInitDict); ++ Notification.call(this, notificationGroupedInitDict); ++ ++ this.textContents = new TextContentsInitDict( ++ notificationGroupedInitDict.textContents ++ ); ++ this.images = new ImagesInitDict(notificationGroupedInitDict.images); ++ this.thumbnails = new ThumbnailsInitDict(notificationGroupedInitDict.thumbnails); ++ this.actions = new ActionsInitDict(notificationGroupedInitDict.actions); ++ this.leds = new LedsInitDict(notificationGroupedInitDict.leds); ++ this.groupContents = new GroupContentsInitDict( ++ notificationGroupedInitDict.groupContents ++ ); ++ ++ var _userType = ++ Object.keys(UserNotificationType).indexOf(userType) >= 0 ++ ? userType ++ : StatusNotificationType.SIMPLE; ++ ++ Object.defineProperties(this, { ++ userType: { ++ get: function() { ++ return _userType; ++ }, ++ set: function(v) { ++ _userType = ++ Object.keys(StatusNotificationType).indexOf(v) >= 0 && _edit.canEdit ++ ? v ++ : _userType; ++ }, ++ enumerable: true ++ } ++ }); +} + +UserNotification.prototype = new Notification(); +UserNotification.prototype.constructor = UserNotification; + +function UserNotificationInitDict(data) { - var _textContents = null; - var _images = null; - var _thumbnails = null; - var _actions = null; - var _groupContents = null; - var _leds = null; - - Object.defineProperties(this, { - textContents: { - get: function() { - return _textContents; - }, - set: function(v) { - _textContents = type_.isObject(v) || type_.isNull(v) ? v : _textContents; - }, - enumerable: true - }, - images: { - get: function() { - return _images; - }, - set: function(v) { - _images = type_.isObject(v) || type_.isNull(v) ? v : _images; - }, - enumerable: true - }, - thumbnails: { - get: function() { - return _thumbnails; - }, - set: function(v) { - _thumbnails = type_.isObject(v) || type_.isNull(v) ? v : _thumbnails; - }, - enumerable: true - }, - actions: { - get: function() { - return _actions; - }, - set: function(v) { - _actions = type_.isObject(v) || type_.isNull(v) ? v : _actions; - }, - enumerable: true - }, - groupContents: { - get: function() { - return _groupContents; - }, - set: function(v) { - _groupContents = type_.isObject(v) || type_.isNull(v) ? v : _groupContents; - }, - enumerable: true - }, - leds: { - get: function() { - return _leds; - }, - set: function(v) { - _leds = type_.isObject(v) || type_.isNull(v) ? v : _leds; - }, - enumerable: true - } - }); ++ var _textContents = null; ++ var _images = null; ++ var _thumbnails = null; ++ var _actions = null; ++ var _groupContents = null; ++ var _leds = null; ++ ++ Object.defineProperties(this, { ++ textContents: { ++ get: function() { ++ return _textContents; ++ }, ++ set: function(v) { ++ _textContents = type_.isObject(v) || type_.isNull(v) ? v : _textContents; ++ }, ++ enumerable: true ++ }, ++ images: { ++ get: function() { ++ return _images; ++ }, ++ set: function(v) { ++ _images = type_.isObject(v) || type_.isNull(v) ? v : _images; ++ }, ++ enumerable: true ++ }, ++ thumbnails: { ++ get: function() { ++ return _thumbnails; ++ }, ++ set: function(v) { ++ _thumbnails = type_.isObject(v) || type_.isNull(v) ? v : _thumbnails; ++ }, ++ enumerable: true ++ }, ++ actions: { ++ get: function() { ++ return _actions; ++ }, ++ set: function(v) { ++ _actions = type_.isObject(v) || type_.isNull(v) ? v : _actions; ++ }, ++ enumerable: true ++ }, ++ groupContents: { ++ get: function() { ++ return _groupContents; ++ }, ++ set: function(v) { ++ _groupContents = ++ type_.isObject(v) || type_.isNull(v) ? v : _groupContents; ++ }, ++ enumerable: true ++ }, ++ leds: { ++ get: function() { ++ return _leds; ++ }, ++ set: function(v) { ++ _leds = type_.isObject(v) || type_.isNull(v) ? v : _leds; ++ }, ++ enumerable: true ++ } ++ }); + - if (data instanceof _global.Object) { - for (var prop in data) { - if (this.hasOwnProperty(prop)) { - this[prop] = data[prop]; - } ++ if (data instanceof _global.Object) { ++ for (var prop in data) { ++ if (this.hasOwnProperty(prop)) { ++ this[prop] = data[prop]; ++ } ++ } + } - } +} + exports = new NotificationManager(); tizen.StatusNotification = StatusNotification; +tizen.UserNotification = UserNotification; tizen.NotificationDetailInfo = NotificationDetailInfo; diff --cc src/ppm/ppm_api.js index 6bc52a06,00000000..e6fa82a0 mode 100644,000000..100644 --- a/src/ppm/ppm_api.js +++ b/src/ppm/ppm_api.js @@@ -1,71 -1,0 +1,69 @@@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + - +var validator_ = xwalk.utils.validator; +var type_ = xwalk.utils.type; +var types_ = validator_.Types; +var native_ = new xwalk.utils.NativeManager(extension); + - function PPMManager() { - } ++function PPMManager() {} + +PPMManager.prototype.checkPermission = function() { - var args = validator_.validateArgs(arguments, [ - { name: 'privilege', type: types_.STRING } - ]); ++ var args = validator_.validateArgs(arguments, [ ++ { name: 'privilege', type: types_.STRING } ++ ]); + - var callArgs = { - privilege: args.privilege - }; ++ var callArgs = { ++ privilege: args.privilege ++ }; + - var result = native_.callSync('PPMManager_checkPermission', callArgs); ++ var result = native_.callSync('PPMManager_checkPermission', callArgs); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } + - return native_.getResultObject(result); ++ return native_.getResultObject(result); +}; + +PPMManager.prototype.requestPermission = function() { + var args = validator_.validateArgs(arguments, [ + { name: 'privilege', type: types_.STRING }, + { name: 'successCallback', type: types_.FUNCTION }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); + + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + } else { + args.successCallback(result.result, result.privilege); + } + }; + + var callArgs = { + privilege: args.privilege + }; + + var result = native_.call('PPMManager_requestPermission', callArgs, callback); + + if (native_.isFailure(result)) { - throw native_.getErrorObject(result); ++ throw native_.getErrorObject(result); + } +}; + +// Exports - exports = new PPMManager(); ++exports = new PPMManager(); diff --cc src/sensor/sensor_api.js index 41c744e0,17d280aa..9305c4f1 --- a/src/sensor/sensor_api.js +++ b/src/sensor/sensor_api.js @@@ -24,19 -24,16 +24,19 @@@ var native_ = new utils_.NativeManager( // Enums var SensorType = { - LIGHT : 'LIGHT', - MAGNETIC : 'MAGNETIC', - PRESSURE : 'PRESSURE', - PROXIMITY : 'PROXIMITY', - ULTRAVIOLET : 'ULTRAVIOLET', - HRM_RAW : 'HRM_RAW', - GRAVITY : 'GRAVITY', - GYROSCOPE : 'GYROSCOPE', - GYROSCOPE_ROTATION_VECTOR : 'GYROSCOPE_ROTATION_VECTOR', - LINEAR_ACCELERATION : 'LINEAR_ACCELERATION', - MAGNETIC_UNCALIBRATED : 'MAGNETIC_UNCALIBRATED', - GYROSCOPE_UNCALIBRATED : 'GYROSCOPE_UNCALIBRATED', - ACCELERATION : 'ACCELERATION' + LIGHT: 'LIGHT', + MAGNETIC: 'MAGNETIC', + PRESSURE: 'PRESSURE', + PROXIMITY: 'PROXIMITY', + ULTRAVIOLET: 'ULTRAVIOLET', + HRM_RAW: 'HRM_RAW', + GRAVITY: 'GRAVITY', + GYROSCOPE: 'GYROSCOPE', + GYROSCOPE_ROTATION_VECTOR: 'GYROSCOPE_ROTATION_VECTOR', - LINEAR_ACCELERATION: 'LINEAR_ACCELERATION' ++ LINEAR_ACCELERATION: 'LINEAR_ACCELERATION', ++ MAGNETIC_UNCALIBRATED: 'MAGNETIC_UNCALIBRATED', ++ GYROSCOPE_UNCALIBRATED: 'GYROSCOPE_UNCALIBRATED', ++ ACCELERATION: 'ACCELERATION' }; var ProximityState = { @@@ -99,9 -97,11 +100,9 @@@ SensorListener.prototype.start = functi } }; - SensorListener.prototype.stop = function () { + SensorListener.prototype.stop = function() { if (SensorStates.NOT_STARTED != this.state) { - var result = native_.callSync('Sensor_stop', {'sensorType' : this.sensorType}); - var result = native_.callSync('Sensor_stop', { - sensorType: this.sensorType - }); ++ var result = native_.callSync('Sensor_stop', { sensorType: this.sensorType }); if (native_.isFailure(result)) { throw native_.getErrorObject(result); } @@@ -165,23 -173,20 +174,23 @@@ SensorListener.prototype.getData = func var _supportedSensors = []; var _isChecked = false; var _sensorListeners = { - 'LIGHT' : {}, - 'MAGNETIC' : {}, - 'PRESSURE' : {}, - 'PROXIMITY' : {}, - 'ULTRAVIOLET' : {}, - 'HRM_RAW' : {}, - 'GRAVITY' : {}, - 'GYROSCOPE' : {}, - 'GYROSCOPE_ROTATION_VECTOR' : {}, - 'LINEAR_ACCELERATION' : {}, - 'MAGNETIC_UNCALIBRATED' : {}, - 'GYROSCOPE_UNCALIBRATED' : {}, - 'ACCELERATION' : {} - }; - - var errorWrapper = function (err) { - if(err.name === "UnknownError") { + LIGHT: {}, + MAGNETIC: {}, + PRESSURE: {}, + PROXIMITY: {}, + ULTRAVIOLET: {}, + HRM_RAW: {}, + GRAVITY: {}, + GYROSCOPE: {}, + GYROSCOPE_ROTATION_VECTOR: {}, - LINEAR_ACCELERATION: {} ++ LINEAR_ACCELERATION: {}, ++ MAGNETIC_UNCALIBRATED: {}, ++ GYROSCOPE_UNCALIBRATED: {}, ++ ACCELERATION: {} + }; + + var errorWrapper = function(err) { + if (err.name === 'UnknownError') { err = new WebAPIException(WebAPIException.ABORT_ERR, err.message); } @@@ -241,23 -245,17 +249,23 @@@ function getDefaultSensor() return new HRMRawSensor(); } else if (_supportedSensors[index] === SensorType.GRAVITY) { return new GravitySensor(); - } else if (_supportedSensors[index] === SensorType.GYROSCOPE){ + } else if (_supportedSensors[index] === SensorType.GYROSCOPE) { return new GyroscopeSensor(); - } else if (_supportedSensors[index] === SensorType.GYROSCOPE_ROTATION_VECTOR){ + } else if (_supportedSensors[index] === SensorType.GYROSCOPE_ROTATION_VECTOR) { return new GyroscopeRotationVectorSensor(); - } else if (_supportedSensors[index] === SensorType.LINEAR_ACCELERATION){ + } else if (_supportedSensors[index] === SensorType.LINEAR_ACCELERATION) { return new LinearAccelerationSensor(); + } else if (_supportedSensors[index] === SensorType.MAGNETIC_UNCALIBRATED) { + return new MagneticUncalibratedSensor(); + } else if (_supportedSensors[index] === SensorType.GYROSCOPE_UNCALIBRATED) { + return new GyroscopeUncalibratedSensor(); + } else if (_supportedSensors[index] === SensorType.ACCELERATION) { + return new AccelerationSensor(); } - }; + } SensorService.prototype.getDefaultSensor = function() { - return getDefaultSensor.apply(this, arguments); + return getDefaultSensor.apply(this, arguments); }; SensorService.prototype.getAvailableSensors = function() { @@@ -268,11 -266,11 +276,11 @@@ return _supportedSensors.slice(); }; - //////////////////////Sensor classes////////////////////////////////////////////////////////// -//////////////////////Sensor classes////////////////////// ++//////////////////////Sensor classes///////////////////////////// //// Base Sensor class - var Sensor = function (type) { + var Sensor = function(type) { Object.defineProperties(this, { - sensorType : {value: type, writable: false, enumerable: true} + sensorType: { value: type, writable: false, enumerable: true } }); }; @@@ -581,22 -595,27 +605,26 @@@ var GyroscopeRotationVectorSensor = fun GyroscopeRotationVectorSensor.prototype = new Sensor(); GyroscopeRotationVectorSensor.prototype.constructor = Sensor; -- - GyroscopeRotationVectorSensor.prototype.getGyroscopeRotationVectorSensorData = function() { + // prettier-ignore + GyroscopeRotationVectorSensor.prototype.getGyroscopeRotationVectorSensorData = + function() { var args = validator_.validateArgs(arguments, [ - { - name : 'successCallback', - type : types_.FUNCTION - }, - { - name : 'errorCallback', - type : types_.FUNCTION, - optional : true, - nullable : true - } + { + name: 'successCallback', + type: types_.FUNCTION + }, + { + name: 'errorCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + } ]); - _sensorListeners[this.sensorType].getData(args.successCallback, errorWrapper.bind(args)); + _sensorListeners[this.sensorType].getData( + args.successCallback, + errorWrapper.bind(args) + ); }; //// LinearAccelerationSensor @@@ -610,109 -629,37 +638,120 @@@ LinearAccelerationSensor.prototype.cons LinearAccelerationSensor.prototype.getLinearAccelerationSensorData = function() { var args = validator_.validateArgs(arguments, [ - { - name : 'successCallback', - type : types_.FUNCTION - }, - { - name : 'errorCallback', - type : types_.FUNCTION, - optional : true, - nullable : true - } + { + name: 'successCallback', + type: types_.FUNCTION + }, + { + name: 'errorCallback', + type: types_.FUNCTION, + optional: true, + nullable: true + } ]); - _sensorListeners[this.sensorType].getData(args.successCallback, errorWrapper.bind(args)); + _sensorListeners[this.sensorType].getData( + args.successCallback, + errorWrapper.bind(args) + ); }; -////////////////////// Sensor Data classes////////////////////// +//// MagneticUncalibratedSensor +var MagneticUncalibratedSensor = function(data) { + Sensor.call(this, SensorType.MAGNETIC_UNCALIBRATED); +}; + +MagneticUncalibratedSensor.prototype = new Sensor(); + +MagneticUncalibratedSensor.prototype.constructor = Sensor; + +MagneticUncalibratedSensor.prototype.getMagneticUncalibratedSensorData = function() { + var args = validator_.validateArgs(arguments, [ + { - name : 'successCallback', - type : types_.FUNCTION ++ name: 'successCallback', ++ type: types_.FUNCTION + }, + { - name : 'errorCallback', - type : types_.FUNCTION, - optional : true, - nullable : true ++ name: 'errorCallback', ++ type: types_.FUNCTION, ++ optional: true, ++ nullable: true + } + ]); + - _sensorListeners[this.sensorType].getData(args.successCallback, errorWrapper.bind(args)); ++ _sensorListeners[this.sensorType].getData( ++ args.successCallback, ++ errorWrapper.bind(args) ++ ); +}; + +//// GyroscopeUncalibratedSensor +var GyroscopeUncalibratedSensor = function(data) { + Sensor.call(this, SensorType.GYROSCOPE_UNCALIBRATED); +}; + +GyroscopeUncalibratedSensor.prototype = new Sensor(); + +GyroscopeUncalibratedSensor.prototype.constructor = Sensor; + +GyroscopeUncalibratedSensor.prototype.getGyroscopeUncalibratedSensorData = function() { + var args = validator_.validateArgs(arguments, [ + { - name : 'successCallback', - type : types_.FUNCTION ++ name: 'successCallback', ++ type: types_.FUNCTION + }, + { - name : 'errorCallback', - type : types_.FUNCTION, - optional : true, - nullable : true ++ name: 'errorCallback', ++ type: types_.FUNCTION, ++ optional: true, ++ nullable: true + } + ]); + - _sensorListeners[this.sensorType].getData(args.successCallback, errorWrapper.bind(args)); ++ _sensorListeners[this.sensorType].getData( ++ args.successCallback, ++ errorWrapper.bind(args) ++ ); +}; + +//// AccelerationSensor +var AccelerationSensor = function(data) { + Sensor.call(this, SensorType.ACCELERATION); +}; + +AccelerationSensor.prototype = new Sensor(); + +AccelerationSensor.prototype.constructor = Sensor; + +AccelerationSensor.prototype.getAccelerationSensorData = function() { + var args = validator_.validateArgs(arguments, [ - { - name : 'successCallback', - type : types_.FUNCTION - }, - { - name : 'errorCallback', - type : types_.FUNCTION, - optional : true, - nullable : true - } ++ { ++ name: 'successCallback', ++ type: types_.FUNCTION ++ }, ++ { ++ name: 'errorCallback', ++ type: types_.FUNCTION, ++ optional: true, ++ nullable: true ++ } + ]); + - _sensorListeners[this.sensorType].getData(args.successCallback, errorWrapper.bind(args)); ++ _sensorListeners[this.sensorType].getData( ++ args.successCallback, ++ errorWrapper.bind(args) ++ ); +}; + - ////////////////////// Sensor Data classes///////////////////////////////////////////////////// ++////////////////////// Sensor Data classes///////////////////////////// ////Base SensorData class - var SensorData = function () { - }; + var SensorData = function() {}; //// SensorLightData var SensorLightData = function(data) { SensorData.call(this); Object.defineProperties(this, { - lightLevel : {value: data.lightLevel, writable: false, enumerable: true} - lightLevel: { - value: data.lightLevel, - writable: false, - enumerable: true - } ++ lightLevel: { value: data.lightLevel, writable: false, enumerable: true } }); }; @@@ -760,7 -713,11 +805,7 @@@ _sensorListeners[SensorType.PRESSURE] var SensorProximityData = function(data) { SensorData.call(this); Object.defineProperties(this, { - proximityState : {value: data.proximityState, writable: false, enumerable: true} - proximityState: { - value: data.proximityState, - writable: false, - enumerable: true - } ++ proximityState: { value: data.proximityState, writable: false, enumerable: true } }); }; @@@ -791,8 -755,12 +843,8 @@@ _sensorListeners[SensorType.ULTRAVIOLET var SensorHRMRawData = function(data) { SensorData.call(this); Object.defineProperties(this, { - lightType : {value: data.lightType, writable: false, enumerable: true}, - lightIntensity : {value: data.lightIntensity, writable: false, enumerable: true} + lightType: { value: data.lightType, writable: false, enumerable: true }, - lightIntensity: { - value: data.lightIntensity, - writable: false, - enumerable: true - } ++ lightIntensity: { value: data.lightIntensity, writable: false, enumerable: true } }); }; @@@ -870,78 -845,34 +929,85 @@@ SensorLinearAccelerationData.prototype SensorLinearAccelerationData.prototype.constructor = SensorData; - _sensorListeners[SensorType.LINEAR_ACCELERATION] = new SensorListener(SensorType.LINEAR_ACCELERATION, - SensorLinearAccelerationData); + _sensorListeners[SensorType.LINEAR_ACCELERATION] = new SensorListener( + SensorType.LINEAR_ACCELERATION, + SensorLinearAccelerationData + ); -//////////////////////SensorHardwareInfo classes////////////////////// +//// SensorMagneticUncalibratedData +var SensorMagneticUncalibratedData = function(data) { + SensorData.call(this); + Object.defineProperties(this, { - x : {value: data.x, writable: false, enumerable: true}, - y : {value: data.y, writable: false, enumerable: true}, - z : {value: data.z, writable: false, enumerable: true}, - xAxisBias : {value: data.xAxisBias, writable: false, enumerable: true}, - yAxisBias : {value: data.yAxisBias, writable: false, enumerable: true}, - zAxisBias : {value: data.zAxisBias, writable: false, enumerable: true} ++ x: { value: data.x, writable: false, enumerable: true }, ++ y: { value: data.y, writable: false, enumerable: true }, ++ z: { value: data.z, writable: false, enumerable: true }, ++ xAxisBias: { value: data.xAxisBias, writable: false, enumerable: true }, ++ yAxisBias: { value: data.yAxisBias, writable: false, enumerable: true }, ++ zAxisBias: { value: data.zAxisBias, writable: false, enumerable: true } + }); +}; + +SensorMagneticUncalibratedData.prototype = new SensorData(); + +SensorMagneticUncalibratedData.prototype.constructor = SensorData; + - _sensorListeners[SensorType.MAGNETIC_UNCALIBRATED] = new SensorListener(SensorType.MAGNETIC_UNCALIBRATED, - SensorMagneticUncalibratedData); ++_sensorListeners[SensorType.MAGNETIC_UNCALIBRATED] = new SensorListener( ++ SensorType.MAGNETIC_UNCALIBRATED, ++ SensorMagneticUncalibratedData ++); + +//// SensorGyroscopeUncalibratedData +var SensorGyroscopeUncalibratedData = function(data) { + SensorData.call(this); + Object.defineProperties(this, { - x : {value: data.x, writable: false, enumerable: true}, - y : {value: data.y, writable: false, enumerable: true}, - z : {value: data.z, writable: false, enumerable: true}, - xAxisDrift : {value: data.xAxisDrift, writable: false, enumerable: true}, - yAxisDrift : {value: data.yAxisDrift, writable: false, enumerable: true}, - zAxisDrift : {value: data.zAxisDrift, writable: false, enumerable: true} ++ x: { value: data.x, writable: false, enumerable: true }, ++ y: { value: data.y, writable: false, enumerable: true }, ++ z: { value: data.z, writable: false, enumerable: true }, ++ xAxisDrift: { value: data.xAxisDrift, writable: false, enumerable: true }, ++ yAxisDrift: { value: data.yAxisDrift, writable: false, enumerable: true }, ++ zAxisDrift: { value: data.zAxisDrift, writable: false, enumerable: true } + }); - +}; + +SensorGyroscopeUncalibratedData.prototype = new SensorData(); + +SensorGyroscopeUncalibratedData.prototype.constructor = SensorData; + - _sensorListeners[SensorType.GYROSCOPE_UNCALIBRATED] = new SensorListener(SensorType.GYROSCOPE_UNCALIBRATED, - SensorGyroscopeUncalibratedData); ++_sensorListeners[SensorType.GYROSCOPE_UNCALIBRATED] = new SensorListener( ++ SensorType.GYROSCOPE_UNCALIBRATED, ++ SensorGyroscopeUncalibratedData ++); + +//// SensorAccelerationData +var SensorAccelerationData = function(data) { + SensorData.call(this); + Object.defineProperties(this, { - x : {value: data.x, writable: false, enumerable: true}, - y : {value: data.y, writable: false, enumerable: true}, - z : {value: data.z, writable: false, enumerable: true}, ++ x: { value: data.x, writable: false, enumerable: true }, ++ y: { value: data.y, writable: false, enumerable: true }, ++ z: { value: data.z, writable: false, enumerable: true } + }); +}; + +SensorAccelerationData.prototype = new SensorData(); + +SensorAccelerationData.prototype.constructor = SensorData; + - _sensorListeners[SensorType.ACCELERATION] = new SensorListener(SensorType.ACCELERATION, - SensorAccelerationData); ++_sensorListeners[SensorType.ACCELERATION] = new SensorListener( ++ SensorType.ACCELERATION, ++ SensorAccelerationData ++); + - //////////////////////SensorHardwareInfo classes////////////////////////////////////////////////////////// ++//////////////////////SensorHardwareInfo classes///////////////////////////// function SensorHardwareInfo(data) { Object.defineProperties(this, { - name : {value: data.name, writable: false, enumerable: true}, - type : {value: data.type, writable: false, enumerable: true}, - vendor : {value: data.vendor, writable: false, enumerable: true}, - minValue : {value: data.minValue, writable: false, enumerable: true}, - maxValue : {value: data.maxValue, writable: false, enumerable: true}, - resolution : {value: data.resolution, writable: false, enumerable: true}, - minInterval : {value: data.minInterval, writable: false, enumerable: true}, - maxBatchCount : {value: data.batchCount, writable: false, enumerable: true} + name: { value: data.name, writable: false, enumerable: true }, + type: { value: data.type, writable: false, enumerable: true }, + vendor: { value: data.vendor, writable: false, enumerable: true }, + minValue: { value: data.minValue, writable: false, enumerable: true }, + maxValue: { value: data.maxValue, writable: false, enumerable: true }, - resolution: { - value: data.resolution, - writable: false, - enumerable: true - }, - minInterval: { - value: data.minInterval, - writable: false, - enumerable: true - }, - maxBatchCount: { - value: data.batchCount, - writable: false, - enumerable: true - } ++ resolution: { value: data.resolution, writable: false, enumerable: true }, ++ minInterval: { value: data.minInterval, writable: false, enumerable: true }, ++ maxBatchCount: { value: data.batchCount, writable: false, enumerable: true } }); } // Exports diff --cc src/systeminfo/systeminfo_api.js index b0628978,19ef6fe5..601f6618 --- a/src/systeminfo/systeminfo_api.js +++ b/src/systeminfo/systeminfo_api.js @@@ -415,25 -415,15 +415,25 @@@ function SystemInfoDeviceCapability(dat //class SystemInfoBattery //////////////////////////////////////////////////// function SystemInfoBattery(data) { Object.defineProperties(this, { - level : { - value : data.level, - writable : false, - enumerable : true - }, - isCharging : { - value : data.isCharging, - writable : false, - enumerable : true - }, - timeToDischarge : { - value : data.timeToDischarge, - writable : false, - enumerable : true - }, - timeToFullCharge : { - value : data.timeToFullCharge, - writable : false, - enumerable : true + level: { + value: data.level, + writable: false, + enumerable: true + }, + isCharging: { + value: data.isCharging, + writable: false, + enumerable: true ++ }, ++ timeToDischarge: { ++ value: data.timeToDischarge, ++ writable: false, ++ enumerable: true ++ }, ++ timeToFullCharge: { ++ value: data.timeToFullCharge, ++ writable: false, ++ enumerable: true } }); } @@@ -464,21 -454,25 +464,24 @@@ function SystemInfoStorageUnit(data) writable: false, enumerable: true }, - availableCapacity : { - value : Converter_.toUnsignedLongLong(data.availableCapacity), - writable : false, - enumerable : true + availableCapacity: { + value: Converter_.toUnsignedLongLong(data.availableCapacity), + writable: false, + enumerable: true }, - isRemovable : { - value : data.isRemovable, - writable : false, - enumerable : true + isRemovable: { + value: data.isRemovable, + writable: false, + enumerable: true }, - isRemoveable : { - enumerable : true, + isRemoveable: { + enumerable: true, get: function() { - privUtils_.warn('DEPRECATION WARNING: SystemInfoStorageUnit.isRemoveable is is deprecated and will be ' - + 'removed from next release. Use SystemInfoStorageUnit.isRemovable instead.'); + privUtils_.warn( - 'DEPRECATION WARNING: ' + - 'SystemInfoStorageUnit.isRemoveable is is deprecated and ' + - 'will be removed from next release. Use ' + - 'SystemInfoStorageUnit.isRemovable instead.' ++ 'DEPRECATION WARNING: SystemInfoStorageUnit.isRemoveable is ' + ++ 'deprecated and will be removed from next release. ' + ++ 'Use SystemInfoStorageUnit.isRemovable instead.' + ); return _isRemovable; }, set: function() {} @@@ -760,11 -776,13 +785,13 @@@ SystemInfoCameraFlash.prototype.setBrig }; //class SystemInfo //////////////////////////////////////////////////// - var SystemInfo = function() { - }; + var SystemInfo = function() {}; SystemInfo.prototype.getCapabilities = function() { - privUtils_.warn('DEPRECATION WARNING: getCapabilities() is deprecated and will be removed from next release. Use getCapability() instead.'); + privUtils_.warn( - 'DEPRECATION WARNING: getCapabilities() is deprecated ' + - 'and will be removed from next release. Use getCapability() instead.' ++ 'DEPRECATION WARNING: getCapabilities() is deprecated and will be removed ' + ++ 'from next release. Use getCapability() instead.' + ); var result = native_.callSync('SystemInfo_getCapabilities', {}); if (native_.isFailure(result)) { @@@ -920,10 -965,16 +974,16 @@@ function _systeminfoBatteryListenerCall /* * According to documentation, the condition should look like this: * - * (T_.isUndefined(listener.lowThreshold) && T_.isUndefined(listener.highThreshold)) || - * (!T_.isUndefined(listener.lowThreshold) && !T_.isUndefined(listener.highThreshold) && (propObj.level <= listener.lowThreshold || propObj.level >= listener.highThreshold)) || - * (!T_.isUndefined(listener.lowThreshold) && (propObj.level <= listener.lowThreshold)) || - * (!T_.isUndefined(listener.highThreshold) && (propObj.level >= listener.highThreshold)) + * (T_.isUndefined(listener.lowThreshold) && + * T_.isUndefined(listener.highThreshold)) || + * (!T_.isUndefined(listener.lowThreshold) && - * !T_.isUndefined(listener.highThreshold) && - * (propObj.level <= listener.lowThreshold || - * propObj.level >= listener.highThreshold)) || ++ * !T_.isUndefined(listener.highThreshold) && ++ * (propObj.level <= listener.lowThreshold || ++ * propObj.level >= listener.highThreshold)) || + * (!T_.isUndefined(listener.lowThreshold) && - * (propObj.level <= listener.lowThreshold)) || ++ * (propObj.level <= listener.lowThreshold)) || + * (!T_.isUndefined(listener.highThreshold) && - * (propObj.level >= listener.highThreshold)) ++ * (propObj.level >= listener.highThreshold)) * * but it can be optimized like this: */ diff --cc src/utils/utils_api.js index c54ccd4f,bed11fcd..bad69c9f --- a/src/utils/utils_api.js +++ b/src/utils/utils_api.js @@@ -147,43 -152,41 +152,43 @@@ function Utils() Utils.prototype.error = console.error.bind(console); Utils.prototype.warn = console.warn.bind(console); - Utils.prototype.log = _enableJsLogs ? console.log.bind(console) : function(){}; + Utils.prototype.log = _enableJsLogs ? console.log.bind(console) : function() {}; +Utils.prototype.global = _global; + Utils.prototype.repackFilter = function(filter) { - if (filter instanceof tizen.AttributeFilter) { - return { - filterType: 'AttributeFilter', - attributeName: filter.attributeName, - matchFlag: filter.matchFlag, - matchValue: _dateConverter.fromTZDate(filter.matchValue) - }; - } - if (filter instanceof tizen.AttributeRangeFilter) { - return { - filterType: 'AttributeRangeFilter', - attributeName: filter.attributeName, - initialValue: _dateConverter.fromTZDate(filter.initialValue), - endValue: _dateConverter.fromTZDate(filter.endValue) - }; - } - if (filter instanceof tizen.CompositeFilter) { - var _f = []; - var filters = filter.filters; - - for (var i = 0; i < filters.length; ++i) { - _f.push(this.repackFilter(filters[i])); + if (filter instanceof tizen.AttributeFilter) { + return { + filterType: 'AttributeFilter', + attributeName: filter.attributeName, + matchFlag: filter.matchFlag, + matchValue: _dateConverter.fromTZDate(filter.matchValue) + }; } + if (filter instanceof tizen.AttributeRangeFilter) { + return { + filterType: 'AttributeRangeFilter', + attributeName: filter.attributeName, + initialValue: _dateConverter.fromTZDate(filter.initialValue), + endValue: _dateConverter.fromTZDate(filter.endValue) + }; + } + if (filter instanceof tizen.CompositeFilter) { + var _f = []; + var filters = filter.filters; - return { - filterType: 'CompositeFilter', - type: filter.type, - filters: _f - }; - } + for (var i = 0; i < filters.length; ++i) { + _f.push(this.repackFilter(filters[i])); + } - return null; + return { + filterType: 'CompositeFilter', + type: filter.type, + filters: _f + }; + } + + return null; }; /** @@@ -233,67 -244,63 +246,69 @@@ Utils.prototype.getPkgApiVersion = func }; Utils.prototype.checkPrivilegeAccess = function(privilege) { - var result = native_.callSync('Utils_checkPrivilegeAccess', { - privilege : _toString(privilege), - }); - - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } - }; - - Utils.prototype.isAppVersionEarlierThan= function(ver) { - var app_ver = this.getPkgApiVersion(); - - var arr_ver = ver.split("."); // reference version - var arr_app_ver = app_ver.split("."); // application version - var num_ver; - var num_app; - - var i; - var length = Math.min(arr_ver.length, arr_app_ver.length); - for (i = 0; i < length; i++) { - num_ver = parseInt(arr_ver[i]); - num_app = parseInt(arr_app_ver[i]); - if (num_app < num_ver) { - return true; - } else if (num_app > num_ver) { - return false; + var result = native_.callSync('Utils_checkPrivilegeAccess', { + privilege: _toString(privilege) + }); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); } - } + }; - if (arr_ver.length > arr_app_ver.length) { - return true; - } - return false; - } + Utils.prototype.isAppVersionEarlierThan = function(ver) { + var app_ver = this.getPkgApiVersion(); + + var arr_ver = ver.split('.'); // reference version + var arr_app_ver = app_ver.split('.'); // application version + var num_ver; + var num_app; + + var i; + var length = Math.min(arr_ver.length, arr_app_ver.length); + for (i = 0; i < length; i++) { + num_ver = parseInt(arr_ver[i]); + num_app = parseInt(arr_app_ver[i]); + if (num_app < num_ver) { + return true; + } else if (num_app > num_ver) { + return false; + } + } - Utils.prototype.checkPrivilegeAccess4Ver = function(new_ver, new_priv, old_priv) { - if (!this.isAppVersionEarlierThan(new_ver)) { - this.checkPrivilegeAccess(new_priv); - } else if (old_priv != undefined) { - this.checkPrivilegeAccess(old_priv); - } - } + if (arr_ver.length > arr_app_ver.length) { + return true; + } + return false; + }; - Utils.prototype.checkBackwardCompabilityPrivilegeAccess = function(current_privilege, previous_privilege) { - var result = native_.callSync('Utils_checkBackwardCompabilityPrivilegeAccess', { - current_privilege : _toString(current_privilege), - previous_privilege : _toString(previous_privilege), - }); + Utils.prototype.checkPrivilegeAccess4Ver = function(new_ver, new_priv, old_priv) { + if (!this.isAppVersionEarlierThan(new_ver)) { + this.checkPrivilegeAccess(new_priv); + } else if (old_priv != undefined) { + this.checkPrivilegeAccess(old_priv); + } + }; - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } + Utils.prototype.checkBackwardCompabilityPrivilegeAccess = function( + current_privilege, + previous_privilege + ) { + var result = native_.callSync('Utils_checkBackwardCompabilityPrivilegeAccess', { + current_privilege: _toString(current_privilege), + previous_privilege: _toString(previous_privilege) + }); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } }; +Utils.prototype.checkProfile = function() { - var result = native_.callSync('Utils_checkProfile', {}); ++ var result = native_.callSync('Utils_checkProfile', {}); + - return native_.getResultObject(result); ++ return native_.getResultObject(result); +}; + - ///////////////////////////////////////////////////////////////////////////// /** @constructor */ var Type = function() {}; @@@ -618,7 -638,8 +646,8 @@@ var Validator = function() * - values - required in case of some objects, value depends on type * - validator - function which accepts a single parameter and returns true or false; * if this property is present, this function will be executed, - * argument converted to expected type is going to be passed to this function - * argument converted to expected type is going to be passed - * to this function ++ * argument converted to expected type is going to be passed to ++ * this function * * @param {Array} a - arguments of a method * @param {Array} d - description of expected arguments @@@ -695,7 -716,8 +724,8 @@@ * { * name: 'first', * type: Validator.Types.ARRAY, - * values: Validator.Types.DOUBLE // converts elements, only primitive types are supported + * values: Validator.Types.DOUBLE // converts elements, - * // only primitive types are supported ++ * only primitive types are supported * } * ] * @code @@@ -1168,14 -1241,279 +1249,15 @@@ NativeManager.prototype.getErrorObject }; NativeManager.prototype.callIfPossible = function(callback) { - if (!_type.isNullOrUndefined(callback)) { - callback.apply(callback, [].slice.call(arguments, 1)); - } + if (!_type.isNullOrUndefined(callback)) { + callback.apply(callback, [].slice.call(arguments, 1)); + } }; -/* - *bridge is a two way communication interface - *Example usage: - *var bridge = new NativeBridge(extension); - * To send sync method: - * var result = bridge.sync({ - * cmd: 'my_cpp_function_symbol', - * args: { - * name: 'My name', - * age: 28 - * } - * }); - * xwalk.utils.log(result); - * - * To send async method and handle response: - * bridge.async({ - * cmd: 'my_cpp_function_symbol', - * args: { - * name: 'My name' - * } - * }).then({ - * success: function (data) { - * var age = data.age; - * args.successCallback(age); - * }, - * error: function (e) {...}, - * someCallback: function (data) {...} - * }); - *bridge.async will add special param to passed data called cid - *that param need to be kept and returned with respons - *To determine which callback should be invoked, response should - *contain "action" param. Value of "action" param indicates name of - *triggered callback. - *Callbask are removed from listenr by defoult to prevent that behaviour - *param "keep" should be assigned to value true - *Example of c++ async response: - * Simple succes with data: - * { - * cid: 23, - * action: 'success', - * args: { - * age: 23 - * } - * } - * More complicated example: - * { - * cid: 23, - * action: 'progress', - * keep: true, - * args: { - * age: 23 - * } - * } - */ -var NativeBridge = function(extension, debug) { - debug = !!debug; - var Callbacks = (function() { - var _collection = {}; - var _cid = 0; - var _next = function() { - return (_cid += 1); - }; - - var CallbackManager = function() {}; - - CallbackManager.prototype = { - add: function(/*callbacks, cid?*/) { - if (debug) xwalk.utils.log('bridge.CallbackManager.add'); - var args = Array.prototype.slice.call(arguments); - var c = args.shift(); - var cid = args.pop(); - if (cid) { - if (c !== null && typeof c === 'object') { - for (var key in c) { - if (c.hasOwnProperty(key)) _collection[cid][key] = c[key]; - } - } - } else { - cid = _next(); - _collection[cid] = c; - } - return cid; - }, - remove: function(cid) { - if (debug) { - xwalk.utils.log('bridge.CallbackManager.remove, cid: ' + cid); - } - if (_collection[cid]) delete _collection[cid]; - }, - call: function(cid, key, args, keep) { - if (debug) { - xwalk.utils.log( - 'bridge.CallbackManager.call, cid: ' + cid + ', key: ' + key - ); - } - var callbacks = _collection[cid]; - keep = !!keep; - if (callbacks) { - var fn = callbacks[key]; - if (fn) { - fn.apply(null, args); - if (!keep) this.remove(cid); - } - } - } - }; - - return { - getInstance: function() { - return this.instance || (this.instance = new CallbackManager()); - } - }; - })(); - - var Listeners = (function() { - var _listeners = {}; - var _id = 0; - var _next = function() { - return (_id += 1); - }; - - var ListenerManager = function() {}; - - ListenerManager.prototype = { - add: function(l) { - if (debug) xwalk.utils.log('bridge.ListenerManager.add'); - var id = _next(); - _listeners[id] = l; - return id; - }, - resolve: function(id, action, data, keep) { - if (debug) - xwalk.utils.log( - 'bridge.ListenerManager.resolve, id: ' + - id + - ', action: ' + - action - ); - keep = !!keep; - var l = _listeners[id]; - if (l) { - var cm = Callbacks.getInstance(); - cm.call(l.cid, action, [data], keep); - } - return l; - }, - remove: function(id) { - if (debug) xwalk.utils.log('bridge.ListenerManager.remove, id: ' + id); - var l = _listeners[id]; - if (l) { - var cm = Callbacks.getInstance(); - if (l.cid) cm.remove(l.cid); - delete _listeners[id]; - } - }, - attach: function(id, key, value) { - if (_listeners[id]) { - _listeners[id][key] = value; - return true; - } - return false; - }, - find: function(key, value) { - var result = []; - for (var p in _listeners) { - if (_listeners.hasOwnProperty(p)) { - var l = _listeners[p]; - if (l[key] === value) result.push({ id: p, listener: l }); - } - } - return result; - } - }; - - return { - getInstance: function() { - return this.instance || (this.instance = new ListenerManager()); - } - }; - })(); - - var Listener = function() { - if (debug) xwalk.utils.log('bridge: Listener constructor'); - this.cid = null; - }; - Listener.prototype = { - then: function(c) { - if (debug) xwalk.utils.log('bridge.Listener.then'); - var cm = Callbacks.getInstance(); - this.cid = cm.add(c, this.cid); - return this; - } - }; - - var Bridge = function() {}; - Bridge.prototype = { - sync: function(data) { - var json = JSON_.stringify({ - cmd: data.cmd, - args: data - }); - if (debug) xwalk.utilss.log('bridge.sync, json: ' + json); - var result = extension.internal.sendSyncMessage(json); - var obj = JSON_.parse(result); - if (obj.error) throw new WebAPIException(obj.code, obj.name, obj.message); - return obj.result; - }, - async: function(data) { - var l = new Listener(); - data.cid = Listeners.getInstance().add(l); - var json = JSON_.stringify({ - cmd: data.cmd, - args: data - }); - if (debug) xwalk.utils.log('bridge.async, json: ' + json); - setTimeout(function() { - extension.postMessage(json); - }); - return l; - }, - listener: function(c) { - var l = new Listener().then(c); - var cid = Listeners.getInstance().add(l); - return cid; - }, - attach: function(id, key, value) { - return Listeners.getInstance().attach(id, key, value); - }, - find: function(key, value) { - return Listeners.getInstance().find(key, value); - }, - remove: function(id) { - Listeners.getInstance().remove(id); - } - }; - - extension.setMessageListener(function(json) { - /* - *Expected response: - *{ - * cid: 23, // callback id - * action: 'success', // expected callback action - * keep: false // optional param - * args: {...} // data pased to callback - *} - */ - - if (debug) xwalk.utils.log('bridge.setMessageListener, json: ' + json); - var data = JSON_.parse(json); - if (data.cid && data.action) { - setTimeout(function() { - Listeners.getInstance().resolve( - data.cid, - data.action, - data.args, - data.keep - ); - }, 0); - } - }); - - return new Bridge(); -}; - // WebAPIException and WebAPIError definition moved to Utils for compliance // reasons with blink-wrt environment. - // In blink-wrt the original Tizen module is loaded, which is not providing exception constructor. + // In blink-wrt the original Tizen module is loaded, + // which is not providing exception constructor. // As modules needs exceptions internally so they are loaded here for now. // See http://168.219.209.56/gerrit/#/c/23472/ for more details. // In future exception definition could be moved back to Tizen module. @@@ -1279,7 -1616,8 +1360,8 @@@ Object.keys(errors).forEach(function(ke * Generic exception interface. * * @param {number} code 16-bit error code. - * @param {string} message An error message that describes the details of an encountered error. - * @param {string} message An error message that describes the details - * of an encountered error. ++ * @param {string} message An error message that describes the details of ++ * an encountered error. * @param {string} name An error type. */ var WebAPIException = function(code, message, name) { @@@ -1384,4 -1722,4 +1465,3 @@@ Object.freeze(exports) Object.freeze(exports.utils); Object.freeze(Utils.prototype); Object.freeze(NativeManager.prototype); - -Object.freeze(NativeBridge.prototype); diff --cc src/voicecontrol/voicecontrol_api.js index 6a588bfc,00000000..a0ab77a1 mode 100755,000000..100755 --- a/src/voicecontrol/voicecontrol_api.js +++ b/src/voicecontrol/voicecontrol_api.js @@@ -1,243 -1,0 +1,275 @@@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + - +var utils_ = xwalk.utils; +var type_ = utils_.type; +var converter_ = utils_.converter; +var validator_ = utils_.validator; +var types_ = validator_.Types; +var native_ = new xwalk.utils.NativeManager(extension); + +function ListenerManager(native, listenerName, handle) { - this.listeners = {}; - this.nextId = 1; - this.nativeSet = false; - this.native = native; - this.listenerName = listenerName; - this.handle = handle || function (msg, listener, watchId) {}; ++ this.listeners = {}; ++ this.nextId = 1; ++ this.nativeSet = false; ++ this.native = native; ++ this.listenerName = listenerName; ++ this.handle = handle || function(msg, listener, watchId) {}; +} + - ListenerManager.prototype.addListener = function (callback, nativeCall, data) { - var id = this.nextId; - if (!this.nativeSet) { - this.native.addListener(this.listenerName, function (msg) { - for (var watchId in this.listeners) { - if (this.listeners.hasOwnProperty(watchId)) { - this.handle(msg, this.listeners[watchId], watchId); ++ListenerManager.prototype.addListener = function(callback, nativeCall, data) { ++ var id = this.nextId; ++ if (!this.nativeSet) { ++ this.native.addListener( ++ this.listenerName, ++ function(msg) { ++ for (var watchId in this.listeners) { ++ if (this.listeners.hasOwnProperty(watchId)) { ++ this.handle(msg, this.listeners[watchId], watchId); ++ } ++ } ++ }.bind(this) ++ ); ++ var result = this.native.callSync(nativeCall, data || {}); ++ if (this.native.isFailure(result)) { ++ throw this.native.getErrorObject(result); + } - } - }.bind(this)); - var result = this.native.callSync(nativeCall, data || {}); - if (this.native.isFailure(result)) { - throw this.native.getErrorObject(result); ++ this.nativeSet = true; + } - this.nativeSet = true; - } + - this.listeners[id] = callback; - ++this.nextId; ++ this.listeners[id] = callback; ++ ++this.nextId; + - return id; ++ return id; +}; + - ListenerManager.prototype.removeListener = function (watchId, nativeCall) { - if (this.listeners.hasOwnProperty(watchId)) { - delete this.listeners[watchId]; - } ++ListenerManager.prototype.removeListener = function(watchId, nativeCall) { ++ if (this.listeners.hasOwnProperty(watchId)) { ++ delete this.listeners[watchId]; ++ } + - if (this.nativeSet && type_.isEmptyObject(this.listeners)) { - this.native.callSync(nativeCall); - this.native.removeListener(this.listenerName); - this.nativeSet = false; - } ++ if (this.nativeSet && type_.isEmptyObject(this.listeners)) { ++ this.native.callSync(nativeCall); ++ this.native.removeListener(this.listenerName); ++ this.nativeSet = false; ++ } +}; + - ListenerManager.prototype.removeAllListeners = function () { - this.native.removeListener(this.listenerName); - this.listeners = {}; - this.nativeSet = false; ++ListenerManager.prototype.removeAllListeners = function() { ++ this.native.removeListener(this.listenerName); ++ this.listeners = {}; ++ this.nativeSet = false; +}; + - var VcResultListener = new ListenerManager(native_, 'onresult', function(result, listener) { - listener(result.event, result.list, result.results); ++var VcResultListener = new ListenerManager(native_, 'onresult', function( ++ result, ++ listener ++) { ++ listener(result.event, result.list, result.results); +}); + - var VcLangListener = new ListenerManager(native_, 'onlanguagechanged', function(result, listener) { - listener(result.previous, result.current); ++var VcLangListener = new ListenerManager(native_, 'onlanguagechanged', function( ++ result, ++ listener ++) { ++ listener(result.previous, result.current); +}); + +var VoiceControlResultEvent = { - SUCCESS: 'SUCCESS', - FAILURE: 'FAILURE' ++ SUCCESS: 'SUCCESS', ++ FAILURE: 'FAILURE' +}; + +var VoiceControlCommandType = { - FOREGROUND: 'FOREGROUND' ++ FOREGROUND: 'FOREGROUND' +}; + - function VoiceControlClientManager() { - } ++function VoiceControlClientManager() {} + - VoiceControlClientManager.prototype.getVoiceControlClient = function () { - var result = native_.callSync('VoiceControlClientManager_getVoiceControlClient', {}); ++VoiceControlClientManager.prototype.getVoiceControlClient = function() { ++ var result = native_.callSync('VoiceControlClientManager_getVoiceControlClient', {}); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } + - return new VoiceControlClient(); ++ return new VoiceControlClient(); +}; + - function VoiceControlClient() { - } ++function VoiceControlClient() {} + - VoiceControlClient.prototype.getCurrentLanguage = function () { - var result = native_.callSync('VoiceControlClient_getCurrentLanguage', {}); ++VoiceControlClient.prototype.getCurrentLanguage = function() { ++ var result = native_.callSync('VoiceControlClient_getCurrentLanguage', {}); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } + - return native_.getResultObject(result); ++ return native_.getResultObject(result); +}; + - VoiceControlClient.prototype.setCommandList = function (list, type) { - var args = validator_.validateArgs(arguments, [ - {name: 'list', type: types_.ARRAY, values: VoiceControlCommand}, - {name: 'type', type: types_.ENUM, values: type_.getValues(VoiceControlCommandType), optional: true, nullable: true} - ]); ++VoiceControlClient.prototype.setCommandList = function(list, type) { ++ var args = validator_.validateArgs(arguments, [ ++ { name: 'list', type: types_.ARRAY, values: VoiceControlCommand }, ++ { ++ name: 'type', ++ type: types_.ENUM, ++ values: type_.getValues(VoiceControlCommandType), ++ optional: true, ++ nullable: true ++ } ++ ]); + - if (type_.isNullOrUndefined(args.type)) { - args.type = VoiceControlCommandType.FOREGROUND; - } ++ if (type_.isNullOrUndefined(args.type)) { ++ args.type = VoiceControlCommandType.FOREGROUND; ++ } + - var data = { - list: args.list, - type: args.type - }; ++ var data = { ++ list: args.list, ++ type: args.type ++ }; + - var result = native_.callSync('VoiceControlClient_setCommandList', data); ++ var result = native_.callSync('VoiceControlClient_setCommandList', data); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } +}; + - VoiceControlClient.prototype.unsetCommandList = function (type) { - var args = validator_.validateArgs(arguments, [ - {name: 'type', type: types_.ENUM, values: type_.getValues(VoiceControlCommandType), optional: true, nullable: true} - ]); ++VoiceControlClient.prototype.unsetCommandList = function(type) { ++ var args = validator_.validateArgs(arguments, [ ++ { ++ name: 'type', ++ type: types_.ENUM, ++ values: type_.getValues(VoiceControlCommandType), ++ optional: true, ++ nullable: true ++ } ++ ]); + - if (type_.isNullOrUndefined(args.type)) { - args.type = VoiceControlCommandType.FOREGROUND; - } ++ if (type_.isNullOrUndefined(args.type)) { ++ args.type = VoiceControlCommandType.FOREGROUND; ++ } + - var result = native_.callSync('VoiceControlClient_unsetCommandList', {type: args.type}); ++ var result = native_.callSync('VoiceControlClient_unsetCommandList', { ++ type: args.type ++ }); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } +}; + - VoiceControlClient.prototype.addResultListener = function (listener) { - var args = validator_.validateArgs(arguments, [ - {name: 'listener', type: types_.FUNCTION} - ]); ++VoiceControlClient.prototype.addResultListener = function(listener) { ++ var args = validator_.validateArgs(arguments, [ ++ { name: 'listener', type: types_.FUNCTION } ++ ]); + - return VcResultListener.addListener(args.listener, 'VoiceControlClient_addResultListener'); ++ return VcResultListener.addListener( ++ args.listener, ++ 'VoiceControlClient_addResultListener' ++ ); +}; + - VoiceControlClient.prototype.removeResultListener = function (id) { - if (!type_.isNumber(id)) { - throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, 'Cannot convert id to int.'); - } ++VoiceControlClient.prototype.removeResultListener = function(id) { ++ if (!type_.isNumber(id)) { ++ throw new WebAPIException( ++ WebAPIException.TYPE_MISMATCH_ERR, ++ 'Cannot convert id to int.' ++ ); ++ } + - var args = validator_.validateArgs(arguments, [ - {name: 'id', type: types_.LONG} - ]); ++ var args = validator_.validateArgs(arguments, [{ name: 'id', type: types_.LONG }]); + - VcResultListener.removeListener(args.id, 'VoiceControlClient_removeResultListener'); ++ VcResultListener.removeListener(args.id, 'VoiceControlClient_removeResultListener'); +}; + - VoiceControlClient.prototype.addLanguageChangeListener = function (listener) { - var args = validator_.validateArgs(arguments, [ - {name: 'listener', type: types_.FUNCTION} - ]); ++VoiceControlClient.prototype.addLanguageChangeListener = function(listener) { ++ var args = validator_.validateArgs(arguments, [ ++ { name: 'listener', type: types_.FUNCTION } ++ ]); + - return VcLangListener.addListener(args.listener, 'VoiceControlClient_addLanguageChangeListener'); ++ return VcLangListener.addListener( ++ args.listener, ++ 'VoiceControlClient_addLanguageChangeListener' ++ ); +}; + - VoiceControlClient.prototype.removeLanguageChangeListener = function (id) { - if (!type_.isNumber(id)) { - throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, 'Cannot convert id to int.'); - } ++VoiceControlClient.prototype.removeLanguageChangeListener = function(id) { ++ if (!type_.isNumber(id)) { ++ throw new WebAPIException( ++ WebAPIException.TYPE_MISMATCH_ERR, ++ 'Cannot convert id to int.' ++ ); ++ } + - var args = validator_.validateArgs(arguments, [ - {name: 'id', type: types_.LONG} - ]); ++ var args = validator_.validateArgs(arguments, [{ name: 'id', type: types_.LONG }]); + - VcLangListener.removeListener(args.id, 'VoiceControlClient_removeLanguageChangeListener'); ++ VcLangListener.removeListener( ++ args.id, ++ 'VoiceControlClient_removeLanguageChangeListener' ++ ); +}; + - VoiceControlClient.prototype.release = function () { - var result = native_.callSync('VoiceControlClient_release', {}); ++VoiceControlClient.prototype.release = function() { ++ var result = native_.callSync('VoiceControlClient_release', {}); + - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } - VcLangListener.removeAllListeners(); - VcResultListener.removeAllListeners(); ++ if (native_.isFailure(result)) { ++ throw native_.getErrorObject(result); ++ } ++ VcLangListener.removeAllListeners(); ++ VcResultListener.removeAllListeners(); +}; + +// Constructor of VoiceControlCommand +function VoiceControlCommand(command, type) { - validator_.isConstructorCall(this, VoiceControlCommand); ++ validator_.isConstructorCall(this, VoiceControlCommand); + - var _command = command; - var _type = type; ++ var _command = command; ++ var _type = type; + - if (type_.isNullOrUndefined(_type)) { - _type = VoiceControlCommandType.FOREGROUND; - } ++ if (type_.isNullOrUndefined(_type)) { ++ _type = VoiceControlCommandType.FOREGROUND; ++ } + - Object.defineProperties(this, - { - command: { - enumerable: true, - get: function () { - return _command; - }, - set: function (value) { - _command = value; - } - }, - type: { - enumerable: true, - get: function () { - return _type; ++ Object.defineProperties(this, { ++ command: { ++ enumerable: true, ++ get: function() { ++ return _command; ++ }, ++ set: function(value) { ++ _command = value; ++ } + }, - set: function (value) { - if (type_.arrayContains(type_.getValues(VoiceControlCommandType), value)) { - _type = value; - } ++ type: { ++ enumerable: true, ++ get: function() { ++ return _type; ++ }, ++ set: function(value) { ++ if ( ++ type_.arrayContains(type_.getValues(VoiceControlCommandType), value) ++ ) { ++ _type = value; ++ } ++ } + } - } + }); +} + +exports = new VoiceControlClientManager(); +tizen.VoiceControlCommand = VoiceControlCommand;