[Verification] TCT passrate 100%.
Signed-off-by: Arkadiusz Pietraszek <a.pietraszek@partner.samsung.com>
Change-Id: Id004158e62f5d0b6f2c09eeee5cf300d461a9d9f
var native = new xwalk.utils.NativeManager(extension);
- var AlarmManager = function () {
+var isAlarmAbsolutePeriodDeprecated = true;
+
+ 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 }
});
};
}
}
+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) {
}
};
- {
- 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;
+AlarmManager.prototype.addAlarmNotification = function() {
+ var args = AV.validateMethod(arguments, [
- callArgs.newImpl = (callArgs.notification instanceof tizen.UserNotification);
++ {
++ 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
- }
- else {
++ callArgs.newImpl = callArgs.notification instanceof tizen.UserNotification;
+
+ var result = native.callSync('AlarmManager_addAlarmNotification', callArgs);
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
- AlarmManager.prototype.remove = function () {
++ } else {
+ _edit.allow();
+ UpdateInternalData_(args.alarm, native.getResultObject(result));
+ _edit.disallow();
+ }
+};
+
+ AlarmManager.prototype.remove = function() {
var args = AV.validateMethod(arguments, [
{
- name : 'id',
- type : AV.Types.STRING,
+ name: 'id',
+ type: AV.Types.STRING
}
]);
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));
}
- 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);
- }
+ _warningLogs.allow();
+ return alarm;
+ }
+};
+
+function _prepareAppControl(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.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) {
- noti.textContents.detailInfo = _d;
- }
++ 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;
+ }
- AlarmManager.prototype.getAlarmNotification = function () {
+}
+
- name : 'id',
- type : AV.Types.STRING,
++AlarmManager.prototype.getAlarmNotification = function() {
+ var args = AV.validateMethod(arguments, [
+ {
- var result = native.callSync('AlarmManager_getAlarmNotification', {id: Number(args.id)});
++ name: 'id',
++ type: AV.Types.STRING
+ }
+ ]);
+
++ 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);
}
};
} else {
var data = native.getResultObject(result);
var md = [];
- data.forEach(function (i) {
- if ('AlarmRelative'=== i.type) {
+ _warningLogs.disallow();
+ 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)));
}
});
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.'
++ );
+ }
}
}
}
},
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);
}
}
};
- if (m_profile == null) {
- m_profile = privUtils_.checkProfile();
- }
- Object.defineProperties(this, {
- profile: {
- get: function() {
- return m_profile;
- },
- set: function() {},
- enumerable: true
- }
- })
- };
+// 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
++ }
++ });
++ }
+
+ 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();
var native = new xwalk.utils.NativeManager(extension);
var ApplicationControlLaunchMode = {
- SINGLE: 'SINGLE',
- GROUP: 'GROUP'
+ SINGLE: 'SINGLE',
+ GROUP: 'GROUP'
};
- RECENTLY: 'RECENTLY',
- FREQUENTLY: 'FREQUENTLY'
+var ApplicationUsageMode = {
++ RECENTLY: 'RECENTLY',
++ FREQUENTLY: 'FREQUENTLY'
+};
+
// TODO: Please uncomment below lines when system events is ready
//var SystemEvent = {
// BATTERY_CHARGER_STATUS: 'BATTERY_CHARGER_STATUS',
};
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;
+ }
};
- 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) {
+ApplicationManager.prototype.getBatteryUsageInfo = function() {
- 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);
- }
++ 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)) {
- 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.');
++ 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
+ }
- if (!T.isNullOrUndefined(filter.endTime)) {
- if (filter.endTime instanceof Date) {
- callArgs.filter.endTime = filter.endTime.getTime() / 1000;
++ ]);
+
- throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR,
- 'endTime given with invalid type.');
++ 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.'
++ );
++ }
++ }
++
++ 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;
- }
+
- var callback = function(result) {
++ if (!T.isNullOrUndefined(args.limit)) {
++ callArgs.limit = args.limit;
++ }
+
- 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);
- }
++ 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)) {
++ 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) {
};
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);
};
- this.listeners = {};
- this.listenersCount = 0;
- this.nextId = 1;
- this.nativeSet = false;
- this.native = native;
- this.listenerName = listenerName;
- };
+function StatusListenerManager(native, listenerName) {
- 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);
- }
++ 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);
++ }
++ }
+ }
- if (!this.nativeSet) {
- var result = this.native.callSync('ApplicationManager_addAppStatusChangeListener');
- if (this.native.isFailure(result)) {
- throw this.native.getErrorObject(result);
- }
+};
+
+StatusListenerManager.prototype.addListener = function(callback, appId) {
- this.native.addListener(this.listenerName, this.onListenerCalled.bind(this));
- this.nativeSet = true;
- }
++ if (!this.nativeSet) {
++ var result = this.native.callSync(
++ 'ApplicationManager_addAppStatusChangeListener'
++ );
++ if (this.native.isFailure(result)) {
++ throw this.native.getErrorObject(result);
++ }
+
- var listener = {
- 'callback' : callback,
- 'appId' : appId
- };
++ this.native.addListener(this.listenerName, this.onListenerCalled.bind(this));
++ this.nativeSet = true;
++ }
+
- var id = this.nextId++;
- this.listeners[id] = listener;
- this.listenersCount++;
++ var listener = {
++ callback: callback,
++ appId: appId
++ };
+
- return id;
++ var id = this.nextId++;
++ this.listeners[id] = listener;
++ this.listenersCount++;
+
- if (this.listeners.hasOwnProperty(watchId)) {
- if (this.listenersCount > 1) {
- delete this.listeners[watchId];
- this.listenersCount--;
- return;
- }
++ return id;
+};
+
+StatusListenerManager.prototype.removeListener = function(watchId) {
- if (this.nativeSet) {
- var result = this.native.callSync('ApplicationManager_removeStatusChangeListener');
- if (this.native.isFailure(result)) {
- throw this.native.getErrorObject(result);
- }
++ if (this.listeners.hasOwnProperty(watchId)) {
++ if (this.listenersCount > 1) {
++ delete this.listeners[watchId];
++ this.listenersCount--;
++ return;
++ }
+
- delete this.listeners[watchId];
- this.listenersCount--;
++ if (this.nativeSet) {
++ var result = this.native.callSync(
++ 'ApplicationManager_removeStatusChangeListener'
++ );
++ if (this.native.isFailure(result)) {
++ throw this.native.getErrorObject(result);
++ }
+
- this.native.removeListener(this.listenerName);
- this.nativeSet = false;
++ delete this.listeners[watchId];
++ this.listenersCount--;
+
- }
++ this.native.removeListener(this.listenerName);
++ this.nativeSet = false;
++ }
+ }
- var appStatusChangeListener = new StatusListenerManager(native, APP_STATUS_CHANGE_LISTENER);
+};
+
+var APP_STATUS_CHANGE_LISTENER = 'AppStatusChangeListener';
- 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 appStatusChangeListener = new StatusListenerManager(
++ native,
++ APP_STATUS_CHANGE_LISTENER
++);
+
+ApplicationManager.prototype.addAppStatusChangeListener = function() {
- var args = AV.validateMethod(arguments, [
- {
- name : 'watchId',
- type : AV.Types.LONG
- }
- ]);
-
- appStatusChangeListener.removeListener(args.watchId);
++ 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);
+};
+
// class Application ////////////////////////////////////////////////////
function Application(data) {
// 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
+ }
+ });
}
- Object.defineProperties(this, {
- appId : {
- value : data.appId,
- writable : false,
- enumerable : true
- },
- batteryUsage : {
- value : data.batteryUsage,
- writable : false,
- enumerable : true
- }
- });
+//class ApplicationBatteryUsage ////////////////////////////////////////////////////
+function ApplicationBatteryUsage(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
++ },
++ 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
++ }
++ });
+}
+
// exports ////////////////////////////////////////////////////
exports = new ApplicationManager();
* 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
}
- 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.addChangeListener = function() {
- var args = validator_.validateArgs(arguments, [
- {'name': 'watchId', 'type': types_.LONG}
- ]);
++ 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 type = DataType.SQL;
- if (this instanceof MappedDataControlConsumer) {
- type = DataType.MAP;
- }
++ var args = validator_.validateArgs(arguments, [
++ { name: 'watchId', type: types_.LONG }
++ ]);
+
- listenersManager.removeChangeListener(type, this.providerId, this.dataId, args.watchId);
++ var type = DataType.SQL;
++ if (this instanceof MappedDataControlConsumer) {
++ type = DataType.MAP;
++ }
+
++ 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();
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) {
}
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() {
};
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();
}
/* 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() {
};
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() {
};
var SleepStatus = {
- ASLEEP: 'ASLEEP',
- AWAKE: 'AWAKE'
+ ASLEEP: 'ASLEEP',
+ AWAKE: 'AWAKE'
};
- 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',
+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'
+};
+
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) {
};
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) {
}
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() {
};
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);
+ }
};
- 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);
+HumanActivityMonitorManager.prototype.isGestureSupported = function() {
- 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;
- }
- };
++ 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) {
- var d = undefined;
- var result = undefined;
- var alwaysOn = msg.alwaysOn;
- switch (msg.action) {
++ 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) {
- d = new GestureData(this.native.getResultObject(msg));
- break;
++ var d = undefined;
++ var result = undefined;
++ var alwaysOn = msg.alwaysOn;
++ switch (msg.action) {
+ case 'ondetect':
- d = this.native.getErrorObject(msg);
- break;
++ d = new GestureData(this.native.getResultObject(msg));
++ break;
+ case 'onerror':
- utils_.log('Unknown mode: ' + msg.action);
- return;
- }
++ d = this.native.getErrorObject(msg);
++ break;
+ default:
- 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);
- }
++ 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);
++ }
++ }
+ }
- 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);
++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);
++ }
+ }
- 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;
- }
++ typeCountMap[type]++;
++ var id = this.nextId++;
++ this.listeners[id] = listener;
+
- return id;
++ if (!this.nativeSet) {
++ this.native.addListener(this.listenerName, this.onListenerCalled.bind(this));
++ this.nativeSet = true;
++ }
+
- 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);
++ 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);
++ }
+ }
- delete this.listeners[watchId];
- typeCountMap[listener.type]--;
- }
+
- if (this.nativeSet && type_.isEmptyObject(this.listeners)) {
- this.native.removeListener(this.listenerName);
- this.nativeSet = false;
- }
++ delete this.listeners[watchId];
++ typeCountMap[listener.type]--;
++ }
+
- var gestureRecognitionListener = new GestureListenerManager(native_, GESTURE_RECOGNITION_LISTENER);
++ if (this.nativeSet && type_.isEmptyObject(this.listeners)) {
++ this.native.removeListener(this.listenerName);
++ this.nativeSet = false;
++ }
+};
+
+var GESTURE_RECOGNITION_LISTENER = 'GestureRecognitionListener';
- 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 gestureRecognitionListener = new GestureListenerManager(
++ native_,
++ GESTURE_RECOGNITION_LISTENER
++);
+
+HumanActivityMonitorManager.prototype.addGestureRecognitionListener = function() {
- var args = validator_.validateMethod(arguments, [{
- name : 'watchId',
- type : types_.LONG,
- }]);
++ 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() {
- gestureRecognitionListener.removeListener(args.watchId);
++ var args = validator_.validateMethod(arguments, [
++ {
++ name: 'watchId',
++ type: types_.LONG
++ }
++ ]);
+
++ 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();
}
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);
}
- 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);
+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);
++ }
+ }
+}
+
HumanActivityRecorderPressureData.prototype = new HumanActivityRecorderData();
- HumanActivityRecorderPressureData.prototype.constructor = HumanActivityRecorderPressureData;
+ // prettier-ignore
+ HumanActivityRecorderPressureData.prototype.constructor =
+ HumanActivityRecorderPressureData;
exports = new HumanActivityMonitorManager();
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) {
};
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) {
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 /////////////////
//////////////////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() {
};
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);
+ }
};
- 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);
- }
+function WebkitVisibilityChangeListener() {
- var result = native_.call('NFCAdapter_setPreferredApp');
++ 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() {
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- } else {
- if (false === isWebkitVisibilityChangeListenerSet) {
- privUtils_.global.document.addEventListener("webkitvisibilitychange", WebkitVisibilityChangeListener);
- isWebkitVisibilityChangeListenerSet = true;
++ 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;
++ }
+ }
- var result = native_.call('NFCAdapter_unsetPreferredApp');
+};
+
+NFCAdapter.prototype.unsetPreferredApp = function() {
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- } else {
- if (true === isWebkitVisibilityChangeListenerSet) {
- privUtils_.global.document.removeEventListener("webkitvisibilitychange", WebkitVisibilityChangeListener);
- isWebkitVisibilityChangeListenerSet = false;
++ 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;
++ }
+ }
+};
+
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 /////////////////
};
var StatusNotificationType = {
- SIMPLE: 'SIMPLE',
- THUMBNAIL: 'THUMBNAIL',
- ONGOING: 'ONGOING',
- PROGRESS: 'PROGRESS'
+ 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'
+};
+
var NotificationProgressType = {
- PERCENTAGE: 'PERCENTAGE',
- BYTE: 'BYTE'
+ PERCENTAGE: 'PERCENTAGE',
+ BYTE: 'BYTE'
};
var LEDCustomFlags = {
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) {
};
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;
};
- var args = validator_.validateArgs(arguments, [
- {name: 'id', type: types_.STRING}
- ]);
+NotificationManager.prototype.getNotification = function(id) {
- if (!arguments.length) {
- throw new WebAPIException(WebAPIException.NOT_FOUND_ERR);
- }
++ var args = validator_.validateArgs(arguments, [{ name: 'id', type: types_.STRING }]);
+
- var data = {
- //add marker for UserNotification implementation
- newImpl: true,
- id: args.id
- };
++ if (!arguments.length) {
++ throw new WebAPIException(WebAPIException.NOT_FOUND_ERR);
++ }
+
- var result = native_.callSync('NotificationManager_get', data);
++ var data = {
++ //add marker for UserNotification implementation
++ newImpl: true,
++ id: args.id
++ };
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
++ var result = native_.callSync('NotificationManager_get', data);
+
- var n = native_.getResultObject(result);
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
+
- _edit.allow();
- var returnObject = new UserNotification(n.userType, n.title, n);
- _edit.disallow();
++ var n = native_.getResultObject(result);
+
- return returnObject;
++ _edit.allow();
++ var returnObject = new UserNotification(n.userType, n.title, n);
++ _edit.disallow();
+
++ 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;
};
- var result = native_.callSync('NotificationManager_getAll', {
- //add marker for UserNotification implementation
- newImpl: true
+NotificationManager.prototype.getAllNotifications = function() {
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
++ var result = native_.callSync('NotificationManager_getAll', {
++ //add marker for UserNotification implementation
++ newImpl: true
+ });
+
- var n = native_.getResultObject(result);
- var notifications = [];
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
+
- _edit.allow();
- for (var i = 0; i < n.length; i++) {
- notifications.push(new UserNotification(n[i].userType, n[i].title, n[i]));
- }
- _edit.disallow();
++ var n = native_.getResultObject(result);
++ var notifications = [];
+
- return 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();
+
++ return notifications;
+};
+
/**
* Plays the custom effect of the service LED that is located to the front of a device.
*
* 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);
+ }
};
- var args = validator_.validateArgs(arguments, [
- {name: 'name', type: types_.STRING},
- {name: 'notification', type: types_.PLATFORM_OBJECT, values: Notification}
- ]);
+NotificationManager.prototype.saveNotificationAsTemplate = function(name, notification) {
- //add marker for UserNotification implementation
- args.newImpl = (args.notification instanceof tizen.UserNotification);
++ var args = validator_.validateArgs(arguments, [
++ { name: 'name', type: types_.STRING },
++ { name: 'notification', type: types_.PLATFORM_OBJECT, values: Notification }
++ ]);
+
- var result = native_.callSync('NotificationManager_saveNotificationAsTemplate', args);
++ //add marker for UserNotification implementation
++ args.newImpl = args.notification instanceof tizen.UserNotification;
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
++ var result = native_.callSync('NotificationManager_saveNotificationAsTemplate', args);
+
- var args = validator_.validateArgs(arguments, [
- {name: 'name', type: types_.STRING}
- ]);
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
+};
+
+NotificationManager.prototype.createNotificationFromTemplate = function(name) {
- if (!arguments.length) {
- throw new WebAPIException(WebAPIException.NOT_FOUND_ERR);
- }
++ var args = validator_.validateArgs(arguments, [
++ { name: 'name', type: types_.STRING }
++ ]);
+
- var result = native_.callSync('NotificationManager_createNotificationFromTemplate', args);
++ if (!arguments.length) {
++ throw new WebAPIException(WebAPIException.NOT_FOUND_ERR);
++ }
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- var n = native_.getResultObject(result);
++ var result = native_.callSync(
++ 'NotificationManager_createNotificationFromTemplate',
++ args
++ );
+
- _edit.allow();
- var returnObject = new UserNotification(n.userType, n.title, n);
- _edit.disallow();
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
++ var n = native_.getResultObject(result);
+
- return returnObject;
++ _edit.allow();
++ var returnObject = new UserNotification(n.userType, n.title, n);
++ _edit.disallow();
+
- if ((_progressType === NotificationProgressType.PERCENTAGE && (v >= 0 && v <= 100))
- || (_progressType === NotificationProgressType.BYTE &&
- converter_.toUnsignedLong(v) >= 0)) {
- return true;
- }
- return false;
++ return returnObject;
+};
+
+var _checkProgressValue = function(v, _progressType) {
- 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 (
++ (_progressType === NotificationProgressType.PERCENTAGE && (v >= 0 && v <= 100)) ||
++ (_progressType === NotificationProgressType.BYTE &&
++ converter_.toUnsignedLong(v) >= 0)
++ ) {
++ return true;
++ }
++ return false;
+};
+
+var _checkDetailInfo = function(v) {
- }
- return true;
++ 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;
++ }
+ }
- var _d = [];
- for (var i = 0; i < v.length; ++i) {
- _d.push(new tizen.NotificationDetailInfo(v[i].mainText, v[i].subText || null));
- }
- return _d;
++ return true;
+};
+
+var _setDetailInfo = 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;
++ 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) {
- }
- return true;
++ if (type_.isNull(v)) {
++ return true;
++ }
++ if (!type_.isArray(v)) {
++ return false;
+ }
- return v.length === 7 && v.substr(0, 1) === '#' && (/^([0-9A-Fa-f]{2})+$/).test(v.substr(1, 7));
++ 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))
++ );
+};
+
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) {
}
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
+ }
+ });
}
- 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;
+function TextContentsInitDict(data) {
- 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 (!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
+ }
++ });
+
- },
- 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];
- }
++ if (data instanceof _global.Object) {
++ this['progressType'] = data['progressType'];
++ for (var prop in data) {
++ if (this.hasOwnProperty(prop)) {
++ this[prop] = data[prop];
++ }
+ }
- }
+ }
- 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
- }
- });
+}
+
+function ImagesInitDict(data) {
- if (data instanceof _global.Object) {
- for (var prop in data) {
- if (this.hasOwnProperty(prop)) {
- this[prop] = data[prop];
- }
++ 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 (!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
- }
- });
+}
+
+function ThumbnailsInitDict(data) {
- if (data instanceof _global.Object) {
- for (var prop in data) {
- if (this.hasOwnProperty(prop)) {
- this[prop] = data[prop];
- }
++ 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 (!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
- }
- });
+}
+
+function ActionsInitDict(data) {
- if (data instanceof _global.Object) {
- for (var prop in data) {
- if (this.hasOwnProperty(prop)) {
- this[prop] = data[prop];
- }
++ 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 (!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
- }
- });
+}
+
+function GroupContentsInitDict(data) {
- if (data instanceof _global.Object) {
- for (var prop in data) {
- if (this.hasOwnProperty(prop)) {
- this[prop] = data[prop];
- }
++ 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 (!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
- }
- });
+}
+
+function LedsInitDict(data) {
- if (data instanceof _global.Object) {
- for (var prop in data) {
- if (this.hasOwnProperty(prop)) {
- this[prop] = data[prop];
- }
++ 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];
++ }
++ }
+ }
- 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
- }
- });
+}
+
+function UserNotification(userType, title, notificationGroupedInitDict) {
- 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
- }
- });
++ 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) {
- if (data instanceof _global.Object) {
- for (var prop in data) {
- if (this.hasOwnProperty(prop)) {
- this[prop] = data[prop];
- }
++ 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];
++ }
++ }
+ }
+}
+
exports = new NotificationManager();
tizen.StatusNotification = StatusNotification;
+tizen.UserNotification = UserNotification;
tizen.NotificationDetailInfo = NotificationDetailInfo;
--- /dev/null
-
+/*
+ * 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.
+ */
+
- function PPMManager() {
- }
+var validator_ = xwalk.utils.validator;
+var type_ = xwalk.utils.type;
+var types_ = validator_.Types;
+var native_ = new xwalk.utils.NativeManager(extension);
+
- var args = validator_.validateArgs(arguments, [
- { name: 'privilege', type: types_.STRING }
- ]);
++function PPMManager() {}
+
+PPMManager.prototype.checkPermission = function() {
- var callArgs = {
- privilege: args.privilege
- };
++ var args = validator_.validateArgs(arguments, [
++ { name: 'privilege', type: types_.STRING }
++ ]);
+
- var result = native_.callSync('PPMManager_checkPermission', callArgs);
++ var callArgs = {
++ privilege: args.privilege
++ };
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
++ var result = native_.callSync('PPMManager_checkPermission', callArgs);
+
- return native_.getResultObject(result);
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
+
- throw native_.getErrorObject(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)) {
- exports = new PPMManager();
++ throw native_.getErrorObject(result);
+ }
+};
+
+// Exports
++exports = new PPMManager();
// 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 = {
}
};
- 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);
}
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);
}
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() {
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 }
});
};
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
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 }
});
};
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 }
});
};
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 }
});
};
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
//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
}
});
}
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() {}
};
//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)) {
/*
* 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:
*/
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;
};
/**
};
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);
+ }
};
- var result = native_.callSync('Utils_checkProfile', {});
+Utils.prototype.checkProfile = function() {
- return native_.getResultObject(result);
++ var result = native_.callSync('Utils_checkProfile', {});
+
-
++ return native_.getResultObject(result);
+};
+
/////////////////////////////////////////////////////////////////////////////
/** @constructor */
var Type = 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
* {
* 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
};
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.
* 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) {
Object.freeze(exports.utils);
Object.freeze(Utils.prototype);
Object.freeze(NativeManager.prototype);
-
-Object.freeze(NativeBridge.prototype);
--- /dev/null
-
+/*
+ * 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.
+ */
+
- this.listeners = {};
- this.nextId = 1;
- this.nativeSet = false;
- this.native = native;
- this.listenerName = listenerName;
- this.handle = handle || function (msg, listener, watchId) {};
+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) {
- 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);
++ this.listeners = {};
++ this.nextId = 1;
++ this.nativeSet = false;
++ this.native = native;
++ this.listenerName = listenerName;
++ this.handle = handle || function(msg, listener, watchId) {};
+}
+
- }
- }.bind(this));
- var result = this.native.callSync(nativeCall, data || {});
- if (this.native.isFailure(result)) {
- throw this.native.getErrorObject(result);
++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);
+ }
- this.nativeSet = true;
- }
++ this.nativeSet = true;
+ }
- this.listeners[id] = callback;
- ++this.nextId;
+
- return id;
++ this.listeners[id] = callback;
++ ++this.nextId;
+
- ListenerManager.prototype.removeListener = function (watchId, nativeCall) {
- if (this.listeners.hasOwnProperty(watchId)) {
- delete this.listeners[watchId];
- }
++ return id;
+};
+
- if (this.nativeSet && type_.isEmptyObject(this.listeners)) {
- this.native.callSync(nativeCall);
- this.native.removeListener(this.listenerName);
- this.nativeSet = false;
- }
++ListenerManager.prototype.removeListener = function(watchId, nativeCall) {
++ if (this.listeners.hasOwnProperty(watchId)) {
++ delete this.listeners[watchId];
++ }
+
- ListenerManager.prototype.removeAllListeners = function () {
- this.native.removeListener(this.listenerName);
- this.listeners = {};
- this.nativeSet = false;
++ if (this.nativeSet && type_.isEmptyObject(this.listeners)) {
++ this.native.callSync(nativeCall);
++ this.native.removeListener(this.listenerName);
++ this.nativeSet = false;
++ }
+};
+
- var VcResultListener = new ListenerManager(native_, 'onresult', function(result, listener) {
- listener(result.event, result.list, result.results);
++ListenerManager.prototype.removeAllListeners = function() {
++ this.native.removeListener(this.listenerName);
++ this.listeners = {};
++ this.nativeSet = false;
+};
+
- var VcLangListener = new ListenerManager(native_, 'onlanguagechanged', function(result, listener) {
- listener(result.previous, result.current);
++var VcResultListener = new ListenerManager(native_, 'onresult', function(
++ result,
++ listener
++) {
++ listener(result.event, result.list, result.results);
+});
+
- SUCCESS: 'SUCCESS',
- FAILURE: 'FAILURE'
++var VcLangListener = new ListenerManager(native_, 'onlanguagechanged', function(
++ result,
++ listener
++) {
++ listener(result.previous, result.current);
+});
+
+var VoiceControlResultEvent = {
- FOREGROUND: 'FOREGROUND'
++ SUCCESS: 'SUCCESS',
++ FAILURE: 'FAILURE'
+};
+
+var VoiceControlCommandType = {
- function VoiceControlClientManager() {
- }
++ FOREGROUND: 'FOREGROUND'
+};
+
- VoiceControlClientManager.prototype.getVoiceControlClient = function () {
- var result = native_.callSync('VoiceControlClientManager_getVoiceControlClient', {});
++function VoiceControlClientManager() {}
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
++VoiceControlClientManager.prototype.getVoiceControlClient = function() {
++ var result = native_.callSync('VoiceControlClientManager_getVoiceControlClient', {});
+
- return new VoiceControlClient();
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
+
- function VoiceControlClient() {
- }
++ return new VoiceControlClient();
+};
+
- VoiceControlClient.prototype.getCurrentLanguage = function () {
- var result = native_.callSync('VoiceControlClient_getCurrentLanguage', {});
++function VoiceControlClient() {}
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
++VoiceControlClient.prototype.getCurrentLanguage = function() {
++ var result = native_.callSync('VoiceControlClient_getCurrentLanguage', {});
+
- return native_.getResultObject(result);
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(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}
- ]);
++ return native_.getResultObject(result);
+};
+
- if (type_.isNullOrUndefined(args.type)) {
- args.type = VoiceControlCommandType.FOREGROUND;
- }
++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
++ }
++ ]);
+
- var data = {
- list: args.list,
- type: args.type
- };
++ if (type_.isNullOrUndefined(args.type)) {
++ args.type = VoiceControlCommandType.FOREGROUND;
++ }
+
- var result = native_.callSync('VoiceControlClient_setCommandList', data);
++ var data = {
++ list: args.list,
++ type: args.type
++ };
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
++ var result = native_.callSync('VoiceControlClient_setCommandList', data);
+
- VoiceControlClient.prototype.unsetCommandList = function (type) {
- var args = validator_.validateArgs(arguments, [
- {name: 'type', type: types_.ENUM, values: type_.getValues(VoiceControlCommandType), optional: true, nullable: true}
- ]);
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
+};
+
- if (type_.isNullOrUndefined(args.type)) {
- args.type = VoiceControlCommandType.FOREGROUND;
- }
++VoiceControlClient.prototype.unsetCommandList = function(type) {
++ var args = validator_.validateArgs(arguments, [
++ {
++ name: 'type',
++ type: types_.ENUM,
++ values: type_.getValues(VoiceControlCommandType),
++ optional: true,
++ nullable: true
++ }
++ ]);
+
- var result = native_.callSync('VoiceControlClient_unsetCommandList', {type: args.type});
++ if (type_.isNullOrUndefined(args.type)) {
++ args.type = VoiceControlCommandType.FOREGROUND;
++ }
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
++ var result = native_.callSync('VoiceControlClient_unsetCommandList', {
++ type: args.type
++ });
+
- VoiceControlClient.prototype.addResultListener = function (listener) {
- var args = validator_.validateArgs(arguments, [
- {name: 'listener', type: types_.FUNCTION}
- ]);
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
+};
+
- return VcResultListener.addListener(args.listener, 'VoiceControlClient_addResultListener');
++VoiceControlClient.prototype.addResultListener = function(listener) {
++ var args = validator_.validateArgs(arguments, [
++ { name: 'listener', type: types_.FUNCTION }
++ ]);
+
- VoiceControlClient.prototype.removeResultListener = function (id) {
- if (!type_.isNumber(id)) {
- throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, 'Cannot convert id to int.');
- }
++ return VcResultListener.addListener(
++ args.listener,
++ 'VoiceControlClient_addResultListener'
++ );
+};
+
- var args = validator_.validateArgs(arguments, [
- {name: 'id', type: types_.LONG}
- ]);
++VoiceControlClient.prototype.removeResultListener = function(id) {
++ if (!type_.isNumber(id)) {
++ throw new WebAPIException(
++ WebAPIException.TYPE_MISMATCH_ERR,
++ 'Cannot convert id to int.'
++ );
++ }
+
- VcResultListener.removeListener(args.id, 'VoiceControlClient_removeResultListener');
++ var args = validator_.validateArgs(arguments, [{ name: 'id', type: types_.LONG }]);
+
- VoiceControlClient.prototype.addLanguageChangeListener = function (listener) {
- var args = validator_.validateArgs(arguments, [
- {name: 'listener', type: types_.FUNCTION}
- ]);
++ VcResultListener.removeListener(args.id, 'VoiceControlClient_removeResultListener');
+};
+
- return VcLangListener.addListener(args.listener, 'VoiceControlClient_addLanguageChangeListener');
++VoiceControlClient.prototype.addLanguageChangeListener = function(listener) {
++ var args = validator_.validateArgs(arguments, [
++ { name: 'listener', type: types_.FUNCTION }
++ ]);
+
- VoiceControlClient.prototype.removeLanguageChangeListener = function (id) {
- if (!type_.isNumber(id)) {
- throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, 'Cannot convert id to int.');
- }
++ return VcLangListener.addListener(
++ args.listener,
++ 'VoiceControlClient_addLanguageChangeListener'
++ );
+};
+
- var args = validator_.validateArgs(arguments, [
- {name: 'id', type: types_.LONG}
- ]);
++VoiceControlClient.prototype.removeLanguageChangeListener = function(id) {
++ if (!type_.isNumber(id)) {
++ throw new WebAPIException(
++ WebAPIException.TYPE_MISMATCH_ERR,
++ 'Cannot convert id to int.'
++ );
++ }
+
- VcLangListener.removeListener(args.id, 'VoiceControlClient_removeLanguageChangeListener');
++ var args = validator_.validateArgs(arguments, [{ name: 'id', type: types_.LONG }]);
+
- VoiceControlClient.prototype.release = function () {
- var result = native_.callSync('VoiceControlClient_release', {});
++ VcLangListener.removeListener(
++ args.id,
++ 'VoiceControlClient_removeLanguageChangeListener'
++ );
+};
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- VcLangListener.removeAllListeners();
- VcResultListener.removeAllListeners();
++VoiceControlClient.prototype.release = function() {
++ var result = native_.callSync('VoiceControlClient_release', {});
+
- validator_.isConstructorCall(this, VoiceControlCommand);
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
++ VcLangListener.removeAllListeners();
++ VcResultListener.removeAllListeners();
+};
+
+// Constructor of VoiceControlCommand
+function VoiceControlCommand(command, type) {
- var _command = command;
- var _type = type;
++ validator_.isConstructorCall(this, VoiceControlCommand);
+
- if (type_.isNullOrUndefined(_type)) {
- _type = VoiceControlCommandType.FOREGROUND;
- }
++ var _command = command;
++ var _type = type;
+
- Object.defineProperties(this,
- {
- command: {
- enumerable: true,
- get: function () {
- return _command;
- },
- set: function (value) {
- _command = value;
- }
- },
- type: {
- enumerable: true,
- get: function () {
- return _type;
++ if (type_.isNullOrUndefined(_type)) {
++ _type = VoiceControlCommandType.FOREGROUND;
++ }
+
- set: function (value) {
- if (type_.arrayContains(type_.getValues(VoiceControlCommandType), value)) {
- _type = value;
- }
++ Object.defineProperties(this, {
++ command: {
++ enumerable: true,
++ get: function() {
++ return _command;
++ },
++ set: function(value) {
++ _command = 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;