}
function _prepareDetailInfo(noti) {
- if (!noti || !noti.textContents || !noti.textContents.detailInfo) {
- privUtils_.log("Do nothing - detailInfo is NOT present");
- return;
- }
- var detailInfo = noti.textContents.detailInfo;
- if (T.isArray(detailInfo)) {
- var _d = [];
- for (var i = 0; i < detailInfo.length; ++i) {
- _d.push(new tizen.NotificationDetailInfo(detailInfo[i].mainText,
- detailInfo[i].subText || null));
+ if (!noti || !noti.textContents || !noti.textContents.detailInfo) {
- console.log('Do nothing - detailInfo is NOT present');
++ privUtils_.log('Do nothing - detailInfo is NOT present');
+ return;
+ }
+ var detailInfo = noti.textContents.detailInfo;
+ if (T.isArray(detailInfo)) {
+ var _d = [];
+ for (var i = 0; i < detailInfo.length; ++i) {
+ _d.push(
+ new tizen.NotificationDetailInfo(
+ detailInfo[i].mainText,
+ detailInfo[i].subText || null
+ )
+ );
+ }
+ noti.textContents.detailInfo = _d;
}
- noti.textContents.detailInfo = _d;
- }
}
- AlarmManager.prototype.getAlarmNotification = function () {
+ AlarmManager.prototype.getAlarmNotification = function() {
var args = AV.validateMethod(arguments, [
{
- name : 'id',
- type : AV.Types.STRING,
+ name: 'id',
+ type: AV.Types.STRING
}
]);
},
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.'
++ '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.'
++ 'long period) is deprecated, thus period attribute should ' +
++ 'not be used.'
+ );
}
if (_edit.canEdit && v) {
var applicationEventListener = new ListenerManager(native, APPLICATION_EVENT_LISTENER);
ApplicationManager.prototype.addAppInfoEventListener = function() {
- privUtils_.warn('DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be removed from next release. '
- + 'Use tizen.package.setPackageInfoEventListener() instead.');
-
- var args = AV.validateMethod(arguments, [
- {
- name : 'eventCallback',
- type : AV.Types.LISTENER,
- values : ['oninstalled', 'onupdated', 'onuninstalled']
- }
- ]);
-
- return applicationEventListener.addListener(args.eventCallback);
+ privUtils_.warn(
- 'DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will ' +
- 'be removed from next release. ' +
++ 'DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be ' +
++ 'removed from next release. ' +
+ 'Use tizen.package.setPackageInfoEventListener() instead.'
+ );
+
+ var args = AV.validateMethod(arguments, [
+ {
+ name: 'eventCallback',
+ type: AV.Types.LISTENER,
+ values: ['oninstalled', 'onupdated', 'onuninstalled']
+ }
+ ]);
+
+ return applicationEventListener.addListener(args.eventCallback);
};
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. ' +
++ 'DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be ' +
++ 'removed from next release. ' +
+ 'Use tizen.package.unsetPackageInfoEventListener() instead.'
+ );
+
+ var args = AV.validateMethod(arguments, [
+ {
+ name: 'watchId',
+ type: AV.Types.LONG
+ }
+ ]);
- applicationEventListener.removeListener(args.watchId);
+ applicationEventListener.removeListener(args.watchId);
};
function StatusListenerManager(native, listenerName) {
native_.addListener(ARCHIVE_ONPROGRESS_CALLBACK, ArchiveFileProgressCallback);
/**
- * The ArchiveFileEntry interface provides access to ArchiveFile member information and file data.
- * The ArchiveFileEntry interface provides access to ArchiveFile member information
- * and file data.
++ * The ArchiveFileEntry interface provides access to ArchiveFile member
++ * information and file data.
* This constructor is for internal use only.
* It should be prohibited to call this constructor by user.
*/
};
}
-
/**
- * The ArchiveManager interface provides methods for global operations related to ArchiveFile.
- * The ArchiveManager interface provides methods for global operations related to
- * ArchiveFile.
++ * The ArchiveManager interface provides methods for global operations
++ * related to ArchiveFile.
*/
/**
};
/**
- * Retrieves information about ArchiveFileEntry with the specified name in ArchiveFile.
- * Retrieves information about ArchiveFileEntry with the specified name in
- * ArchiveFile.
++ * Retrieves information about ArchiveFileEntry with the specified
++ * name in ArchiveFile.
*/
- this.getEntryByName = function () {
+ this.getEntryByName = function() {
var args = validator_.validateArgs(arguments, [
- { name: "name", type: types_.STRING },
- { name: "onsuccess", type: types_.FUNCTION },
- { name: "onerror", type: types_.FUNCTION, optional: true, nullable: true }
- ]),
- opId = getNextOpId();
+ { name: 'name', type: types_.STRING },
+ { name: 'onsuccess', type: types_.FUNCTION },
+ { name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true }
+ ]),
+ opId = getNextOpId();
- checkMode(this.mode, ["r","rw"]);
+ checkMode(this.mode, ['r', 'rw']);
var callArgs = {
- name : args.name,
- opId : opId,
- handle : getHandle()
+ name: args.name,
+ opId: opId,
+ handle: getHandle()
};
var callback = function(result) {
};
}
-
- var ArchiveManager = function () {
- };
+ var ArchiveManager = function() {};
/**
- * Opens the archive file. After this operation, it is possible to add or get files to and from the archive.
- * Opens the archive file. After this operation, it is possible to add or get files
- * to and from the archive.
++ * Opens the archive file. After this operation, it is possible to add or get
++ * files to and from the archive.
*/
- ArchiveManager.prototype.open = function () {
+ ArchiveManager.prototype.open = function() {
var args = validator_.validateArgs(arguments, [
- { name: "file", type: types_.FILE_REFERENCE },
- { name: "mode", type: types_.ENUM, values: ["r", "rw", "w", "a"] },
- { name: "onsuccess", type: types_.FUNCTION },
- { name: "onerror", type: types_.FUNCTION, optional: true, nullable: true },
- { name: "options", type: types_.DICTIONARY, optional: true, nullable: true }
- ]),
- opId = getNextOpId();
-
- var optionsAttributes = ["overwrite"],
+ { name: 'file', type: types_.FILE_REFERENCE },
+ { name: 'mode', type: types_.ENUM, values: ['r', 'rw', 'w', 'a'] },
+ { name: 'onsuccess', type: types_.FUNCTION },
+ { name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true },
+ { name: 'options', type: types_.DICTIONARY, optional: true, nullable: true }
+ ]),
+ opId = getNextOpId();
+
+ var optionsAttributes = ['overwrite'],
options = args.options || {};
- for(var i in optionsAttributes) {
+ for (var i in optionsAttributes) {
if (!options[optionsAttributes[i]]) {
options[optionsAttributes[i]] = null;
}
});
};
- //class tizen.BluetoothLEServiceData ////////////////////////////////////////////////////
-//class tizen.BluetoothLEServiceData //////////////////////////
++//class tizen.BluetoothLEServiceData ///////////////////////////
tizen.BluetoothLEServiceData = function(d) {
- AV.isConstructorCall(this, tizen.BluetoothLEServiceData);
- var uuid_ = '';
- var data_ = '';
-
- Object.defineProperties(this, {
- uuid: {
- enumerable: true,
- get: function() {
- return uuid_;
- },
- set: function(v) {
- uuid_ = Converter.toString(v);
- }
- },
- data: {
- enumerable: true,
- get: function() {
- return data_;
- },
- set: function(v) {
- data_ = Converter.toString(v);
- }
- }
- });
-
- if (arguments.length >= 2) { // public constructor
- this.uuid = arguments[0];
- this.data = arguments[1];
- } else if (d && T.isObject(d)) { // internal constructor
- this.uuid = d.uuid;
- this.data = d.data;
- } else {
- uuid_ = undefined;
- data_ = undefined;
- }
- };
-
- //class BluetoothLEAdvertiseData ////////////////////////////////////////////////////
- tizen.BluetoothLEAdvertiseData = function(dict) {
- AV.isConstructorCall(this, tizen.BluetoothLEAdvertiseData);
- var includeName_ = false;
- var uuids_ = null;
- var solicitationuuids_ = null;
- var appearance_ = null;
- var includeTxPowerLevel_ = false;
- var serviceData_ = null;
- var manufacturerData_ = null;
-
- Object.defineProperties(this, {
- includeName: {
- enumerable: true,
- get: function() {
- return includeName_;
- },
- set: function(v) {
- includeName_ = Converter.toBoolean(v, true);
- }
- },
- uuids: {
- enumerable: true,
- get: function() {
- return uuids_;
- },
- set: function(v) {
- if (T.isNull(v)) {
- uuids_ = v;
- } else if (T.isArray(v)) {
- for (var i = 0; i < v.length; ++i) {
- if (!T.isString(v[i])) {
- v[i] = Converter.toString(v[i]);
+ AV.isConstructorCall(this, tizen.BluetoothLEServiceData);
+ var uuid_ = '';
+ var data_ = '';
+
+ Object.defineProperties(this, {
+ uuid: {
+ enumerable: true,
+ get: function() {
+ return uuid_;
+ },
+ set: function(v) {
+ uuid_ = Converter.toString(v);
+ }
+ },
+ data: {
+ enumerable: true,
+ get: function() {
+ return data_;
+ },
+ set: function(v) {
+ data_ = Converter.toString(v);
}
- }
- uuids_ = v;
}
- }
- },
- solicitationuuids: {
- enumerable: true,
- get: function() {
- return solicitationuuids_;
- },
- set: function(v) {
- if (T.isNull(v)) {
- solicitationuuids_ = v;
- } else if (T.isArray(v)) {
- for (var i = 0; i < v.length; ++i) {
- if (!T.isString(v[i])) {
- v[i] = Converter.toString(v[i]);
+ });
+
+ if (arguments.length >= 2) {
+ // public constructor
+ this.uuid = arguments[0];
+ this.data = arguments[1];
+ } else if (d && T.isObject(d)) {
+ // internal constructor
+ this.uuid = d.uuid;
+ this.data = d.data;
+ } else {
+ uuid_ = undefined;
+ data_ = undefined;
+ }
+ };
+
-//class BluetoothLEAdvertiseData //////////////////////////
++//class BluetoothLEAdvertiseData ///////////////////////////
+ tizen.BluetoothLEAdvertiseData = function(dict) {
+ AV.isConstructorCall(this, tizen.BluetoothLEAdvertiseData);
+ var includeName_ = false;
+ var uuids_ = null;
+ var solicitationuuids_ = null;
+ var appearance_ = null;
+ var includeTxPowerLevel_ = false;
+ var serviceData_ = null;
+ var manufacturerData_ = null;
+
+ Object.defineProperties(this, {
+ includeName: {
+ enumerable: true,
+ get: function() {
+ return includeName_;
+ },
+ set: function(v) {
+ includeName_ = Converter.toBoolean(v, true);
+ }
+ },
+ uuids: {
+ enumerable: true,
+ get: function() {
+ return uuids_;
+ },
+ set: function(v) {
+ if (T.isNull(v)) {
+ uuids_ = v;
+ } else if (T.isArray(v)) {
+ for (var i = 0; i < v.length; ++i) {
+ if (!T.isString(v[i])) {
+ v[i] = Converter.toString(v[i]);
+ }
+ }
+ uuids_ = v;
+ }
+ }
+ },
+ solicitationuuids: {
+ enumerable: true,
+ get: function() {
+ return solicitationuuids_;
+ },
+ set: function(v) {
+ if (T.isNull(v)) {
+ solicitationuuids_ = v;
+ } else if (T.isArray(v)) {
+ for (var i = 0; i < v.length; ++i) {
+ if (!T.isString(v[i])) {
+ v[i] = Converter.toString(v[i]);
+ }
+ }
+ solicitationuuids_ = v;
+ }
+ }
+ },
+ appearance: {
+ enumerable: true,
+ get: function() {
+ return appearance_;
+ },
+ set: function(v) {
+ appearance_ = Converter.toUnsignedLong(v, true);
+ }
+ },
+ includeTxPowerLevel: {
+ enumerable: true,
+ get: function() {
+ return includeTxPowerLevel_;
+ },
+ set: function(v) {
+ includeTxPowerLevel_ = Converter.toBoolean(v, true);
+ }
+ },
+ serviceData: {
+ enumerable: true,
+ get: function() {
+ return serviceData_;
+ },
+ set: function(v) {
+ if (T.isNull(v) || v instanceof tizen.BluetoothLEServiceData) {
+ serviceData_ = v;
+ }
+ }
+ },
+ manufacturerData: {
+ enumerable: true,
+ get: function() {
+ return manufacturerData_;
+ },
+ set: function(v) {
+ if (T.isNull(v) || v instanceof tizen.BluetoothLEManufacturerData) {
+ manufacturerData_ = v;
+ }
}
- }
- solicitationuuids_ = v;
}
- }
- },
- appearance: {
- enumerable: true,
- get: function() {
- return appearance_;
- },
- set: function(v) {
- appearance_ = Converter.toUnsignedLong(v, true);
- }
- },
- includeTxPowerLevel: {
- enumerable: true,
- get: function() {
- return includeTxPowerLevel_;
- },
- set: function(v) {
- includeTxPowerLevel_ = Converter.toBoolean(v, true);
- }
- },
- serviceData: {
- enumerable: true,
- get: function() {
- return serviceData_;
- },
- set: function(v) {
- if (T.isNull(v) || (v instanceof tizen.BluetoothLEServiceData)) {
- serviceData_ = v;
- }
- }
- },
- manufacturerData: {
- enumerable: true,
- get: function() {
- return manufacturerData_;
- },
- set: function(v) {
- if (T.isNull(v) || (v instanceof tizen.BluetoothLEManufacturerData)) {
- manufacturerData_ = v;
+ });
+
+ if (T.isObject(dict)) {
+ var o = {};
+
+ // includeName
+ if (T.isNull(dict.includeName) || T.isBoolean(dict.includeName)) {
+ o.includeName = dict.includeName;
+ } else if (!T.isUndefined(dict.includeName)) {
+ return;
}
- }
- }
- });
- if (T.isObject(dict)) {
- var o = {};
+ // uuids
+ if (T.isNull(dict.uuids)) {
+ o.uuids = dict.uuids;
+ } else if (T.isArray(dict.uuids)) {
+ for (var i = 0; i < dict.uuids.length; ++i) {
+ if (!T.isString(dict.uuids[i])) {
+ return;
+ }
+ }
+ o.uuids = dict.uuids;
+ } else if (!T.isUndefined(dict.uuids)) {
+ return;
+ }
+
+ // solicitationuuids
+ if (T.isNull(dict.solicitationuuids)) {
+ o.solicitationuuids = dict.solicitationuuids;
+ } else if (T.isArray(dict.solicitationuuids)) {
+ for (var i = 0; i < dict.solicitationuuids.length; ++i) {
+ if (!T.isString(dict.solicitationuuids[i])) {
+ return;
+ }
+ }
+ o.solicitationuuids = dict.solicitationuuids;
+ } else if (!T.isUndefined(dict.solicitationuuids)) {
+ return;
+ }
- // includeName
- if (T.isNull(dict.includeName) || T.isBoolean(dict.includeName)) {
- o.includeName = dict.includeName;
- } else if (!T.isUndefined(dict.includeName)) {
- return;
- }
+ // appearance
+ if (T.isNull(dict.appearance) || T.isNumber(dict.appearance)) {
+ o.appearance = dict.appearance;
+ } else if (!T.isUndefined(dict.appearance)) {
+ return;
+ }
- // uuids
- if (T.isNull(dict.uuids)) {
- o.uuids = dict.uuids;
- } else if (T.isArray(dict.uuids)) {
- for (var i = 0; i < dict.uuids.length; ++i) {
- if (!T.isString(dict.uuids[i])) {
- return;
+ // includeTxPowerLevel
+ if (T.isNull(dict.includeTxPowerLevel) || T.isBoolean(dict.includeTxPowerLevel)) {
+ o.includeTxPowerLevel = dict.includeTxPowerLevel;
+ } else if (!T.isUndefined(dict.includeTxPowerLevel)) {
+ return;
}
- }
- o.uuids = dict.uuids;
- } else if (!T.isUndefined(dict.uuids)) {
- return;
- }
- // solicitationuuids
- if (T.isNull(dict.solicitationuuids)) {
- o.solicitationuuids = dict.solicitationuuids;
- } else if (T.isArray(dict.solicitationuuids)) {
- for (var i = 0; i < dict.solicitationuuids.length; ++i) {
- if (!T.isString(dict.solicitationuuids[i])) {
- return;
+ // serviceData
+ if (
+ T.isNull(dict.serviceData) ||
+ dict.serviceData instanceof tizen.BluetoothLEServiceData
+ ) {
+ o.serviceData = dict.serviceData;
+ } else if (!T.isUndefined(dict.serviceData)) {
+ return;
}
- }
- o.solicitationuuids = dict.solicitationuuids;
- } else if (!T.isUndefined(dict.solicitationuuids)) {
- return;
- }
- // appearance
- if (T.isNull(dict.appearance) || T.isNumber(dict.appearance)) {
- o.appearance = dict.appearance;
- } else if (!T.isUndefined(dict.appearance)) {
- return;
- }
+ // manufacturerData
+ if (
+ T.isNull(dict.manufacturerData) ||
+ dict.manufacturerData instanceof tizen.BluetoothLEManufacturerData
+ ) {
+ o.manufacturerData = dict.manufacturerData;
+ } else if (!T.isUndefined(dict.manufacturerData)) {
+ return;
+ }
- // includeTxPowerLevel
- if (T.isNull(dict.includeTxPowerLevel) || T.isBoolean(dict.includeTxPowerLevel)) {
- o.includeTxPowerLevel = dict.includeTxPowerLevel;
- } else if (!T.isUndefined(dict.includeTxPowerLevel)) {
- return;
+ for (var prop in o) {
+ if (o.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
+ this[prop] = o[prop];
+ }
+ }
}
+ };
- // serviceData
- if (T.isNull(dict.serviceData) || dict.serviceData instanceof tizen.BluetoothLEServiceData) {
- o.serviceData = dict.serviceData;
- } else if (!T.isUndefined(dict.serviceData)) {
- return;
- }
-//class tizen.BluetoothLEManufacturerData //////////////////////////
++//class tizen.BluetoothLEManufacturerData ///////////////////////////
+ tizen.BluetoothLEManufacturerData = function(d) {
+ AV.isConstructorCall(this, tizen.BluetoothLEManufacturerData);
+ var id_ = '';
+ var data_ = '';
- // manufacturerData
- if (T.isNull(dict.manufacturerData) ||
- (dict.manufacturerData instanceof tizen.BluetoothLEManufacturerData)) {
- o.manufacturerData = dict.manufacturerData;
- } else if (!T.isUndefined(dict.manufacturerData)) {
- return;
- }
+ Object.defineProperties(this, {
+ id: {
+ enumerable: true,
+ get: function() {
+ return id_;
+ },
+ set: function(v) {
+ id_ = Converter.toString(v);
+ }
+ },
+ data: {
+ enumerable: true,
+ get: function() {
+ return data_;
+ },
+ set: function(v) {
+ data_ = Converter.toString(v);
+ }
+ }
+ });
- for (var prop in o) {
- if (o.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
- this[prop] = o[prop];
- }
+ if (arguments.length >= 2) {
+ // public constructor
+ this.id = arguments[0];
+ this.data = arguments[1];
+ } else if (d && T.isObject(d)) {
+ // internal constructor
+ this.id = d.id;
+ this.data = d.data;
+ } else {
+ id_ = undefined;
+ data_ = undefined;
}
- }
};
- //class tizen.BluetoothLEManufacturerData ////////////////////////////////////////////////////
- tizen.BluetoothLEManufacturerData = function(d) {
- AV.isConstructorCall(this, tizen.BluetoothLEManufacturerData);
- var id_ = '';
- var data_ = '';
-
- Object.defineProperties(this, {
- id: {
- enumerable: true,
- get: function() {
- return id_;
- },
- set: function(v) {
- id_ = Converter.toString(v);
- }
- },
- data: {
- enumerable: true,
- get: function() {
- return data_;
- },
- set: function(v) {
- data_ = Converter.toString(v);
- }
- }
- });
-
- if (arguments.length >= 2) { // public constructor
- this.id = arguments[0];
- this.data = arguments[1];
- } else if (d && T.isObject(d)) { // internal constructor
- this.id = d.id;
- this.data = d.data;
- } else {
- id_ = undefined;
- data_ = undefined;
- }
- };
-
- // class BluetoothClass ////////////////////////////////////////////////////
-// class BluetoothClass //////////////////////////
++// class BluetoothClass ///////////////////////////
var BluetoothClass = function(data) {
var services = [];
if (data) {
return BluetoothClass_hasService.apply(this, arguments);
};
- // class BluetoothSocket ////////////////////////////////////////////////////
-// class BluetoothSocket //////////////////////////
++// class BluetoothSocket ///////////////////////////
var _BLUETOOTH_SOCKET_STATE_CLOSED = 'CLOSED';
function BluetoothSocketListeners() {
}
};
- //class BluetoothLEDevice ////////////////////////////////////////////////////
-//class BluetoothLEDevice //////////////////////////
++//class BluetoothLEDevice ///////////////////////////
var BluetoothLEDevice = function(data) {
- var address = "", name = null, txpowerlevel = null, appearance = null, uuids = null,
- solicitationuuids = null, serviceData = null, manufacturerData = null, rssi = null;
+ var address = '',
+ name = null,
+ txpowerlevel = null,
+ appearance = null,
+ uuids = null,
+ solicitationuuids = null,
+ serviceData = null,
+ manufacturerData = null,
+ rssi = null;
if (data) {
- address = data.address;
- name = data.name || null;
- txpowerlevel = data.txpowerlevel || null;
- appearance = data.appearance || null;
- uuids = data.uuids || null;
- solicitationuuids = data.solicitationuuids || null;
- if (data.serviceData) {
- data.serviceData.forEach(function(d) {
- serviceData.push(new tizen.BluetoothLEServiceData(d));
- });
- }
- if (data.manufacturerData) {
- manufacturerData = new tizen.BluetoothLEManufacturerData(data.manufacturerData);
- }
- if (data.rssi) {
- rssi = data.rssi;
- }
+ address = data.address;
+ name = data.name || null;
+ txpowerlevel = data.txpowerlevel || null;
+ appearance = data.appearance || null;
+ uuids = data.uuids || null;
+ solicitationuuids = data.solicitationuuids || null;
+ if (data.serviceData) {
+ data.serviceData.forEach(function(d) {
+ serviceData.push(new tizen.BluetoothLEServiceData(d));
+ });
+ }
+ if (data.manufacturerData) {
+ manufacturerData = new tizen.BluetoothLEManufacturerData(
+ data.manufacturerData
+ );
+ }
+ if (data.rssi) {
+ rssi = data.rssi;
+ }
}
Object.defineProperties(this, {
_bleConnectChangeListener.removeListener(args.watchID);
};
- // class BluetoothDevice ////////////////////////////////////////////////////
-// class BluetoothDevice //////////////////////////
++// class BluetoothDevice ///////////////////////////
var BluetoothDevice = function(data) {
var self = this;
function _getter(field) {
}
};
- // class BluetoothServiceHandler ////////////////////////////////////////////////////
-// class BluetoothServiceHandler //////////////////////////
++// class BluetoothServiceHandler ///////////////////////////
function BluetoothServiceListeners() {
var that = this;
- this.serviceCallback = function (data) {
+ this.serviceCallback = function(data) {
var e = data;
var service = that.services[e.uuid];
var result = new BluetoothSocket(e);
_bluetoothServiceListeners.removeListener(this.uuid);
};
- // class BluetoothHealthApplication ////////////////////////////////////////////////////
-// class BluetoothHealthApplication //////////////////////////
++// class BluetoothHealthApplication ///////////////////////////
function BluetoothHealthApplicationListeners() {
var that = this;
- this.appCallback = function (data) {
+ this.appCallback = function(data) {
var event = data;
var app = that.apps[event.id];
BluetoothHealthApplication.prototype.unregister = function() {
privUtils_.log('Entered BluetoothHealthApplication.unregister()');
+ privUtils_.printDeprecationWarningFor('BluetoothHealthApplication');
var args = AV.validateMethod(arguments, [
{
- name : 'successCallback',
- type : AV.Types.FUNCTION,
- optional : true,
- nullable : true
+ name: 'successCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
},
{
- name : 'errorCallback',
- type : AV.Types.FUNCTION,
- optional : true,
- nullable : true
+ name: 'errorCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
}
]);
_bluetoothHealthApplicationListeners.removeListener(this._id);
};
- // class BluetoothProfileHandler ////////////////////////////////////////////////////
-// class BluetoothProfileHandler //////////////////////////
++// class BluetoothProfileHandler ///////////////////////////
var _BluetoothProfileType = {
- HEALTH : 'HEALTH'
+ HEALTH: 'HEALTH'
};
- var BluetoothProfileHandler = function (data) {
+ var BluetoothProfileHandler = function(data) {
if (data) {
+ var profileType = data.profileType;
+ function profileTypeGetter() {
+ privUtils_.printDeprecationWarningFor('profileType');
+ return profileType;
+ }
Object.defineProperties(this, {
- profileType: { enumerable: true, set: function () { }, get: profileTypeGetter }
- profileType: { value: data.profileType, writable: false, enumerable: true }
++ profileType: { enumerable: true, set: function() {}, get: profileTypeGetter }
});
}
};
- // class BluetoothHealthProfileHandler ////////////////////////////////////////////////////
-// class BluetoothHealthProfileHandler //////////////////////////
++// class BluetoothHealthProfileHandler ///////////////////////////
var BluetoothHealthProfileHandler = function(data) {
BluetoothProfileHandler.call(this, data);
};
}
};
- // class BluetoothHealthChannel ////////////////////////////////////////////////////
-// class BluetoothHealthChannel //////////////////////////
++// class BluetoothHealthChannel ///////////////////////////
var BluetoothHealthChannel = function(data) {
Object.defineProperties(this, {
- peer : {value: data.peer, writable: false, enumerable: true},
- channelType : {value: data.channelType, writable: false, enumerable: true},
- application : {
+ peer: { value: data.peer, writable: false, enumerable: true },
+ channelType: { value: data.channelType, writable: false, enumerable: true },
+ application: {
value: _bluetoothHealthApplicationListeners.apps[data.appId],
writable: false,
enumerable: true
BluetoothHealthChannel.prototype.sendData = function() {
privUtils_.log('Entered BluetoothHealthChannel.sendData()');
+ privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
+
var args = AV.validateMethod(arguments, [
{
- name : 'data',
- type : AV.Types.ARRAY,
- values : AV.Types.BYTE
+ name: 'data',
+ type: AV.Types.ARRAY,
+ values: AV.Types.BYTE
}
]);
}
var BluetoothHealthChannel_setListener = function() {
- privUtils_.log('Entered BluetoothHealthChannel.setListener()');
- privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
- privUtils_.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_HEALTH);
- var args = AV.validateMethod(arguments, [
- {
- name : 'changeCallback',
- type : AV.Types.LISTENER,
- values : ['onmessage', 'onclose']
- }
- ]);
+ privUtils_.log('Entered BluetoothHealthChannel.setListener()');
++ privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
+ privUtils_.checkPrivilegeAccess4Ver(
+ '2.4',
+ Privilege.BLUETOOTH,
+ Privilege.BLUETOOTH_HEALTH
+ );
+ var args = AV.validateMethod(arguments, [
+ {
+ name: 'changeCallback',
+ type: AV.Types.LISTENER,
+ values: ['onmessage', 'onclose']
+ }
+ ]);
- if (T.isEmptyObject(_healthListeners)) {
- native.addListener('BluetoothHealthChannelChangeCallback',
- _BluetoothHealthChannelChangeCallback);
- }
- _healthListeners[this._id] = args.changeCallback;
+ if (T.isEmptyObject(_healthListeners)) {
+ native.addListener(
+ 'BluetoothHealthChannelChangeCallback',
+ _BluetoothHealthChannelChangeCallback
+ );
+ }
+ _healthListeners[this._id] = args.changeCallback;
};
-
BluetoothHealthChannel.prototype.setListener = function() {
BluetoothHealthChannel_setListener.apply(this, arguments);
};
- var BluetoothHealthChannel_unsetListener = function() {
- privUtils_.log('Entered BluetoothHealthChannel.unsetListener ()');
- privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
- if (T.isEmptyObject(_healthListeners)) {
- privUtils_.checkPrivilegeAccess4Ver("2.4", Privilege.BLUETOOTH, Privilege.BLUETOOTH_HEALTH);
- }
+ var BluetoothHealthChannel_unsetListener = function() {
+ privUtils_.log('Entered BluetoothHealthChannel.unsetListener ()');
++ privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
+ if (T.isEmptyObject(_healthListeners)) {
+ privUtils_.checkPrivilegeAccess4Ver(
+ '2.4',
+ Privilege.BLUETOOTH,
+ Privilege.BLUETOOTH_HEALTH
+ );
+ }
- delete _healthListeners[this._id];
+ delete _healthListeners[this._id];
- if (T.isEmptyObject(_healthListeners)) {
- native.removeListener('BluetoothHealthChannelChangeCallback',
- _BluetoothHealthChannelChangeCallback);
- }
+ if (T.isEmptyObject(_healthListeners)) {
+ native.removeListener(
+ 'BluetoothHealthChannelChangeCallback',
+ _BluetoothHealthChannelChangeCallback
+ );
+ }
};
- BluetoothHealthChannel.prototype.unsetListener = function() {
- privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
- BluetoothHealthChannel_unsetListener.apply(this, arguments);
+ BluetoothHealthChannel.prototype.unsetListener = function() {
++ privUtils_.printDeprecationWarningFor('BluetoothHealthChannel');
+ BluetoothHealthChannel_unsetListener.apply(this, arguments);
};
-
/**
* Creates a manager for specified listener event.
*
* @return {object} object which allows to add or remove callbacks for specified listener
*/
function _singleListenerBuilder(name, callback) {
- var listenerName = name;
- var successCallback;
- var errorCallback;
- var callbackFunction = callback;
- var listenerRegistered = false;
+ var listenerName = name;
+ var successCallback;
+ var errorCallback;
+ var callbackFunction = callback;
+ var listenerRegistered = false;
- function innerCallback(event) {
- if (!callbackFunction(event, successCallback, errorCallback)) {
- removeListener();
+ function innerCallback(event) {
+ if (!callbackFunction(event, successCallback, errorCallback)) {
+ removeListener();
+ }
}
- }
- function addListener(s, e) {
- successCallback = s;
- errorCallback = e;
+ function addListener(s, e) {
+ successCallback = s;
+ errorCallback = e;
- if (!listenerRegistered) {
- native.addListener(listenerName, innerCallback);
- listenerRegistered = true;
+ if (!listenerRegistered) {
+ native.addListener(listenerName, innerCallback);
+ listenerRegistered = true;
+ }
}
- }
- function removeListener() {
- if (listenerRegistered) {
- native.removeListener(listenerName, innerCallback);
- listenerRegistered = false;
- }
+ function removeListener() {
+ if (listenerRegistered) {
+ native.removeListener(listenerName, innerCallback);
+ listenerRegistered = false;
+ }
- successCallback = undefined;
- errorCallback = undefined;
- }
+ successCallback = undefined;
+ errorCallback = undefined;
+ }
- return {
- addListener: addListener,
- removeListener: removeListener
- };
+ return {
+ addListener: addListener,
+ removeListener: removeListener
+ };
}
- var _bleScanListener = _singleListenerBuilder('BluetoothLEScanCallback',
- function(event, successCallback, errorCallback) {
-
- var d;
- var ret = true;
+ var _bleScanListener = _singleListenerBuilder('BluetoothLEScanCallback', function(
+ event,
+ successCallback,
+ errorCallback
+ ) {
+ var d;
+ var ret = true;
- switch (event.action) {
+ switch (event.action) {
case 'onsuccess':
- d = new BluetoothLEDevice(event.data);
- break;
+ d = new BluetoothLEDevice(event.data);
+ break;
case 'onerror':
- if (errorCallback) {
- errorCallback(native.getErrorObject(event));
- }
- return ret;
+ if (errorCallback) {
+ errorCallback(native.getErrorObject(event));
+ }
+ return ret;
default:
- privUtils_.log('Unknown mode: ' + event.action);
- return ret;
- }
- if (successCallback) {
- successCallback(d);
- }
-
- return ret;
+ privUtils_.log('Unknown mode: ' + event.action);
+ return ret;
+ }
+ if (successCallback) {
+ successCallback(d);
+ }
+
+ return ret;
});
- var _bleAdvertiseListener = _singleListenerBuilder('BluetoothLEAdvertiseCallback',
+ var _bleAdvertiseListener = _singleListenerBuilder(
+ 'BluetoothLEAdvertiseCallback',
function(event, successCallback, errorCallback) {
- var d;
- var ret = true;
-
- switch (event.action) {
- case 'onstate':
- if (successCallback) {
- successCallback(native.getResultObject(event));
- if (native.getResultObject(event) == 'STOPPED') {
- _bleAdvertiseListener.removeListener();
- }
- }
- return ret;
+ var d;
+ var ret = true;
+
+ switch (event.action) {
+ case 'onstate':
+ if (successCallback) {
+ successCallback(native.getResultObject(event));
+ if (native.getResultObject(event) == 'STOPPED') {
+ _bleAdvertiseListener.removeListener();
+ }
+ }
+ return ret;
- case 'onerror':
- if (errorCallback) {
- errorCallback(native.getErrorObject(event));
- }
- return ret;
+ case 'onerror':
+ if (errorCallback) {
+ errorCallback(native.getErrorObject(event));
+ }
+ return ret;
- default:
- privUtils_.log('Unknown mode: ' + event.action);
- return ret;
- }
- });
+ default:
+ privUtils_.log('Unknown mode: ' + event.action);
+ return ret;
+ }
+ }
+ );
- //class BluetoothLEAdapter ////////////////////////////////////////////////////
- var BluetoothLEAdapter = function() {
- };
-//class BluetoothLEAdapter //////////////////////////
++//class BluetoothLEAdapter ///////////////////////////
+ var BluetoothLEAdapter = function() {};
BluetoothLEAdapter.prototype.startScan = function() {
- privUtils_.log('Entered BluetoothLEAdapter.startScan()');
- var args = AV.validateMethod(arguments, [{
- name: 'successCallback',
- type: AV.Types.FUNCTION
- }, {
- name: 'errorCallback',
- type: AV.Types.FUNCTION,
- optional: true,
- nullable: true
- }]);
+ privUtils_.log('Entered BluetoothLEAdapter.startScan()');
+ var args = AV.validateMethod(arguments, [
+ {
+ name: 'successCallback',
+ type: AV.Types.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
- var result = native.callSync('BluetoothLEAdapter_startScan', {});
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- }
+ var result = native.callSync('BluetoothLEAdapter_startScan', {});
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
+ }
- _bleScanListener.addListener(args.successCallback, args.errorCallback);
+ _bleScanListener.addListener(args.successCallback, args.errorCallback);
};
BluetoothLEAdapter.prototype.stopScan = function() {
};
BluetoothLEAdapter.prototype.stopAdvertise = function() {
- privUtils_.log('Entered BluetoothLEAdapter.stopAdvertise()');
+ privUtils_.log('Entered BluetoothLEAdapter.stopAdvertise()');
- var result = native.callSync('BluetoothLEAdapter_stopAdvertise', {});
+ var result = native.callSync('BluetoothLEAdapter_stopAdvertise', {});
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- }
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
+ }
};
- //class BluetoothGATTService ////////////////////////////////////////////////////
-//class BluetoothGATTService //////////////////////////
++//class BluetoothGATTService ///////////////////////////
var BluetoothGATTService = function(data, address) {
var handle_ = data.handle;
var uuid_ = data.uuid;
return d;
};
- //class BluetoothGATTCharacteristic ////////////////////////////////////////////////////
-//class BluetoothGATTCharacteristic //////////////////////////
++//class BluetoothGATTCharacteristic ///////////////////////////
var BluetoothGATTCharacteristic = function(data, address) {
- var handle_ = data.handle;
- var descriptors_ = [];
- var isBroadcast_ = false;
- var hasExtendedProperties_ = false;
- var isNotify_ = false;
- var isIndication_ = false;
- var isReadable_ = false;
- var isSignedWrite_ = false;
- var isWritable_ = false;
- var isWriteNoResponse_ = false;
- //address_ is needed to control if device is still connected
- var address_ = address;
-
- if (T.isObject(data)) {
- data.descriptors.forEach(function(dd) {
- descriptors_.push(new BluetoothGATTDescriptor(dd, address_));
- });
- isBroadcast_ = data.isBroadcast;
- hasExtendedProperties_ = data.hasExtendedProperties;
- isNotify_ = data.isNotify;
- isIndication_ = data.isIndication;
- isReadable_ = data.isReadable;
- isSignedWrite_ = data.isSignedWrite;
- isWritable_ = data.isWritable;
- isWriteNoResponse_ = data.isWriteNoResponse;
- }
-
- Object.defineProperties(this, {
- descriptors: {
- enumerable: true,
- get: function() {
- return descriptors_.slice();
- },
- set: function() {
- }
- },
- isBroadcast: {
- enumerable: true,
- get: function() {
- return isBroadcast_;
- },
- set: function() {
- }
- },
- hasExtendedProperties: {
- enumerable: true,
- get: function() {
- return hasExtendedProperties_;
- },
- set: function() {
- }
- },
- isNotify: {
- enumerable: true,
- get: function() {
- return isNotify_;
- },
- set: function() {
- }
- },
- isIndication: {
- enumerable: true,
- get: function() {
- return isIndication_;
- },
- set: function() {
- }
- },
- isReadable: {
- enumerable: true,
- get: function() {
- return isReadable_;
- },
- set: function() {
- }
- },
- isSignedWrite: {
- enumerable: true,
- get: function() {
- return isSignedWrite_;
- },
- set: function() {
- }
- },
- isWritable: {
- enumerable: true,
- get: function() {
- return isWritable_;
- },
- set: function() {
- }
- },
- isWriteNoResponse: {
- enumerable: true,
- get: function() {
- return isWriteNoResponse_;
- },
- set: function() {
- }
- }
- });
-
- this.readValue = function() {
- privUtils_.log('Entered BluetoothGATTCharacteristic.readValue()');
- var args = AV.validateMethod(arguments, [{
- name: 'successCallback',
- type: AV.Types.FUNCTION
- }, {
- name: 'errorCallback',
- type: AV.Types.FUNCTION,
- optional: true,
- nullable: true
- }]);
-
- var callback = function(result) {
- if (native.isFailure(result)) {
- native.callIfPossible(args.errorCallback, native.getErrorObject(result));
- } else {
- var d = toByteArray(native.getResultObject(result));
- args.successCallback(d);
+ var handle_ = data.handle;
+ var descriptors_ = [];
+ var isBroadcast_ = false;
+ var hasExtendedProperties_ = false;
+ var isNotify_ = false;
+ var isIndication_ = false;
+ var isReadable_ = false;
+ var isSignedWrite_ = false;
+ var isWritable_ = false;
+ var isWriteNoResponse_ = false;
+ //address_ is needed to control if device is still connected
+ var address_ = address;
+
+ if (T.isObject(data)) {
+ data.descriptors.forEach(function(dd) {
+ descriptors_.push(new BluetoothGATTDescriptor(dd, address_));
+ });
+ isBroadcast_ = data.isBroadcast;
+ hasExtendedProperties_ = data.hasExtendedProperties;
+ isNotify_ = data.isNotify;
+ isIndication_ = data.isIndication;
+ isReadable_ = data.isReadable;
+ isSignedWrite_ = data.isSignedWrite;
+ isWritable_ = data.isWritable;
+ isWriteNoResponse_ = data.isWriteNoResponse;
+ }
+
+ Object.defineProperties(this, {
+ descriptors: {
+ enumerable: true,
+ get: function() {
+ return descriptors_.slice();
+ },
+ set: function() {}
+ },
+ isBroadcast: {
+ enumerable: true,
+ get: function() {
+ return isBroadcast_;
+ },
+ set: function() {}
+ },
+ hasExtendedProperties: {
+ enumerable: true,
+ get: function() {
+ return hasExtendedProperties_;
+ },
+ set: function() {}
+ },
+ isNotify: {
+ enumerable: true,
+ get: function() {
+ return isNotify_;
+ },
+ set: function() {}
+ },
+ isIndication: {
+ enumerable: true,
+ get: function() {
+ return isIndication_;
+ },
+ set: function() {}
+ },
+ isReadable: {
+ enumerable: true,
+ get: function() {
+ return isReadable_;
+ },
+ set: function() {}
+ },
+ isSignedWrite: {
+ enumerable: true,
+ get: function() {
+ return isSignedWrite_;
+ },
+ set: function() {}
+ },
+ isWritable: {
+ enumerable: true,
+ get: function() {
+ return isWritable_;
+ },
+ set: function() {}
+ },
+ isWriteNoResponse: {
+ enumerable: true,
+ get: function() {
+ return isWriteNoResponse_;
+ },
+ set: function() {}
}
- };
+ });
- var callArgs = {handle : handle_, address : address_};
+ this.readValue = function() {
+ privUtils_.log('Entered BluetoothGATTCharacteristic.readValue()');
+ var args = AV.validateMethod(arguments, [
+ {
+ name: 'successCallback',
+ type: AV.Types.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
+
+ var callback = function(result) {
+ if (native.isFailure(result)) {
+ native.callIfPossible(args.errorCallback, native.getErrorObject(result));
+ } else {
+ var d = toByteArray(native.getResultObject(result));
+ args.successCallback(d);
+ }
+ };
- var result = native.call('BluetoothGATT_readValue', callArgs, callback);
+ var callArgs = { handle: handle_, address: address_ };
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- }
- };
+ var result = native.call('BluetoothGATT_readValue', callArgs, callback);
- this.writeValue = function() {
- privUtils_.log('Entered BluetoothGATTCharacteristic.writeValue()');
- var args = AV.validateMethod(arguments, [{
- name: 'value',
- type: AV.Types.ARRAY,
- values: AV.Types.BYTE
- }, {
- name: 'successCallback',
- type: AV.Types.FUNCTION,
- optional: true,
- nullable: true
- }, {
- name: 'errorCallback',
- type: AV.Types.FUNCTION,
- optional: true,
- nullable: true
- }]);
-
- var callback = function(result) {
if (native.isFailure(result)) {
- native.callIfPossible(args.errorCallback, native.getErrorObject(result));
- } else {
- native.callIfPossible(args.successCallback);
+ throw native.getErrorObject(result);
}
- };
+ };
- var callArgs = { handle : handle_, value: toByteArray(args.value), address : address_ };
+ this.writeValue = function() {
+ privUtils_.log('Entered BluetoothGATTCharacteristic.writeValue()');
+ var args = AV.validateMethod(arguments, [
+ {
+ name: 'value',
+ type: AV.Types.ARRAY,
+ values: AV.Types.BYTE
+ },
+ {
+ name: 'successCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ {
+ name: 'errorCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
- var result = native.call('BluetoothGATT_writeValue', callArgs, callback);
+ var callback = function(result) {
+ if (native.isFailure(result)) {
+ native.callIfPossible(args.errorCallback, native.getErrorObject(result));
+ } else {
+ native.callIfPossible(args.successCallback);
+ }
+ };
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- }
+ var callArgs = {
+ handle: handle_,
+ value: toByteArray(args.value),
+ address: address_
+ };
+
+ var result = native.call('BluetoothGATT_writeValue', callArgs, callback);
+
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
+ }
};
var addValueChangeListener = function() {
'BluetoothLEDevice_removeConnectStateChangeListener'
);
- //class BluetoothGATTDescriptor ////////////////////////////////////////////////////
-//class BluetoothGATTDescriptor //////////////////////////
++//class BluetoothGATTDescriptor ///////////////////////////
var BluetoothGATTDescriptor = function(data, address) {
- var handle_ = data.handle;
- //address_ is needed to control if device is still connected
- var address_ = address;
-
- this.readValue = function() {
- privUtils_.log('Entered BluetoothGATTDescriptor.readValue()');
- var args = AV.validateMethod(arguments, [{
- name: 'successCallback',
- type: AV.Types.FUNCTION
- }, {
- name: 'errorCallback',
- type: AV.Types.FUNCTION,
- optional: true,
- nullable: true
- }]);
-
- var callback = function(result) {
- if (native.isFailure(result)) {
- native.callIfPossible(args.errorCallback, native.getErrorObject(result));
- } else {
- var d = toByteArray(native.getResultObject(result));
- args.successCallback(d);
- }
- };
-
- var callArgs = {handle : handle_, address : address_};
+ var handle_ = data.handle;
+ //address_ is needed to control if device is still connected
+ var address_ = address;
+
+ this.readValue = function() {
+ privUtils_.log('Entered BluetoothGATTDescriptor.readValue()');
+ var args = AV.validateMethod(arguments, [
+ {
+ name: 'successCallback',
+ type: AV.Types.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
+
+ var callback = function(result) {
+ if (native.isFailure(result)) {
+ native.callIfPossible(args.errorCallback, native.getErrorObject(result));
+ } else {
+ var d = toByteArray(native.getResultObject(result));
+ args.successCallback(d);
+ }
+ };
- var result = native.call('BluetoothGATT_readValue', callArgs, callback);
+ var callArgs = { handle: handle_, address: address_ };
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- }
- };
-
- this.writeValue = function() {
- privUtils_.log('Entered BluetoothGATTDescriptor.writeValue()');
- var args = AV.validateMethod(arguments, [{
- name: 'value',
- type: AV.Types.ARRAY,
- values: AV.Types.BYTE
- }, {
- name: 'successCallback',
- type: AV.Types.FUNCTION,
- optional: true,
- nullable: true
- }, {
- name: 'errorCallback',
- type: AV.Types.FUNCTION,
- optional: true,
- nullable: true
- }]);
+ var result = native.call('BluetoothGATT_readValue', callArgs, callback);
- var callback = function(result) {
- if (native.isFailure(result)) {
- native.callIfPossible(args.errorCallback, native.getErrorObject(result));
- } else {
- native.callIfPossible(args.successCallback);
- }
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
+ }
};
- var callArgs = { handle : handle_, value: toByteArray(args.value), address : address_ };
+ this.writeValue = function() {
+ privUtils_.log('Entered BluetoothGATTDescriptor.writeValue()');
+ var args = AV.validateMethod(arguments, [
+ {
+ name: 'value',
+ type: AV.Types.ARRAY,
+ values: AV.Types.BYTE
+ },
+ {
+ name: 'successCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ {
+ name: 'errorCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
- var result = native.call('BluetoothGATT_writeValue', callArgs, callback);
+ var callback = function(result) {
+ if (native.isFailure(result)) {
+ native.callIfPossible(args.errorCallback, native.getErrorObject(result));
+ } else {
+ native.callIfPossible(args.successCallback);
+ }
+ };
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- }
- };
- };
+ var callArgs = {
+ handle: handle_,
+ value: toByteArray(args.value),
+ address: address_
+ };
+ var result = native.call('BluetoothGATT_writeValue', callArgs, callback);
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
+ }
+ };
+ };
- // class BluetoothAdapter ////////////////////////////////////////////////////
-// class BluetoothAdapter //////////////////////////
++// class BluetoothAdapter ///////////////////////////
var BluetoothAdapter = function() {
function nameGetter() {
var result = native.callSync('BluetoothAdapter_getName', {});
BluetoothAdapter.prototype.setPowered = function() {
privUtils_.log('Entered BluetoothAdapter.setPowered()');
- privUtils_.warn('Let the user turn on/off Bluetooth through the Settings application instead.');
+ privUtils_.printDeprecationWarningFor('setPowered()');
- 'DEPRECATION WARNING: setPowered() is deprecated and will be removed from ' +
- 'next release. Let the user turn on/off Bluetooth through the Settings ' +
- 'application instead.'
+ privUtils_.warn(
++ 'Let the user turn on/off Bluetooth through the Settings application instead.'
+ );
var args = AV.validateMethod(arguments, [
{
}
};
-
-// This method is deprecated since Tizen 2.3 and will be removed in Tizen 3.0.
+// This method is deprecated since Tizen 2.3.
BluetoothAdapter.prototype.setVisible = function() {
privUtils_.log('Entered BluetoothAdapter.setVisible()');
- privUtils_.warn('Let the user change the Bluetooth visibility through the Settings application instead.');
+ privUtils_.printDeprecationWarningFor('setVisible()');
- 'DEPRECATION WARNING: setVisible() is deprecated and will be removed from ' +
- 'next release. Let the user change the Bluetooth visibility through the ' +
- 'Settings application instead.'
+ privUtils_.warn(
++ 'Let the user change the Bluetooth visibility through the Settings ' +
++ 'application instead.'
+ );
var args = AV.validateMethod(arguments, [
{
BluetoothAdapter.prototype.getBluetoothProfileHandler = function() {
privUtils_.log('Entered BluetoothAdapter.getBluetoothProfileHandler()');
-
+ privUtils_.printDeprecationWarningFor('getBluetoothProfileHandler');
var args = AV.validateMethod(arguments, [
{
- name : 'profileType',
- type : AV.Types.ENUM,
- values : T.getValues(_BluetoothProfileType)
+ name: 'profileType',
+ type: AV.Types.ENUM,
+ values: T.getValues(_BluetoothProfileType)
}
]);
}
};
- // class BluetoothManager ////////////////////////////////////////////////////
-// class BluetoothManager //////////////////////////
++// class BluetoothManager ///////////////////////////
var BluetoothManager = function() {
Object.defineProperties(this, {
- deviceMajor : {
+ deviceMajor: {
value: new BluetoothClassDeviceMajor(),
writable: false,
enumerable: true
privUtils_.log('Entered BluetoothManager.getLEAdapter()');
return BluetoothManager_getLEAdapter();
};
- // exports ///////////////////////////////////////////////////////////////////
-// exports /////////////////////////////////////////
++// exports //////////////////////////////////////////
exports = new BluetoothManager();
};
BookmarkManager.prototype.remove = function() {
- var args = validator_.validateArgs(arguments, [
- {
- name: 'bookmark',
- type: types_.PLATFORM_OBJECT,
- values: [tizen.BookmarkFolder, tizen.BookmarkItem],
- optional: true,
- nullable: true
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'bookmark',
+ type: types_.PLATFORM_OBJECT,
+ values: [tizen.BookmarkFolder, tizen.BookmarkItem],
+ optional: true,
+ nullable: true
+ }
+ ]);
+
+ if (!arguments.length || args.bookmark === null) {
+ var result = native_.callSync('Bookmark_removeAll');
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
-
+ return;
+ }
+
+ if (!args.bookmark.id) {
+ throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
}
- ]);
- if (!arguments.length || args.bookmark === null) {
- var result = native_.callSync('Bookmark_removeAll');
+ var result = native_.isFailure(
+ native_.callSync('Bookmark_remove', { id: args.bookmark.id })
+ );
if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
+ throw native_.getErrorObject(result);
}
- return;
- }
-
- if (!args.bookmark.id) {
- throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
- }
-
- var result = native_.isFailure(native_.callSync('Bookmark_remove', {id: args.bookmark.id}));
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
-
- _edit.allow();
- args.bookmark.id = null;
- args.bookmark.parent = undefined;
- _edit.disallow();
+
+ _edit.allow();
+ args.bookmark.id = null;
+ args.bookmark.parent = undefined;
+ _edit.disallow();
};
function BookmarkProvider() {}
BookmarkProvider.prototype.addToFolder = function() {
- var args = validator_.validateArgs(arguments, [
- {
- name: 'bookmark',
- type: types_.PLATFORM_OBJECT,
- values: [tizen.BookmarkFolder, tizen.BookmarkItem],
- optional: true,
- nullable: true
- },
- {
- name: 'parentId',
- type: types_.DOUBLE,
- optional: false,
- nullable: false}
- ]);
- var ret = native_.callSync('Bookmark_add',
- {
- title: args.bookmark.title,
- url: String(args.bookmark.url),
- parentId: args.parentId,
- type: args.bookmark instanceof tizen.BookmarkFolder
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'bookmark',
+ type: types_.PLATFORM_OBJECT,
+ values: [tizen.BookmarkFolder, tizen.BookmarkItem],
+ optional: true,
+ nullable: true
+ },
+ {
+ name: 'parentId',
+ type: types_.DOUBLE,
+ optional: false,
+ nullable: false
+ }
+ ]);
+ var ret = native_.callSync('Bookmark_add', {
+ title: args.bookmark.title,
+ url: String(args.bookmark.url),
+ parentId: args.parentId,
- type: args.bookmark instanceof tizen.BookmarkFolder ? 1 : 0
++ type: args.bookmark instanceof tizen.BookmarkFolder
+ });
+
+ if (native_.isFailure(ret)) {
+ throw native_.getErrorObject(ret);
}
- );
- if (native_.isFailure(ret)) {
- throw native_.getErrorObject(ret);
- }
-
- var ret_id = native_.getResultObject(ret);
- _edit.allow();
- args.bookmark.id = ret_id;
- args.bookmark.parent = this.getFolder(args.parentId);
- _edit.disallow();
+ var ret_id = native_.getResultObject(ret);
+ _edit.allow();
+ args.bookmark.id = ret_id;
+ args.bookmark.parent = this.getFolder(args.parentId);
+ _edit.disallow();
};
BookmarkProvider.prototype.getFolder = function() {
- var args = validator_.validateArgs(arguments, [
- {
- name: 'id',
- type: types_.DOUBLE,
- optional: false,
- nullable: false
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'id',
+ type: types_.DOUBLE,
+ optional: false,
+ nullable: false
+ }
+ ]);
+ if (arguments.length === 0 || args.id <= 0) return null;
+ if (args.id == this.getRootId()) return null;
+
+ var ret = native_.callSync('Bookmark_get', {
+ id: args.id,
- shouldGetItems: 0
++ shouldGetItems: false
+ });
+
+ if (native_.isFailure(ret)) {
+ throw native_.getErrorObject(ret);
}
- ]);
- if (arguments.length === 0 || args.id <= 0)
- return null;
- if (args.id == this.getRootId())
- return null;
-
- var ret = native_.callSync('Bookmark_get', {
- id: args.id,
- shouldGetItems: false
- });
-
- if (native_.isFailure(ret)) {
- throw native_.getErrorObject(ret);
- }
-
- var folder = native_.getResultObject(ret);
- if (folder === undefined || folder === null) {
- throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
- }
-
- var obj = new tizen.BookmarkFolder(folder[0].title);
- obj.id = folder[0].id;
- obj.parent = this.getFolder(folder[0].parentId);
- return obj;
- };
- BookmarkProvider.prototype.getFolderItems = function() {
- var args = validator_.validateArgs(arguments, [
- {
- name: 'id',
- type: types_.DOUBLE,
- optional: false,
- nullable: false
- },
- {
- name: 'recursive',
- type: types_.BOOLEAN,
- optional: true,
- nullable: true
+ var folder = native_.getResultObject(ret);
+ if (folder === undefined || folder === null) {
+ throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
}
- ]);
- var ret = native_.callSync('Bookmark_get', {
- id: Number(args.id),
- shouldGetItems: true
- });
+ var obj = new tizen.BookmarkFolder(folder[0].title);
+ obj.id = folder[0].id;
+ obj.parent = this.getFolder(folder[0].parentId);
+ return obj;
+ };
- if (native_.isFailure(ret)) {
- throw native_.getErrorObject(ret);
- }
+ BookmarkProvider.prototype.getFolderItems = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'id',
+ type: types_.DOUBLE,
+ optional: false,
+ nullable: false
+ },
+ {
+ name: 'recursive',
+ type: types_.BOOLEAN,
+ optional: true,
+ nullable: true
+ }
+ ]);
+
+ var ret = native_.callSync('Bookmark_get', {
+ id: Number(args.id),
- shouldGetItems: 1
++ shouldGetItems: true
+ });
+
+ if (native_.isFailure(ret)) {
+ throw native_.getErrorObject(ret);
+ }
- var folder = native_.getResultObject(ret);
- if (folder === undefined) {
- throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
- }
+ var folder = native_.getResultObject(ret);
+ if (folder === undefined) {
+ throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
+ }
- var item;
- var obj;
- var result = [];
- var len = folder.length;
+ var item;
+ var obj;
+ var result = [];
+ var len = folder.length;
- for (var i = 0; item = folder[i], i < len; i++) {
- if (Number(item.type) === 0)
- obj = new tizen.BookmarkItem(item.title, item.url);
- else
- obj = new tizen.BookmarkFolder(item.title);
+ for (var i = 0; (item = folder[i]), i < len; i++) {
+ if (Number(item.type) === 0) obj = new tizen.BookmarkItem(item.title, item.url);
+ else obj = new tizen.BookmarkFolder(item.title);
- _edit.allow();
- obj.id = item.id;
- obj.parent = this.getFolder(item.parentId);
- _edit.disallow();
- result.push(obj);
+ _edit.allow();
+ obj.id = item.id;
+ obj.parent = this.getFolder(item.parentId);
+ _edit.disallow();
+ result.push(obj);
- if (args.recursive && Number(item.type) !== 0)
- result = result.concat(this.getFolderItems(item.id, true));
- }
- return result;
+ if (args.recursive && Number(item.type) !== 0)
+ result = result.concat(this.getFolderItems(item.id, true));
+ }
+ return result;
};
BookmarkProvider.prototype.getRootId = function() {
};
var Calendar_removeChangeListener = function() {
- if (type_.isEmptyObject(_listeners)) {
- utils_.checkPrivilegeAccess(privilege_.CALENDAR_READ);
- }
- var args = validator_.validateArgs(arguments, [
- {
- name: 'watchId',
- type: types_.LONG
+ if (type_.isEmptyObject(_listeners)) {
+ utils_.checkPrivilegeAccess(privilege_.CALENDAR_READ);
}
- ]);
-
- var watchId = converter_.toString(args.watchId);
- var calendarId = (this.isUnified) ? this.type : this.id;
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'watchId',
+ type: types_.LONG
+ }
+ ]);
- if (!_listeners[calendarId] || !_listeners[calendarId][watchId]) {
- return;
- }
+ var watchId = converter_.toString(args.watchId);
+ var calendarId = this.isUnified ? this.type : this.id;
- delete _listeners[calendarId][watchId];
+ if (!_listeners[calendarId] || !_listeners[calendarId][watchId]) {
+ return;
+ }
- if (type_.isEmptyObject(_listeners[calendarId])) {
- delete _listeners[calendarId];
- }
+ delete _listeners[calendarId][watchId];
- if (type_.isEmptyObject(_listeners)) {
+ if (type_.isEmptyObject(_listeners[calendarId])) {
+ delete _listeners[calendarId];
+ }
- var result;
- // @todo consider listener unregister when we are not listening on this.type of calendar
- var fail = false;
- for (var listenerId in _nativeListeners) {
- if (_nativeListeners.hasOwnProperty(listenerId)) {
- result = native_.callSync('Calendar_removeChangeListener', {
- type: _nativeListeners[listenerId]
- });
- if (native_.isFailure(result)) {
- fail = native_.getErrorObject(result);
+ if (type_.isEmptyObject(_listeners)) {
+ var result;
- // @todo consider listener unregister when we are not listening on
- // this.type of calendar
++ // @todo consider listener unregister when we are not listening on this.type
++ // of calendar
+ var fail = false;
+ for (var listenerId in _nativeListeners) {
+ if (_nativeListeners.hasOwnProperty(listenerId)) {
+ result = native_.callSync('Calendar_removeChangeListener', {
+ type: _nativeListeners[listenerId]
+ });
+ if (native_.isFailure(result)) {
+ fail = native_.getErrorObject(result);
+ }
+ native_.removeListener(
+ listenerId,
+ this.type === 'EVENT'
+ ? _CalendarEventChangeCallback
+ : _CalendarTaskChangeCallback
+ );
+
+ delete _nativeListeners[listenerId];
+ }
}
- native_.removeListener(listenerId, (this.type === 'EVENT')
- ? _CalendarEventChangeCallback
- : _CalendarTaskChangeCallback);
- delete _nativeListeners[listenerId];
- }
- }
-
- if (fail) {
- throw fail;
+ if (fail) {
+ throw fail;
+ }
}
- }
};
Calendar.prototype.removeChangeListener = function() {
// class CalendarItem
var CalendarItem = function(data) {
- var _id = null;
- var _calendarId = null;
- var _lastModificationDate = null;
- var _description = '';
- var _summary = '';
- var _isAllDay = false;
- var _startDate = null;
- var _duration = null;
- var _location = '';
- var _geolocation = null;
- var _organizer = '';
- var _visibility = CalendarItemVisibility.PUBLIC;
- var _status = CalendarItemStatus.NONE;
- var _priority = CalendarItemPriority.NONE;
- var _alarms = [];
- var _categories = [];
- var _attendees = [];
-
- function _validateAlarms(v) {
- var valid = false;
-
- if (type_.isArray(v)) {
- for (var i = 0; i < v.length; i++) {
- if (!(v[i] instanceof tizen.CalendarAlarm)) {
- return false;
+ var _id = null;
+ var _calendarId = null;
+ var _lastModificationDate = null;
+ var _description = '';
+ var _summary = '';
+ var _isAllDay = false;
+ var _startDate = null;
+ var _duration = null;
+ var _location = '';
+ var _geolocation = null;
+ var _organizer = '';
+ var _visibility = CalendarItemVisibility.PUBLIC;
+ var _status = CalendarItemStatus.NONE;
+ var _priority = CalendarItemPriority.NONE;
+ var _alarms = [];
+ var _categories = [];
+ var _attendees = [];
+
+ function _validateAlarms(v) {
+ var valid = false;
+
+ if (type_.isArray(v)) {
+ for (var i = 0; i < v.length; i++) {
+ if (!(v[i] instanceof tizen.CalendarAlarm)) {
+ return false;
+ }
+ }
+ valid = true;
}
- }
- valid = true;
+ return valid;
}
- return valid;
- }
- function _validateAttendees(v) {
- var valid = false;
+ function _validateAttendees(v) {
+ var valid = false;
- if (type_.isArray(v)) {
- for (var i = 0; i < v.length; i++) {
- if (!(v[i] instanceof tizen.CalendarAttendee)) {
- return false;
+ if (type_.isArray(v)) {
+ for (var i = 0; i < v.length; i++) {
+ if (!(v[i] instanceof tizen.CalendarAttendee)) {
+ return false;
+ }
+ }
+ valid = true;
}
- }
- valid = true;
+ return valid;
}
- return valid;
- }
- function _validateCategories(v) {
- var valid = false;
+ function _validateCategories(v) {
+ var valid = false;
- if (type_.isArray(v)) {
- for (var i = 0; i < v.length; i++) {
- if (!(type_.isString(v[i]))) {
- return false;
+ if (type_.isArray(v)) {
+ for (var i = 0; i < v.length; i++) {
+ if (!type_.isString(v[i])) {
+ return false;
+ }
+ }
+ valid = true;
}
- }
- valid = true;
+ return valid;
}
- return valid;
- }
-
- Object.defineProperties(this, {
- id: {
- get: function() {
- return _id;
- },
- set: function(v) {
- if (_edit.canEdit) {
- if (v instanceof _global.Object) {
- _id = new CalendarEventId(v.uid, v.rid);
- } else {
- _id = converter_.toString(v, true);
- }
- }
- },
- enumerable: true
- },
- calendarId: {
- get: function() {
- return _calendarId;
- },
- set: function(v) {
- if (_edit.canEdit) {
- _calendarId = v;
- }
- },
- enumerable: true
- },
- lastModificationDate: {
- get: function() {
- return _lastModificationDate;
- },
- set: function(v) {
- if (_edit.canEdit) {
- _lastModificationDate = v instanceof tizen.TZDate ? v :
- tizen.time.getCurrentDateTime();
- }
- },
- enumerable: true
- },
- description: {
- get: function() {
- return _description;
- },
- set: function(v) {
- _description = v ? converter_.toString(v, true) : _description;
- },
- enumerable: true
- },
- summary: {
- get: function() {
- return _summary;
- },
- set: function(v) {
- _summary = v ? converter_.toString(v, true) : _summary;
- },
- enumerable: true
- },
- isAllDay: {
- get: function() {
- return _isAllDay;
- },
- set: function(v) {
- _isAllDay = converter_.toBoolean(v);
- },
- enumerable: true
- },
- startDate: {
- get: function() {
- return _startDate;
- },
- set: function(v) {
- _startDate = v instanceof tizen.TZDate ? v : _startDate;
- this.duration = _duration;
- },
- enumerable: true
- },
- duration: {
- get: function() {
- return _duration;
- },
- set: function(v) {
- // set duration as dueDate or endDate
- var _startDate = this.startDate ?
- this.startDate : tizen.time.getCurrentDateTime();
- if (this instanceof tizen.CalendarEvent) {
- this.endDate = v instanceof tizen.TimeDuration ?
- _startDate.addDuration(v) : this.endDate;
- } else {
- this.dueDate = v instanceof tizen.TimeDuration ?
- _startDate.addDuration(v) : this.dueDate;
- }
- _duration = v instanceof tizen.TimeDuration ? v : null;
- //@todo Fix UTC, UTC expect duration value but according to documentation:
- // ... the implementation may not save the duration itself,
- // rather convert it to the corresponding endDate/dueDate attribute and save it.
- // For example, if you set the startDate and the duration attributes and save the item,
- // you may see that the duration is null while endDate/dueDate is non-null
- // after retrieving it because the implementation has calculated the endDate/dueDate
- // based on the duration and the startDate then saved it, not the duration.
- },
- enumerable: true
- },
- location: {
- get: function() {
- return _location;
- },
- set: function(v) {
- _location = v ? converter_.toString(v) : _location;
- },
- enumerable: true
- },
- geolocation: {
- get: function() {
- return _geolocation;
- },
- set: function(v) {
- _geolocation = v instanceof tizen.SimpleCoordinates ? v : _geolocation;
- },
- enumerable: true
- },
- organizer: {
- get: function() {
- return _organizer;
- },
- set: function(v) {
- _organizer = v ? converter_.toString(v) : _organizer;
- },
- enumerable: true
- },
- visibility: {
- get: function() {
- return _visibility;
- },
- set: function(v) {
- _visibility = v ? converter_.toEnum(v, Object.keys(CalendarItemVisibility), false) :
- _visibility;
- },
- enumerable: true
- },
- status: {
- get: function() {
- return _status;
- },
- set: function(v) {
- if (v === null) {
- return;
- }
- if (this instanceof tizen.CalendarEvent) {
- _status = v ? converter_.toEnum(v, Object.keys(CalendarItemStatus).slice(0, 4), false) :
- CalendarItemStatus.NONE;
- } else {
- _status = v ? converter_.toEnum(v, Object.keys(CalendarItemStatus).slice(2), false) :
- CalendarItemStatus.NONE;
+
+ Object.defineProperties(this, {
+ id: {
+ get: function() {
+ return _id;
+ },
+ set: function(v) {
+ if (_edit.canEdit) {
+ if (v instanceof _global.Object) {
+ _id = new CalendarEventId(v.uid, v.rid);
+ } else {
+ _id = converter_.toString(v, true);
+ }
+ }
+ },
+ enumerable: true
+ },
+ calendarId: {
+ get: function() {
+ return _calendarId;
+ },
+ set: function(v) {
+ if (_edit.canEdit) {
+ _calendarId = v;
+ }
+ },
+ enumerable: true
+ },
+ lastModificationDate: {
+ get: function() {
+ return _lastModificationDate;
+ },
+ set: function(v) {
+ if (_edit.canEdit) {
+ _lastModificationDate =
+ v instanceof tizen.TZDate ? v : tizen.time.getCurrentDateTime();
+ }
+ },
+ enumerable: true
+ },
+ description: {
+ get: function() {
+ return _description;
+ },
+ set: function(v) {
+ _description = v ? converter_.toString(v, true) : _description;
+ },
+ enumerable: true
+ },
+ summary: {
+ get: function() {
+ return _summary;
+ },
+ set: function(v) {
+ _summary = v ? converter_.toString(v, true) : _summary;
+ },
+ enumerable: true
+ },
+ isAllDay: {
+ get: function() {
+ return _isAllDay;
+ },
+ set: function(v) {
+ _isAllDay = converter_.toBoolean(v);
+ },
+ enumerable: true
+ },
+ startDate: {
+ get: function() {
+ return _startDate;
+ },
+ set: function(v) {
+ _startDate = v instanceof tizen.TZDate ? v : _startDate;
+ this.duration = _duration;
+ },
+ enumerable: true
+ },
+ duration: {
+ get: function() {
+ return _duration;
+ },
+ set: function(v) {
+ // set duration as dueDate or endDate
+ var _startDate = this.startDate
+ ? this.startDate
+ : tizen.time.getCurrentDateTime();
+ if (this instanceof tizen.CalendarEvent) {
+ this.endDate =
+ v instanceof tizen.TimeDuration
+ ? _startDate.addDuration(v)
+ : this.endDate;
+ } else {
+ this.dueDate =
+ v instanceof tizen.TimeDuration
+ ? _startDate.addDuration(v)
+ : this.dueDate;
+ }
+ _duration = v instanceof tizen.TimeDuration ? v : null;
+ //@todo Fix UTC, UTC expect duration value but according to
+ // documentation:
+ // ... the implementation may not save the duration itself,
- // rather convert it to the corresponding endDate/dueDate attribute and
- // save it. For example, if you set the startDate and the duration
- // attributes and save the item, you may see that the duration is null
- // while endDate/dueDate is non-null after retrieving it because the
++ // rather convert it to the corresponding endDate/dueDate attribute
++ // and save it.
++ // For example, if you set the startDate and the duration attributes and
++ // save the item, you may see that the duration is null while
++ // endDate/dueDate is non-null after retrieving it because the
+ // implementation has calculated the endDate/dueDate based on the
+ // duration and the startDate then saved it, not the duration.
+ },
+ enumerable: true
+ },
+ location: {
+ get: function() {
+ return _location;
+ },
+ set: function(v) {
+ _location = v ? converter_.toString(v) : _location;
+ },
+ enumerable: true
+ },
+ geolocation: {
+ get: function() {
+ return _geolocation;
+ },
+ set: function(v) {
+ _geolocation = v instanceof tizen.SimpleCoordinates ? v : _geolocation;
+ },
+ enumerable: true
+ },
+ organizer: {
+ get: function() {
+ return _organizer;
+ },
+ set: function(v) {
+ _organizer = v ? converter_.toString(v) : _organizer;
+ },
+ enumerable: true
+ },
+ visibility: {
+ get: function() {
+ return _visibility;
+ },
+ set: function(v) {
+ _visibility = v
+ ? converter_.toEnum(v, Object.keys(CalendarItemVisibility), false)
+ : _visibility;
+ },
+ enumerable: true
+ },
+ status: {
+ get: function() {
+ return _status;
+ },
+ set: function(v) {
+ if (v === null) {
+ return;
+ }
+ if (this instanceof tizen.CalendarEvent) {
+ _status = v
+ ? converter_.toEnum(
+ v,
+ Object.keys(CalendarItemStatus).slice(0, 4),
+ false
+ )
+ : CalendarItemStatus.NONE;
+ } else {
+ _status = v
+ ? converter_.toEnum(
+ v,
+ Object.keys(CalendarItemStatus).slice(2),
+ false
+ )
+ : CalendarItemStatus.NONE;
+ }
+ },
+ enumerable: true
+ },
+ priority: {
+ get: function() {
+ return _priority;
+ },
+ set: function(v) {
+ if (v === null) {
+ return;
+ }
+ _priority = v
+ ? converter_.toEnum(v, Object.keys(CalendarItemPriority), false)
+ : _status;
+ },
+ enumerable: true
+ },
+ alarms: {
+ get: function() {
+ return _alarms;
+ },
+ set: function(v) {
+ _alarms = _validateAlarms(v) ? v : _alarms;
+ },
+ enumerable: true
+ },
+ categories: {
+ get: function() {
+ return _categories;
+ },
+ set: function(v) {
+ _categories = _validateCategories(v) ? v : _categories;
+ },
+ enumerable: true
+ },
+ attendees: {
+ get: function() {
+ return _attendees;
+ },
+ set: function(v) {
+ _attendees = _validateAttendees(v) ? v : _attendees;
+ },
+ enumerable: true
}
- },
- enumerable: true
- },
- priority: {
- get: function() {
- return _priority;
- },
- set: function(v) {
- if (v === null) {
- return;
+ });
+
+ if (data instanceof _global.Object) {
+ for (var prop in data) {
+ if (this.hasOwnProperty(prop)) {
+ this[prop] = data[prop];
+ }
}
- _priority = v ? converter_.toEnum(v, Object.keys(CalendarItemPriority), false) :
- _status;
- },
- enumerable: true
- },
- alarms: {
- get: function() {
- return _alarms;
- },
- set: function(v) {
- _alarms = _validateAlarms(v) ? v : _alarms;
- },
- enumerable: true
- },
- categories: {
- get: function() {
- return _categories;
- },
- set: function(v) {
- _categories = _validateCategories(v) ? v : _categories;
- },
- enumerable: true
- },
- attendees: {
- get: function() {
- return _attendees;
- },
- set: function(v) {
- _attendees = _validateAttendees(v) ? v : _attendees;
- },
- enumerable: true
}
- });
+ };
- if (data instanceof _global.Object) {
- for (var prop in data) {
- if (this.hasOwnProperty(prop)) {
- this[prop] = data[prop];
- }
+ var CalendarItem_convertToString = function() {
+ utils_.checkPrivilegeAccess(privilege_.CALENDAR_READ);
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'format',
+ type: types_.ENUM,
+ values: Object.keys(CalendarTextFormat)
+ }
+ ]);
+
+ var _checkNumber = function(n) {
+ return n < 10 ? '0' + n : n;
+ };
+
+ var _timeFormat = function(d) {
+ return (
+ ';TZID=' +
+ d.getTimezone() +
+ ':' +
+ d.getFullYear() +
+ _checkNumber(d.getMonth()) +
+ _checkNumber(d.getDate()) +
+ 'T' +
+ _checkNumber(d.getHours()) +
+ _checkNumber(d.getMinutes()) +
+ _checkNumber(d.getSeconds() + 'Z')
+ );
+ };
+
+ var _this = this;
+ var _dtStart = '';
+
+ if (_this.startDate) {
+ _dtStart = _timeFormat(_this.startDate);
+ } else {
+ _dtStart = _timeFormat(tizen.time.getCurrentDateTime());
}
- }
- };
+ var _dtEnd = _dtStart;
- var CalendarItem_convertToString = function() {
- utils_.checkPrivilegeAccess(privilege_.CALENDAR_READ);
- var args = validator_.validateArgs(arguments, [
- {
- name: 'format',
- type: types_.ENUM,
- values: Object.keys(CalendarTextFormat)
+ if (_this.endDate) {
+ _dtEnd = _timeFormat(_this.endDate);
+ } else if (_this.dueDate) {
+ _dtEnd = _timeFormat(_this.dueDate);
}
- ]);
-
- var _checkNumber = function(n) {
- return n < 10 ? '0' + n : n;
- };
-
- var _timeFormat = function(d) {
- return ';TZID=' + d.getTimezone() +
- ':' + d.getFullYear() + _checkNumber(d.getMonth()) + _checkNumber(d.getDate()) +
- 'T' + _checkNumber(d.getHours()) + _checkNumber(d.getMinutes()) +
- _checkNumber(d.getSeconds() + 'Z');
- };
-
- var _this = this;
- var _dtStart = '';
-
- if (_this.startDate) {
- _dtStart = _timeFormat(_this.startDate);
- } else {
- _dtStart = _timeFormat(tizen.time.getCurrentDateTime());
- }
-
- var _dtEnd = _dtStart;
-
- if (_this.endDate) {
- _dtEnd = _timeFormat(_this.endDate);
- } else if (_this.dueDate) {
- _dtEnd = _timeFormat(_this.dueDate);
- }
-
- var _description = _this.description.length ? ':' + _this.description : '';
- var _location = _this.location.length ? ':' + _this.location : '';
- var _organizer = _this.organizer.length ? ';CN=' + _this.organizer : '';
- var _priority = _this.priority.length ? ':' + _this.priority : '';
- var _summary = _this.summary.length ? ':' + _this.summary : '';
- var _categories = _this.categories.length ? ':' + _this.categories.join(', ') : '';
- var _visibility = _this.visibility;
- var _status = _this.status;
- var _version = args.format === CalendarTextFormat.ICALENDAR_20 ? ':2.0' : ':1.0';
-
- var vEven = [
- 'BEGIN:VCALENDAR',
- 'VERSION' + _version,
- 'BEGIN:VEVENT',
- 'CLASS:' + _visibility,
- 'TRANSP:OPAQUE',
- 'DTSTART' + _dtStart,
- 'DESCRIPTION' + _description,
- 'LOCATION' + _location,
- 'ORGANIZER' + _organizer,
- 'PRIORITY' + _priority,
- 'SUMMARY' + _summary,
- 'DTEND' + _dtEnd,
- 'CATEGORIES' + _categories,
- 'END:VEVENT',
- 'END:VCALENDAR'
- ].join('\n');
-
- var vTodo = [
- 'BEGIN:VCALENDAR',
- 'VERSION' + _version,
- 'BEGIN:VTODO',
- 'SUMMARY' + _summary,
- 'DUE' + _dtEnd,
- 'STATUS' + _status,
- 'END:VTODO',
- 'END:VCALENDAR'
- ].join('\n');
-
- if (this instanceof tizen.CalendarTask) {
- return vTodo;
- } else {
- return vEven;
- }
+ var _description = _this.description.length ? ':' + _this.description : '';
+ var _location = _this.location.length ? ':' + _this.location : '';
+ var _organizer = _this.organizer.length ? ';CN=' + _this.organizer : '';
+ var _priority = _this.priority.length ? ':' + _this.priority : '';
+ var _summary = _this.summary.length ? ':' + _this.summary : '';
+ var _categories = _this.categories.length ? ':' + _this.categories.join(', ') : '';
+ var _visibility = _this.visibility;
+ var _status = _this.status;
+ var _version = args.format === CalendarTextFormat.ICALENDAR_20 ? ':2.0' : ':1.0';
+
+ var vEven = [
+ 'BEGIN:VCALENDAR',
+ 'VERSION' + _version,
+ 'BEGIN:VEVENT',
+ 'CLASS:' + _visibility,
+ 'TRANSP:OPAQUE',
+ 'DTSTART' + _dtStart,
+ 'DESCRIPTION' + _description,
+ 'LOCATION' + _location,
+ 'ORGANIZER' + _organizer,
+ 'PRIORITY' + _priority,
+ 'SUMMARY' + _summary,
+ 'DTEND' + _dtEnd,
+ 'CATEGORIES' + _categories,
+ 'END:VEVENT',
+ 'END:VCALENDAR'
+ ].join('\n');
+
+ var vTodo = [
+ 'BEGIN:VCALENDAR',
+ 'VERSION' + _version,
+ 'BEGIN:VTODO',
+ 'SUMMARY' + _summary,
+ 'DUE' + _dtEnd,
+ 'STATUS' + _status,
+ 'END:VTODO',
+ 'END:VCALENDAR'
+ ].join('\n');
+
+ if (this instanceof tizen.CalendarTask) {
+ return vTodo;
+ } else {
+ return vEven;
+ }
};
CalendarItem.prototype.convertToString = function() {
var types_ = validator_.Types;
var native_ = new xwalk.utils.NativeManager(extension);
+var isEarlierThan55 = utils_.isAppVersionEarlierThan('5.5');
+
var EditManager = function() {
- this.isAllowed = false;
+ this.isAllowed = false;
};
EditManager.prototype.allow = function() {
};
function ContentDirectory(data) {
- var id;
- var directoryURI;
- var title;
- var storageType;
- var modifiedDate = null;
-
- Object.defineProperties(this, {
- id: {
- get: function() {
- return id;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- id = converter_.toString(v, false);
- }
- },
- enumerable: true
- },
- directoryURI: {
- get: function() {
- return directoryURI;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- directoryURI = convertPathToUri_(converter_.toString(v, false));
- }
- },
- enumerable: true
- },
- title: {
- get: function() {
- return title;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- title = converter_.toString(v, false);
- }
- },
- enumerable: true
- },
- storageType: {
- get: function() {
- utils_.printDeprecationWarningFor('ContentDirectoryStorageType');
- return storageType;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- storageType = converter_.toEnum(v, Object.keys(ContentDirectoryStorageType), false);
- }
- },
- enumerable: true
- },
- modifiedDate: {
- get: function() {
- return modifiedDate;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- modifiedDate = v > 0 ? new Date(v * 1000) : null;
- }
- },
- enumerable: true
- }
- });
-
- if (type_.isObject(data)) {
- // fill object with data
- edit_.allow();
- for (var key in data) {
- if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
- this[key] = data[key];
- }
+ var id;
+ var directoryURI;
+ var title;
+ var storageType;
+ var modifiedDate = null;
+
+ Object.defineProperties(this, {
+ id: {
+ get: function() {
+ return id;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ id = converter_.toString(v, false);
+ }
+ },
+ enumerable: true
+ },
+ directoryURI: {
+ get: function() {
+ return directoryURI;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ directoryURI = convertPathToUri_(converter_.toString(v, false));
+ }
+ },
+ enumerable: true
+ },
+ title: {
+ get: function() {
+ return title;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ title = converter_.toString(v, false);
+ }
+ },
+ enumerable: true
+ },
+ storageType: {
+ get: function() {
++ utils_.printDeprecationWarningFor('ContentDirectoryStorageType');
+ return storageType;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ storageType = converter_.toEnum(
+ v,
+ Object.keys(ContentDirectoryStorageType),
+ false
+ );
+ }
+ },
+ enumerable: true
+ },
+ modifiedDate: {
+ get: function() {
+ return modifiedDate;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ modifiedDate = v > 0 ? new Date(v * 1000) : null;
+ }
+ },
+ enumerable: true
+ }
+ });
+
+ if (type_.isObject(data)) {
+ // fill object with data
+ edit_.allow();
+ for (var key in data) {
+ if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
+ this[key] = data[key];
+ }
+ }
+ edit_.disallow();
}
- edit_.disallow();
- }
}
-
function Content(data) {
- var editableAttributes = ['isFavorite'];
- // since 5.5 these attributes are readonly, it is disallowed to modify them,
- // but for applications developed for earlier versions backward compatibility
- // is kept
- if (isEarlierThan55) {
- editableAttributes.push('name');
- editableAttributes.push('rating');
- editableAttributes.push('description');
- }
- var id;
- var name;
- var type;
- var mimeType;
- var title;
- var contentURI;
- var thumbnailURIs = null;
- var releaseDate = null;
- var modifiedDate = null;
- var size;
- var description = null;
- var rating;
- var isFavorite;
-
- Object.defineProperties(this, {
- editableAttributes: {
- value: editableAttributes,
- writable: false,
- enumerable: true
- },
- id: {
- get: function() {
- return id;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- id = converter_.toString(v, false);
- }
- },
- enumerable: true
- },
- name: {
- get: function() {
- return name;
- },
- set: function(v) {
- // since 5.5 this attribute is readonly, it is disallowed to modify it,
- // but for applications developed for earlier versions backward compatibility
- // is kept
- if (isEarlierThan55 || edit_.isAllowed) {
- if (!type_.isNull(v)) {
- name = converter_.toString(v, false);
- }
- } else {
- utils_.warn('Since 5.5 "name" attribute is readonly, modifying it has no effect.');
- }
- },
- enumerable: true
- },
- type: {
- get: function() {
- return type;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- type = converter_.toEnum(v, Object.keys(ContentType), false);
- }
- },
- enumerable: true
- },
- mimeType: {
- get: function() {
- return mimeType;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- mimeType = converter_.toString(v, false);
- }
- },
- enumerable: true
- },
- title: {
- get: function() {
- return title;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- title = converter_.toString(v, false);
- }
- },
- enumerable: true
- },
- contentURI: {
- get: function() {
- return contentURI;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- contentURI = convertPathToUri_(v);
- }
- },
- enumerable: true
- },
- thumbnailURIs: {
- get: function() {
- return thumbnailURIs;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- thumbnailURIs = converter_.toArray(v, true);
- }
- },
- enumerable: true
- },
- releaseDate: {
- get: function() {
- return releaseDate;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- releaseDate = v > 0 ? new Date(v * 1000) : null;
- }
- },
- enumerable: true
- },
- modifiedDate: {
- get: function() {
- return modifiedDate;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- modifiedDate = v > 0 ? new Date(v * 1000) : null;
- }
- },
- enumerable: true
- },
- size: {
- get: function() {
- return size;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- size = converter_.toUnsignedLong(v, false);
- }
- },
- enumerable: true
- },
- description: {
- get: function() {
- return description;
- },
- set: function(v) {
- // since 5.5 this attribute is readonly, it is disallowed to modify it,
- // but for applications developed for earlier versions backward compatibility
- // is kept
- if (isEarlierThan55 || edit_.isAllowed) {
- description = converter_.toString(v, true);
- } else {
- utils_.warn('Since 5.5 "description" attribute is readonly, modifying it has no effect.');
- }
- },
- enumerable: true
- },
- rating: {
- get: function() {
- return rating;
- },
- set: function(v) {
- // since 5.5 this attribute is readonly, it is disallowed to modify it,
- // but for applications developed for earlier versions backward compatibility
- // is kept
- if (isEarlierThan55 || edit_.isAllowed) {
- if (!type_.isNull(v) && v >= 0 && v <= 10) {
- rating = converter_.toUnsignedLong(v, false);
- }
- } else {
- utils_.warn('Since 5.5 "rating" attribute is readonly, modifying it has no effect.');
- }
- },
- enumerable: true
- },
- isFavorite: {
- get: function() {
- return isFavorite;
- },
- set: function(v) {
- if (!type_.isNull(v)) {
- isFavorite = converter_.toBoolean(v, false);
- }
- },
- enumerable: true
- var editableAttributes = ['name', 'rating', 'description', 'isFavorite'];
++ var editableAttributes = ['isFavorite'];
++ // since 5.5 these attributes are readonly, it is disallowed to modify them,
++ // but for applications developed for earlier versions backward compatibility
++ // is kept
++ if (isEarlierThan55) {
++ editableAttributes.push('name');
++ editableAttributes.push('rating');
++ editableAttributes.push('description');
+ }
- });
-
- if (type_.isObject(data)) {
- // fill object with data
- edit_.allow();
- for (var key in data) {
- if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
- this[key] = data[key];
- }
+ var id;
+ var name;
+ var type;
+ var mimeType;
+ var title;
+ var contentURI;
+ var thumbnailURIs = null;
+ var releaseDate = null;
+ var modifiedDate = null;
+ var size;
+ var description = null;
+ var rating;
+ var isFavorite;
+
+ Object.defineProperties(this, {
+ editableAttributes: {
+ value: editableAttributes,
+ writable: false,
+ enumerable: true
+ },
+ id: {
+ get: function() {
+ return id;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ id = converter_.toString(v, false);
+ }
+ },
+ enumerable: true
+ },
+ name: {
+ get: function() {
+ return name;
+ },
+ set: function(v) {
- if (!type_.isNull(v)) {
- name = converter_.toString(v, false);
++ // since 5.5 this attribute is readonly, it is disallowed to modify it,
++ // but for applications developed for earlier versions backward
++ // compatibility is kept
++ if (isEarlierThan55 || edit_.isAllowed) {
++ if (!type_.isNull(v)) {
++ name = converter_.toString(v, false);
++ }
++ } else {
++ utils_.warn(
++ 'Since 5.5 "name" attribute is readonly, modifying it has no ' +
++ 'effect.'
++ );
+ }
+ },
+ enumerable: true
+ },
+ type: {
+ get: function() {
+ return type;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ type = converter_.toEnum(v, Object.keys(ContentType), false);
+ }
+ },
+ enumerable: true
+ },
+ mimeType: {
+ get: function() {
+ return mimeType;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ mimeType = converter_.toString(v, false);
+ }
+ },
+ enumerable: true
+ },
+ title: {
+ get: function() {
+ return title;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ title = converter_.toString(v, false);
+ }
+ },
+ enumerable: true
+ },
+ contentURI: {
+ get: function() {
+ return contentURI;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ contentURI = convertPathToUri_(v);
+ }
+ },
+ enumerable: true
+ },
+ thumbnailURIs: {
+ get: function() {
+ return thumbnailURIs;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ thumbnailURIs = converter_.toArray(v, true);
+ }
+ },
+ enumerable: true
+ },
+ releaseDate: {
+ get: function() {
+ return releaseDate;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ releaseDate = v > 0 ? new Date(v * 1000) : null;
+ }
+ },
+ enumerable: true
+ },
+ modifiedDate: {
+ get: function() {
+ return modifiedDate;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ modifiedDate = v > 0 ? new Date(v * 1000) : null;
+ }
+ },
+ enumerable: true
+ },
+ size: {
+ get: function() {
+ return size;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ size = converter_.toUnsignedLong(v, false);
+ }
+ },
+ enumerable: true
+ },
+ description: {
+ get: function() {
+ return description;
+ },
+ set: function(v) {
- description = converter_.toString(v, true);
++ // since 5.5 this attribute is readonly, it is disallowed to modify it,
++ // but for applications developed for earlier versions backward
++ // compatibility is kept
++ if (isEarlierThan55 || edit_.isAllowed) {
++ description = converter_.toString(v, true);
++ } else {
++ utils_.warn(
++ 'Since 5.5 "description" attribute is readonly, modifying it ' +
++ 'has no effect.'
++ );
++ }
+ },
+ enumerable: true
+ },
+ rating: {
+ get: function() {
+ return rating;
+ },
+ set: function(v) {
- if (!type_.isNull(v) && v >= 0 && v <= 10) {
- rating = converter_.toUnsignedLong(v, false);
++ // since 5.5 this attribute is readonly, it is disallowed to modify it,
++ // but for applications developed for earlier versions backward
++ // compatibility is kept
++ if (isEarlierThan55 || edit_.isAllowed) {
++ if (!type_.isNull(v) && v >= 0 && v <= 10) {
++ rating = converter_.toUnsignedLong(v, false);
++ }
++ } else {
++ utils_.warn(
++ 'Since 5.5 "rating" attribute is readonly, modifying it has no ' +
++ 'effect.'
++ );
+ }
+ },
+ enumerable: true
+ },
+ isFavorite: {
+ get: function() {
+ return isFavorite;
+ },
+ set: function(v) {
+ if (!type_.isNull(v)) {
+ isFavorite = converter_.toBoolean(v, false);
+ }
+ },
+ enumerable: true
+ }
+ });
+
+ if (type_.isObject(data)) {
+ // fill object with data
+ edit_.allow();
+ for (var key in data) {
+ if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
+ this[key] = data[key];
+ }
+ }
+ edit_.disallow();
}
- edit_.disallow();
- }
}
-
function VideoContent(data) {
- Content.call(this, data);
-
- var editableAttributes = this.editableAttributes;
- // since 5.5 this attribute is readonly, it is disallowed to modify it,
- // but for applications developed for earlier versions backward compatibility
- // is kept
- if (isEarlierThan55) {
- editableAttributes.push('geolocation');
- }
-
- var geolocation;
- var album;
- var artists;
- var duration;
- var width;
- var height;
+ Content.call(this, data);
+
+ var editableAttributes = this.editableAttributes;
- editableAttributes.push('geolocation');
++ // since 5.5 this attribute is readonly, it is disallowed to modify it,
++ // but for applications developed for earlier versions backward compatibility
++ // is kept
++ if (isEarlierThan55) {
++ editableAttributes.push('geolocation');
++ }
+
+ var geolocation;
+ var album;
+ var artists;
+ var duration;
+ var width;
+ var height;
Object.defineProperties(this, {
- editableAttributes: {
- value: editableAttributes,
- writable: false,
- enumerable: true
- },
- geolocation: {
- get: function() {
- if (isEarlierThan55) {
- return geolocation;
- } else {
- // for keep geolocation's latitude and longitude readonly
- // we need to return copy of this object
- return new tizen.SimpleCoordinates(geolocation.latitude, geolocation.longitude);
- }
- },
- set: function(v) {
- // since 5.5 this attribute is readonly, it is disallowed to modify it,
- // but for applications developed for earlier versions backward compatibility
- // is kept
- if (isEarlierThan55 || edit_.isAllowed) {
- if (!type_.isNull(v)) {
- var latitude = converter_.toDouble(v.latitude, false);
- var longitude = converter_.toDouble(v.longitude, false);
- geolocation = new tizen.SimpleCoordinates(latitude, longitude);
- }
- } else {
- utils_.warn('Since 5.5 "geolocation" attribute is readonly, modifying it has no effect.');
- }
- },
- enumerable: true
- },
- album: {
- get: function() {
- return album;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- album = converter_.toString(v, false);
- }
- },
- enumerable: true
- },
- artists: {
- get: function() {
- return artists;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- artists = converter_.toArray(v, true);
- }
- },
- enumerable: true
- },
- duration: {
- get: function() {
- return duration;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- duration = converter_.toUnsignedLong(v, false);
- }
- },
- enumerable: true
- },
- width: {
- get: function() {
- return width;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- width = converter_.toUnsignedLong(v, false);
- }
- },
- enumerable: true
- },
- height: {
- get: function() {
- return height;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- height = converter_.toUnsignedLong(v, false);
- }
- },
- enumerable: true
- }
- });
-
- if (type_.isObject(data)) {
- // fill object with data
- edit_.allow();
- for (var key in data) {
- if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
- this[key] = data[key];
- }
+ editableAttributes: {
+ value: editableAttributes,
+ writable: false,
+ enumerable: true
+ },
+ geolocation: {
+ get: function() {
- return geolocation;
++ if (isEarlierThan55) {
++ return geolocation;
++ } else {
++ // for keep geolocation's latitude and longitude readonly
++ // we need to return copy of this object
++ return new tizen.SimpleCoordinates(
++ geolocation.latitude,
++ geolocation.longitude
++ );
++ }
+ },
+ set: function(v) {
- if (!type_.isNull(v)) {
- var latitude = converter_.toDouble(v.latitude, false);
- var longitude = converter_.toDouble(v.longitude, false);
- geolocation = new tizen.SimpleCoordinates(latitude, longitude);
++ // since 5.5 this attribute is readonly, it is disallowed to modify it,
++ // but for applications developed for earlier versions backward
++ // compatibility is kept
++ if (isEarlierThan55 || edit_.isAllowed) {
++ if (!type_.isNull(v)) {
++ var latitude = converter_.toDouble(v.latitude, false);
++ var longitude = converter_.toDouble(v.longitude, false);
++ geolocation = new tizen.SimpleCoordinates(latitude, longitude);
++ }
++ } else {
++ utils_.warn(
++ 'Since 5.5 "geolocation" attribute is readonly, modifying it ' +
++ 'has no effect.'
++ );
+ }
+ },
+ enumerable: true
+ },
+ album: {
+ get: function() {
+ return album;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ album = converter_.toString(v, false);
+ }
+ },
+ enumerable: true
+ },
+ artists: {
+ get: function() {
+ return artists;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ artists = converter_.toArray(v, true);
+ }
+ },
+ enumerable: true
+ },
+ duration: {
+ get: function() {
+ return duration;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ duration = converter_.toUnsignedLong(v, false);
+ }
+ },
+ enumerable: true
+ },
+ width: {
+ get: function() {
+ return width;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ width = converter_.toUnsignedLong(v, false);
+ }
+ },
+ enumerable: true
+ },
+ height: {
+ get: function() {
+ return height;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ height = converter_.toUnsignedLong(v, false);
+ }
+ },
+ enumerable: true
+ }
+ });
+
+ if (type_.isObject(data)) {
+ // fill object with data
+ edit_.allow();
+ for (var key in data) {
+ if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
+ this[key] = data[key];
+ }
+ }
+ edit_.disallow();
}
- edit_.disallow();
- }
}
VideoContent.prototype = new Content();
AudioContent.prototype = new Content();
AudioContent.prototype.constructor = AudioContent;
-
function ImageContent(data) {
- Content.call(this, data);
-
- var editableAttributes = this.editableAttributes;
- // since 5.5 these attributes are readonly, it is disallowed to modify them,
- // but for applications developed for earlier versions backward compatibility
- // is kept
- if (isEarlierThan55) {
- editableAttributes.push('geolocation');
- editableAttributes.push('orientation');
- }
-
- var geolocation;
- var width;
- var height;
- var orientation;
-
- Object.defineProperties(this, {
- editableAttributes: {
- value: editableAttributes,
- writable: false,
- enumerable: true
- },
- geolocation: {
- get: function() {
- if (isEarlierThan55) {
- return geolocation;
- } else {
- // for keep geolocation's latitude and longitude readonly
- // we need to return copy of this object
- return new tizen.SimpleCoordinates(geolocation.latitude, geolocation.longitude);
- }
- },
- set: function(v) {
- // since 5.5 this attribute is readonly, it is disallowed to modify it,
- // but for applications developed for earlier versions backward compatibility
- // is kept
- if (isEarlierThan55 || edit_.isAllowed) {
- if (!type_.isNull(v)) {
- var latitude = converter_.toDouble(v.latitude, false);
- var longitude = converter_.toDouble(v.longitude, false);
- geolocation = new tizen.SimpleCoordinates(latitude, longitude);
- }
- } else {
- utils_.warn('Since 5.5 "geolocation" attribute is readonly, modifying it has no effect.');
- }
- },
- enumerable: true
- },
- width: {
- get: function() {
- return width;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- width = converter_.toUnsignedLong(v, false);
- }
- },
- enumerable: true
- },
- height: {
- get: function() {
- return height;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- height = converter_.toUnsignedLong(v, false);
- }
- },
- enumerable: true
- },
- orientation: {
- get: function() {
- return orientation;
- },
- set: function(v) {
- // since 5.5 this attribute is readonly, it is disallowed to modify it,
- // but for applications developed for earlier versions backward compatibility
- // is kept
- if (isEarlierThan55 || edit_.isAllowed) {
- if (!type_.isNull(v)) {
- orientation = converter_.toEnum(v, Object.keys(ImageContentOrientation), false);
- }
- } else {
- utils_.warn('Since 5.5 "orientation" attribute is readonly, modifying it has no effect.');
- }
- },
- enumerable: true
+ Content.call(this, data);
+
+ var editableAttributes = this.editableAttributes;
- editableAttributes.push('geolocation');
- editableAttributes.push('orientation');
++ // since 5.5 these attributes are readonly, it is disallowed to modify them,
++ // but for applications developed for earlier versions backward compatibility
++ // is kept
++ if (isEarlierThan55) {
++ editableAttributes.push('geolocation');
++ editableAttributes.push('orientation');
+ }
- });
-
- if (type_.isObject(data)) {
- // fill object with data
- edit_.allow();
- for (var key in data) {
- if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
- this[key] = data[key];
- }
+
+ var geolocation;
+ var width;
+ var height;
+ var orientation;
+
+ Object.defineProperties(this, {
+ editableAttributes: {
+ value: editableAttributes,
+ writable: false,
+ enumerable: true
+ },
+ geolocation: {
+ get: function() {
- return geolocation;
++ if (isEarlierThan55) {
++ return geolocation;
++ } else {
++ // for keep geolocation's latitude and longitude readonly
++ // we need to return copy of this object
++ return new tizen.SimpleCoordinates(
++ geolocation.latitude,
++ geolocation.longitude
++ );
++ }
+ },
+ set: function(v) {
- if (!type_.isNull(v)) {
- var latitude = converter_.toDouble(v.latitude, false);
- var longitude = converter_.toDouble(v.longitude, false);
- geolocation = new tizen.SimpleCoordinates(latitude, longitude);
++ // since 5.5 this attribute is readonly, it is disallowed to modify it,
++ // but for applications developed for earlier versions backward
++ // compatibility is kept
++ if (isEarlierThan55 || edit_.isAllowed) {
++ if (!type_.isNull(v)) {
++ var latitude = converter_.toDouble(v.latitude, false);
++ var longitude = converter_.toDouble(v.longitude, false);
++ geolocation = new tizen.SimpleCoordinates(latitude, longitude);
++ }
++ } else {
++ utils_.warn(
++ 'Since 5.5 "geolocation" attribute is readonly, modifying it ' +
++ 'has no effect.'
++ );
+ }
+ },
+ enumerable: true
+ },
+ width: {
+ get: function() {
+ return width;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ width = converter_.toUnsignedLong(v, false);
+ }
+ },
+ enumerable: true
+ },
+ height: {
+ get: function() {
+ return height;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ height = converter_.toUnsignedLong(v, false);
+ }
+ },
+ enumerable: true
+ },
+ orientation: {
+ get: function() {
+ return orientation;
+ },
+ set: function(v) {
- if (!type_.isNull(v)) {
- orientation = converter_.toEnum(
- v,
- Object.keys(ImageContentOrientation),
- false
++ // since 5.5 this attribute is readonly, it is disallowed to modify it,
++ // but for applications developed for earlier versions backward
++ // compatibility is kept
++ if (isEarlierThan55 || edit_.isAllowed) {
++ if (!type_.isNull(v)) {
++ orientation = converter_.toEnum(
++ v,
++ Object.keys(ImageContentOrientation),
++ false
++ );
++ }
++ } else {
++ utils_.warn(
++ 'Since 5.5 "orientation" attribute is readonly, modifying it ' +
++ 'has no effect.'
+ );
+ }
+ },
+ enumerable: true
+ }
+ });
+
+ if (type_.isObject(data)) {
+ // fill object with data
+ edit_.allow();
+ for (var key in data) {
+ if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
+ this[key] = data[key];
+ }
+ }
+ edit_.disallow();
}
- edit_.disallow();
- }
}
ImageContent.prototype = new Content();
* limitations under the License.
*/
function Playlist(data) {
- var id;
- var numberOfTracks;
-
- Object.defineProperties(this, {
- id: {
- get: function() {
- return id;
- },
- set: function(v) {
- if (edit_.isAllowed) {
- id = converter_.toString(v, false);
+ var id;
+ var numberOfTracks;
+
+ Object.defineProperties(this, {
+ id: {
+ get: function() {
+ return id;
+ },
+ set: function(v) {
+ if (edit_.isAllowed) {
+ id = converter_.toString(v, false);
+ }
+ },
+ enumerable: true
+ },
+ name: {
+ get: function() {
+ var result = native_.callSync('ContentPlaylist_getName', {
+ id: Number(id)
+ });
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ return native_.getResultObject(result);
+ },
+ set: function(v) {
+ if (!type_.isNull(v)) {
+ var name = converter_.toString(v, false);
+ var result = native_.callSync('ContentPlaylist_setName', {
+ id: Number(id),
+ name: name
+ });
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ },
+ enumerable: true
+ },
+ numberOfTracks: {
+ get: function() {
+ var result = native_.callSync('ContentPlaylist_getNumberOfTracks', {
+ id: Number(id)
+ });
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ return native_.getResultObject(result);
+ },
+ set: function() {},
+ enumerable: true
+ },
+ thumbnailURI: {
+ get: function() {
+ var result = native_.callSync('ContentPlaylist_getThumbnailUri', {
+ id: Number(id)
+ });
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ var res = native_.getResultObject(result);
- //CoreAPI not support empty thumbnail, so one space must be used instead
- //null thumbnail
++ //CoreAPI not support empty thumbnail, so one space must be used
++ // instead null thumbnail
+ return res === ' ' ? null : res;
+ },
+ set: function(v) {
+ var thumbnailURI = converter_.toString(v, true);
+ if (type_.isNullOrUndefined(thumbnailURI)) {
+ //CoreAPI not support empty thumbnail, so one space must be used
- //instead null thumbnail
++ // instead null thumbnail
+ thumbnailURI = ' ';
+ }
- //TODO probably thumbnailURI should be converted here to absolute uri
- //in case of virtual
++ //TODO probably thumbnailURI should be converted here to absolute
++ // uri in case of virtual
+ var result = native_.callSync('ContentPlaylist_setThumbnailUri', {
+ id: Number(id),
+ uri: thumbnailURI
+ });
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ },
+ enumerable: true
}
- },
- enumerable: true
- },
- name: {
- get: function() {
- var result = native_.callSync('ContentPlaylist_getName', {'id' : Number(id)});
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- return native_.getResultObject(result);
- },
- set: function(v) {
- if (!type_.isNull(v)) {
- var name = converter_.toString(v, false);
- var result = native_.callSync('ContentPlaylist_setName',
- {'id' : Number(id), 'name' : name});
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- }
- },
- enumerable: true
- },
- numberOfTracks: {
- get: function() {
- var result = native_.callSync('ContentPlaylist_getNumberOfTracks', {'id' : Number(id)});
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- return native_.getResultObject(result);
- },
- set: function() {},
- enumerable: true
- },
- thumbnailURI: {
- get: function() {
- var result = native_.callSync('ContentPlaylist_getThumbnailUri', {'id' : Number(id)});
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
+ });
+
+ if (type_.isObject(data)) {
+ // fill object with data
+ edit_.allow();
+ for (var key in data) {
+ if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
+ this[key] = data[key];
+ }
}
- var res = native_.getResultObject(result);
- //CoreAPI not support empty thumbnail, so one space must be used instead null thumbnail
- return res === " " ? null : res;
- },
- set: function(v) {
- var thumbnailURI = converter_.toString(v, true);
- if (type_.isNullOrUndefined(thumbnailURI)) {
- //CoreAPI not support empty thumbnail, so one space must be used instead null thumbnail
- thumbnailURI = " ";
- }
- //TODO probably thumbnailURI should be converted here to absolute uri in case of virtual
- var result = native_.callSync('ContentPlaylist_setThumbnailUri',
- {'id' : Number(id), 'uri' : thumbnailURI});
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- },
- enumerable: true
- },
- });
-
- if (type_.isObject(data)) {
- // fill object with data
- edit_.allow();
- for (var key in data) {
- if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
- this[key] = data[key];
- }
+ edit_.disallow();
}
- edit_.disallow();
- }
}
- Playlist.prototype.add = function (item) {
- var args = validator_.validateArgs(arguments, [
- {name: 'item', type: types_.PLATFORM_OBJECT, values: Content}
- ]);
+ Playlist.prototype.add = function(item) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'item', type: types_.PLATFORM_OBJECT, values: Content }
+ ]);
- var data = {
- contentId: args.item.id,
- playlistId: this.id,
- };
+ var data = {
+ contentId: args.item.id,
+ playlistId: this.id
+ };
- var result = native_.callSync('ContentPlaylist_add', data);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+ var result = native_.callSync('ContentPlaylist_add', data);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
};
- Playlist.prototype.addBatch = function (items, successCallback, errorCallback) {
- var args = validator_.validateArgs(arguments, [
- {name: 'items', type: types_.ARRAY, values: Content},
- {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true},
- {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
- ]);
+ Playlist.prototype.addBatch = function(items, successCallback, errorCallback) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'items', type: types_.ARRAY, values: Content },
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+ ]);
+
+ var data = {
+ playlistId: this.id,
+ contents: args.items
+ };
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ native_.callIfPossible(args.successCallback);
+ };
- var data = {
- playlistId: this.id,
- contents: args.items
- };
+ var result = native_.call('ContentPlaylist_addBatch', data, callback);
- 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 result = native_.call('ContentPlaylist_addBatch', data, callback);
-
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
};
- Playlist.prototype.remove = function (item) {
- var args = validator_.validateArgs(arguments, [
- {name: 'item', type: types_.PLATFORM_OBJECT, values: PlaylistItem}
- ]);
+ Playlist.prototype.remove = function(item) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'item', type: types_.PLATFORM_OBJECT, values: PlaylistItem }
+ ]);
- var data = {
- playlistId: this.id,
- memberId: args.item.content.memberId
- };
- var result = native_.callSync('ContentPlaylist_remove', data);
+ var data = {
+ playlistId: this.id,
+ memberId: args.item.content.memberId
+ };
+ var result = native_.callSync('ContentPlaylist_remove', data);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
};
- Playlist.prototype.removeBatch = function (items, successCallback, errorCallback) {
- var args = validator_.validateArgs(arguments, [
- {name: 'items', type: types_.ARRAY, values: PlaylistItem},
- {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true},
- {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
- ]);
+ Playlist.prototype.removeBatch = function(items, successCallback, errorCallback) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'items', type: types_.ARRAY, values: PlaylistItem },
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+ ]);
+
+ var members = [];
+ for (var i = 0; i < args.items.length; i++) {
+ members.push(args.items[i].content.memberId);
+ }
- var members = [];
- for (var i = 0; i < args.items.length; i++) {
- members.push(args.items[i].content.memberId);
- }
+ var data = {
+ playlistId: this.id,
+ members: members
+ };
- var data = {
- playlistId: this.id,
- members: members
- };
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ native_.callIfPossible(args.successCallback);
+ };
+
+ var result = native_.call('ContentPlaylist_removeBatch', data, callback);
- 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 result = native_.call('ContentPlaylist_removeBatch', data, callback);
+ Playlist.prototype.get = function(successCallback, errorCallback, count, offset) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'successCallback', type: types_.FUNCTION },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true },
+ { name: 'count', type: types_.LONG, optional: true },
+ { name: 'offset', type: types_.LONG, optional: true }
+ ]);
+
+ if (args.offset < 0 || args.count < 0) {
+ setTimeout(function() {
+ args.errorCallback(new WebAPIException(WebAPIException.INVALID_VALUES_ERR));
+ }, 0);
+ return;
+ }
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- };
+ var data = {
+ playlistId: this.id,
+ count: type_.isNullOrUndefined(args.count) ? -1 : args.count,
+ offset: type_.isNullOrUndefined(args.offset) ? -1 : args.offset
+ };
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ result = native_.getResultObject(result);
+ var out = [];
+ for (var i = 0, max = result.length; i < max; i++) {
+ var itemToPush = createContentObject_(result[i]);
+ itemToPush['memberId'] = result[i]['playlist_member_id'];
+ out.push(new PlaylistItem(itemToPush));
+ }
+ native_.callIfPossible(args.successCallback, out);
+ };
+
+ var result = native_.call('ContentPlaylist_get', data, callback);
- Playlist.prototype.get = function (successCallback, errorCallback, count, offset) {
- var args = validator_.validateArgs(arguments, [
- {name: 'successCallback', type: types_.FUNCTION},
- {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true},
- {name: 'count', type: types_.LONG, optional: true},
- {name: 'offset', type: types_.LONG, optional: true}
- ]);
-
- if (args.offset < 0 || args.count < 0) {
- setTimeout(function() {
- args.errorCallback(new WebAPIException(WebAPIException.INVALID_VALUES_ERR));
- }, 0);
- return;
- }
-
- var data = {
- playlistId: this.id,
- count: type_.isNullOrUndefined(args.count) ? -1 : args.count,
- offset: type_.isNullOrUndefined(args.offset) ? -1 : args.offset
- };
-
- var callback = function (result) {
if (native_.isFailure(result)) {
- native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
- return;
+ throw native_.getErrorObject(result);
}
- result = native_.getResultObject(result);
- var out = [];
- for (var i = 0, max = result.length; i < max; i++) {
- var itemToPush = createContentObject_(result[i]);
- itemToPush['memberId'] = result[i]['playlist_member_id'];
- out.push(new PlaylistItem(itemToPush));
+ };
+
+ Playlist.prototype.setOrder = function(items, successCallback, errorCallback) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'items', type: types_.ARRAY, values: PlaylistItem },
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+ ]);
+
+ if (!args.items.length) {
+ setTimeout(function() {
+ args.errorCallback(new WebAPIException(WebAPIException.INVALID_VALUES_ERR));
+ }, 0);
+ return;
}
- native_.callIfPossible(args.successCallback, out);
- };
- var result = native_.call('ContentPlaylist_get', data, callback);
+ var members = [];
+ for (var i = 0; i < args.items.length; i++) {
+ members.push(args.items[i].content.memberId);
+ }
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- };
+ var data = {
+ playlistId: this.id,
+ members: members
+ };
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ native_.callIfPossible(args.successCallback);
+ };
+
+ var result = native_.call('ContentPlaylist_setOrder', data, callback);
- Playlist.prototype.setOrder = function (items, successCallback, errorCallback) {
- var args = validator_.validateArgs(arguments, [
- {name: 'items', type: types_.ARRAY, values: PlaylistItem},
- {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true},
- {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
- ]);
-
- if (!args.items.length) {
- setTimeout(function() {
- args.errorCallback(new WebAPIException(WebAPIException.INVALID_VALUES_ERR));
- }, 0);
- return;
- }
-
- var members = [];
- for (var i = 0; i < args.items.length; i++) {
- members.push(args.items[i].content.memberId);
- }
-
- var data = {
- playlistId: this.id,
- members: members,
- };
-
- 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 result = native_.call('ContentPlaylist_setOrder', data, callback);
+ Playlist.prototype.move = function(item, delta, successCallback, errorCallback) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'item', type: types_.PLATFORM_OBJECT, values: PlaylistItem },
+ { name: 'delta', type: types_.LONG },
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+ ]);
+
+ var data = {
+ playlistId: this.id,
+ memberId: args.item.content.memberId,
+ delta: args.delta
+ };
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ native_.callIfPossible(args.successCallback);
+ };
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- };
+ var result = native_.call('ContentPlaylist_move', data, callback);
- Playlist.prototype.move = function (item, delta, successCallback, errorCallback) {
- var args = validator_.validateArgs(arguments, [
- {name: 'item', type: types_.PLATFORM_OBJECT, values: PlaylistItem},
- {name: 'delta', type: types_.LONG},
- {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true},
- {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
- ]);
-
- var data = {
- playlistId: this.id,
- memberId: args.item.content.memberId,
- delta: args.delta
- };
-
- 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 result = native_.call('ContentPlaylist_move', data, callback);
-
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
};
};
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});
+ 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;
- }
- }
+ 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;
+ _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;
+
+ 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 {
- privUtils_.log('Type invalid or listener was not added');
- return;
- }
- if (0 != _realWatchId) {
- native_.call('DataControlConsumerObject_removeChangeListener',{
- watchId: _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;
+ }
+ }
+ } 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');
++ privUtils_.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 stringToRegex(str) {
- var _regString = '^';
- if (str === '') {
- return new RegExp(_regString + "$", 'i');
- }
- // single '\' sign is not visible in JS string, escaping % wildcard need to be done by '\\%'
- str = str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
-
- var _percentTokens = str.split('%');
- var i;
- for (i = 0; i < _percentTokens.length - 1; ++i) {
- _regString = _regString + _percentTokens[i];
- if (_regString[_regString.length - 1] === '\\') {
- // special handling \\% sequence - '%' sign is threaten as regular sign - not wildcard
- _regString = _regString.split('');
- _regString.pop();
- _regString = _regString.join('') + '%';
- }
- else {
- // handling '%' as a wildcard
- _regString = _regString + '.*';
- }
- }
- return new RegExp(_regString + _percentTokens[i] + '$', 'i');
+ var _regString = '^';
+ if (str === '') {
+ return new RegExp(_regString + '$', 'i');
+ }
- // single '\' sign is not visible in JS string, escaping % wildcard need to
- // be done by '\\%'
++ // single '\' sign is not visible in JS string, escaping % wildcard
++ // need to be done by '\\%'
+ str = str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
+
+ var _percentTokens = str.split('%');
+ var i;
+ for (i = 0; i < _percentTokens.length - 1; ++i) {
+ _regString = _regString + _percentTokens[i];
+ if (_regString[_regString.length - 1] === '\\') {
+ // special handling \\% sequence - '%' sign is threaten as
+ // regular sign - not wildcard
+ _regString = _regString.split('');
+ _regString.pop();
+ _regString = _regString.join('') + '%';
+ } else {
+ // handling '%' as a wildcard
+ _regString = _regString + '.*';
+ }
+ }
+ return new RegExp(_regString + _percentTokens[i] + '$', 'i');
}
-
function createFilter(fileFilter) {
- if (type_.isNull(fileFilter)) {
- return null;
- }
-
- var FileFilter = {
- name: 'name',
- startModified: 'startModified',
- endModified: 'endModified',
- startCreated: 'startCreated',
- endCreated: 'endCreated'
- };
-
- var _fileFilter = {}, i;
- for (i in fileFilter) {
- if (!type_.isNullOrUndefined(fileFilter[i])) {
- if (Object.keys(FileFilter).indexOf(i) >= 0) {
- if (FileFilter.name === i) {
- _fileFilter[i] = stringToRegex(fileFilter[i]);
- } else {
- if (!(fileFilter[i] instanceof Date)) {
- throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR,
- 'Invalid date');
- }
- _fileFilter[i] = fileFilter[i];
+ if (type_.isNull(fileFilter)) {
+ return null;
+ }
+
+ var FileFilter = {
+ name: 'name',
+ startModified: 'startModified',
+ endModified: 'endModified',
+ startCreated: 'startCreated',
+ endCreated: 'endCreated'
+ };
+
+ var _fileFilter = {},
+ i;
+ for (i in fileFilter) {
+ if (!type_.isNullOrUndefined(fileFilter[i])) {
+ if (Object.keys(FileFilter).indexOf(i) >= 0) {
+ if (FileFilter.name === i) {
+ _fileFilter[i] = stringToRegex(fileFilter[i]);
+ } else {
+ if (!(fileFilter[i] instanceof Date)) {
+ throw new WebAPIException(
+ WebAPIException.INVALID_VALUES_ERR,
+ 'Invalid date'
+ );
+ }
+ _fileFilter[i] = fileFilter[i];
+ }
+ }
}
- }
}
- }
- return !type_.isEmptyObject(_fileFilter) ? _fileFilter : null;
+ return !type_.isEmptyObject(_fileFilter) ? _fileFilter : null;
}
function matchRange(value, min, max) {
};
function removeStorageStateChangeListener() {
- var args = validator_.validateArgs(arguments, [{name: 'watchId', type: types_.LONG}]);
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
- if (!arguments.length) {
- throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, 'Missing watchId');
- }
- var id = args.watchId;
+ if (!arguments.length) {
+ throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, 'Missing watchId');
+ }
+ var id = args.watchId;
- if (type_.isNullOrUndefined(callbacks[id])) {
- return;
- }
+ if (type_.isNullOrUndefined(callbacks[id])) {
- throw new WebAPIException(WebAPIException.NOT_FOUND_ERR, 'Watch ID not found.');
++ return;
+ }
- delete callbacks[id];
+ delete callbacks[id];
- if (type_.isEmptyObject(callbacks)) {
- var result =
- native_.callSync('FileSystemManager_removeStorageStateChangeListener', {});
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
+ if (type_.isEmptyObject(callbacks)) {
+ var result = native_.callSync(
+ 'FileSystemManager_removeStorageStateChangeListener',
+ {}
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
}
- }
}
FileSystemManager.prototype.removeStorageStateChangeListener = function() {
};
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) {
}
HumanActivityAccumulativePedometerData.prototype = new HumanActivityData();
- HumanActivityAccumulativePedometerData.prototype.constructor = HumanActivityAccumulativePedometerData;
-
+ // prettier-ignore
+ HumanActivityAccumulativePedometerData.prototype.constructor =
- HumanActivityAccumulativePedometerData;
++HumanActivityAccumulativePedometerData;
function HumanActivityHRMData(data) {
- SetReadOnlyProperty(this, 'heartRate', data.heartRate);
- SetReadOnlyProperty(this, 'rRInterval', data.rRInterval);
+ SetReadOnlyProperty(this, 'heartRate', data.heartRate);
+ SetReadOnlyProperty(this, 'rRInterval', data.rRInterval);
}
HumanActivityHRMData.prototype = new HumanActivityData();
}
HumanActivityRecorderPedometerData.prototype = new HumanActivityRecorderData();
- HumanActivityRecorderPedometerData.prototype.constructor = HumanActivityRecorderPedometerData;
+ // prettier-ignore
+ HumanActivityRecorderPedometerData.prototype.constructor =
- HumanActivityRecorderPedometerData;
++HumanActivityRecorderPedometerData;
function HumanActivityRecorderHRMData(data) {
- HumanActivityRecorderData.call(this, data);
- SetReadOnlyProperty(this, 'heartRate', data.heartRate);
+ HumanActivityRecorderData.call(this, data);
+ SetReadOnlyProperty(this, 'heartRate', data.heartRate);
}
HumanActivityRecorderHRMData.prototype = new HumanActivityRecorderData();
}
HumanActivityRecorderSleepMonitorData.prototype = new HumanActivityRecorderData();
- HumanActivityRecorderSleepMonitorData.prototype.constructor = HumanActivityRecorderSleepMonitorData;
+ // prettier-ignore
+ HumanActivityRecorderSleepMonitorData.prototype.constructor =
- HumanActivityRecorderSleepMonitorData;
++HumanActivityRecorderSleepMonitorData;
function HumanActivityRecorderPressureData(data) {
- HumanActivityRecorderData.call(this, data);
- SetReadOnlyProperty(this, 'max', data.max);
- SetReadOnlyProperty(this, 'min', data.min);
- SetReadOnlyProperty(this, 'average', data.average);
+ HumanActivityRecorderData.call(this, data);
+ SetReadOnlyProperty(this, 'max', data.max);
+ SetReadOnlyProperty(this, 'min', data.min);
+ SetReadOnlyProperty(this, 'average', data.average);
}
function GestureData(data) {
}
HumanActivityRecorderPressureData.prototype = new HumanActivityRecorderData();
- HumanActivityRecorderPressureData.prototype.constructor = HumanActivityRecorderPressureData;
+ // prettier-ignore
+ HumanActivityRecorderPressureData.prototype.constructor =
- HumanActivityRecorderPressureData;
++HumanActivityRecorderPressureData;
tizen.StressMonitorDataRange = StressMonitorDataRange;
var validator = xwalk.utils.validator;
var types = validator.Types;
var map = {
- "VolumeUp": {
- keyName: "XF86AudioRaiseVolume",
- keyCode: 175
- },
- "VolumeDown": {
- keyName: "XF86AudioLowerVolume",
- keyCode: 174
- },
+ VolumeUp: {
+ keyName: 'XF86AudioRaiseVolume',
+ keyCode: 175
+ },
+ VolumeDown: {
+ keyName: 'XF86AudioLowerVolume',
+ keyCode: 174
+ }
};
-
function InputDeviceKey(dict) {
- for (var key in dict) {
- if (dict.hasOwnProperty(key)) {
- Object.defineProperty(this, key, {
- value: dict[key],
- enumerable: true
- });
+ for (var key in dict) {
+ if (dict.hasOwnProperty(key)) {
+ Object.defineProperty(this, key, {
+ value: dict[key],
+ enumerable: true
+ });
+ }
}
- }
- Object.freeze(this);
+ Object.freeze(this);
}
-
/**
- * This class provides access to the API functionalities through the tizen.tvinputdevice interface.
- * This class provides access to the API functionalities through the
- * tizen.tvinputdevice interface.
++ * This class provides access to the API functionalities through
++ * the tizen.tvinputdevice interface.
* @constructor
*/
function InputDeviceManager() {
* @return {object} Key object
*/
InputDeviceManager.prototype.getKey = function(keyName) {
- var args = validator.validateArgs(arguments, [
- {name: 'keyName', type: types.STRING}
- ]);
-
- if (!map[args.keyName]) {
- throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR,
- 'Parameter "keyName" is invalid.');
- }
-
- return new InputDeviceKey( { name: args.keyName, code: map[args.keyName].keyCode } );
+ var args = validator.validateArgs(arguments, [
+ { name: 'keyName', type: types.STRING }
+ ]);
+
+ if (!map[args.keyName]) {
+ throw new WebAPIException(
+ WebAPIException.INVALID_VALUES_ERR,
+ 'Parameter "keyName" is invalid.'
+ );
+ }
+ return new InputDeviceKey({ name: args.keyName, code: map[args.keyName].keyCode });
};
-
/**
- * Registers an input device key to receive DOM keyboard event when it is pressed or released.
- * Registers an input device key to receive DOM keyboard event when it is pressed or
- * released.
++ * Registers an input device key to receive DOM keyboard event when
++ * it is pressed or released.
* @param {!string} keyName The key name
*/
InputDeviceManager.prototype.registerKey = function(keyName) {
}
ListenerManager.prototype.removeServerInfoListener = function(watchId) {
- this.removeListener(watchId);
- if (this.listenerIdToName.hasOwnProperty(watchId)) {
- var name = this.listenerIdToName[watchId];
- removeArrayElement(this.listenerNameToIds[name], watchId);
- delete this.listenerIdToName[watchId];
- }
+ this.removeListener(watchId);
+ if (this.listenerIdToName.hasOwnProperty(watchId)) {
+ var name = this.listenerIdToName[watchId];
+ removeArrayElement(this.listenerNameToIds[name], watchId);
+ delete this.listenerIdToName[watchId];
+ }
};
- var ServerCommandListener = new ListenerManager(native_, '_ServerCommandListener', function(msg, listener) {
- var data = undefined;
- data = listener(msg.clientName, msg.command, msg.data);
-
- if (type_.isUndefined(data)) {
- data = null;
- }
-
- var bundle;
- if (data instanceof tizen.Bundle) {
- bundle = data;
- } else {
- bundle = new tizen.Bundle(data);
- }
-
- var nativeData = {
- clientName: msg.clientName,
- requestId: msg.requestId,
- data: bundle
- };
-
- var result = native_.callSync('MediaControllerServer_replyCommand', nativeData);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- });
+ var ServerCommandListener = new ListenerManager(
+ native_,
+ '_ServerCommandListener',
+ function(msg, listener) {
+ var data = undefined;
+ data = listener(msg.clientName, msg.command, msg.data);
- var ReplyCommandListener = new ListenerManager(native_, '_ReplyCommandListener', function(msg, listener, watchId) {
- if (this.requestIdToListenerId[watchId] === msg.requestId) {
- listener(msg);
- this.removeListener(watchId);
- delete this.requestIdToListenerId[watchId];
- return true;
- }
- return false;
- });
+ if (type_.isUndefined(data)) {
+ data = null;
+ }
- var ServerPlaybackInfoListener = new ListenerManager(native_, '_ServerPlaybackInfoListener', function(msg, listener) {
- if (msg.action === 'onplaybackstaterequest') {
- native_.callIfPossible(listener[msg.action], msg.state, msg.clientName);
- }
- if (msg.action === 'onplaybackpositionrequest') {
- native_.callIfPossible(listener[msg.action], msg.position, msg.clientName);
- }
- if (msg.action === 'onshufflemoderequest') {
- native_.callIfPossible(listener[msg.action], msg.mode, msg.clientName);
- }
- if (msg.action === 'onrepeatmoderequest') {
- utils_.printDeprecationWarningFor('onrepeatmoderequest', 'onrepeatstaterequest');
- native_.callIfPossible(listener[msg.action], msg.mode, msg.clientName);
- }
- if (msg.action === 'onrepeatstaterequest') {
- native_.callIfPossible(listener[msg.action], msg.state, msg.clientName);
- }
- if (msg.action === 'onplaybackitemrequest') {
- native_.callIfPossible(listener[msg.action], msg.playlistName, msg.index, msg.state, msg.position, msg.clientName);
- }
++ var bundle;
++ if (data instanceof tizen.Bundle) {
++ bundle = data;
++ } else {
++ bundle = new tizen.Bundle(data);
++ }
+
- });
+ var nativeData = {
+ clientName: msg.clientName,
+ requestId: msg.requestId,
- data: data
++ data: bundle
+ };
- var ServerInfoStatusListener = new ListenerManager(native_, '_ServerInfoStatusListener', function(msg, listener) {
- listener(msg.state);
+ var result = native_.callSync('MediaControllerServer_replyCommand', nativeData);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ }
+ );
+
+ var ReplyCommandListener = new ListenerManager(native_, '_ReplyCommandListener', function(
+ msg,
+ listener,
+ watchId
+ ) {
+ if (this.requestIdToListenerId[watchId] === msg.requestId) {
+ listener(msg);
+ this.removeListener(watchId);
+ delete this.requestIdToListenerId[watchId];
+ return true;
+ }
+ return false;
});
- var ServerInfoPlaybackInfoListener = new ListenerManager(native_, '_ServerInfoPlaybackInfoListener', function(msg, listener) {
- if (msg.action === 'onplaybackchanged') {
- listener[msg.action](msg.state, msg.position);
- }
- if (msg.action === 'onshufflemodechanged') {
- listener[msg.action](msg.mode);
- }
- if (msg.action === 'onrepeatmodechanged') {
- utils_.printDeprecationWarningFor('onrepeatmodechanged', 'onrepeatstatechanged');
- listener[msg.action](msg.mode);
- }
- if (msg.action === 'onrepeatstatechanged') {
- listener[msg.action](msg.state);
- }
- if (msg.action === 'onmetadatachanged') {
- listener[msg.action](new MediaControllerMetadata(msg.metadata));
- }
- });
+ var ServerPlaybackInfoListener = new ListenerManager(
+ native_,
+ '_ServerPlaybackInfoListener',
+ function(msg, listener) {
+ if (msg.action === 'onplaybackstaterequest') {
- native_.callIfPossible(listener[msg.action], msg.state);
++ native_.callIfPossible(listener[msg.action], msg.state, msg.clientName);
+ }
+ if (msg.action === 'onplaybackpositionrequest') {
- native_.callIfPossible(listener[msg.action], msg.position);
++ native_.callIfPossible(listener[msg.action], msg.position, msg.clientName);
++ }
++ if (msg.action === 'onshufflemoderequest') {
++ native_.callIfPossible(listener[msg.action], msg.mode, msg.clientName);
++ }
++ if (msg.action === 'onrepeatmoderequest') {
++ utils_.printDeprecationWarningFor(
++ 'onrepeatmoderequest',
++ 'onrepeatstaterequest'
++ );
++ native_.callIfPossible(listener[msg.action], msg.mode, msg.clientName);
+ }
- if (
- msg.action === 'onshufflemoderequest' ||
- msg.action === 'onrepeatmoderequest'
- ) {
- native_.callIfPossible(listener[msg.action], msg.mode);
++ if (msg.action === 'onrepeatstaterequest') {
++ native_.callIfPossible(listener[msg.action], msg.state, msg.clientName);
++ }
++ if (msg.action === 'onplaybackitemrequest') {
++ native_.callIfPossible(
++ listener[msg.action],
++ msg.playlistName,
++ msg.index,
++ msg.state,
++ msg.position,
++ msg.clientName
++ );
+ }
+ }
+ );
- var ServerInfoPlaylistUpdatedListener = new ListenerManager(native_, '_ServerInfoPlaylistUpdatedListener', function(msg, listener) {
- if (msg.action === 'onplaylistupdated') {
- listener[msg.action](msg.serverName, new MediaControllerPlaylist(msg));
- }
- if (msg.action === 'onplaylistdeleted') {
- listener[msg.action](msg.serverName, msg.name);
- }
- });
+ var ServerInfoStatusListener = new ListenerManager(
+ native_,
+ '_ServerInfoStatusListener',
+ function(msg, listener) {
+ listener(msg.state);
+ }
+ );
+
+ var ServerInfoPlaybackInfoListener = new ListenerManager(
+ native_,
+ '_ServerInfoPlaybackInfoListener',
+ function(msg, listener) {
+ if (msg.action === 'onplaybackchanged') {
+ listener[msg.action](msg.state, msg.position);
+ }
- if (
- msg.action === 'onshufflemodechanged' ||
- msg.action === 'onrepeatmodechanged'
- ) {
++ if (msg.action === 'onshufflemodechanged') {
++ listener[msg.action](msg.mode);
++ }
++ if (msg.action === 'onrepeatmodechanged') {
++ utils_.printDeprecationWarningFor(
++ 'onrepeatmodechanged',
++ 'onrepeatstatechanged'
++ );
+ listener[msg.action](msg.mode);
+ }
++ if (msg.action === 'onrepeatstatechanged') {
++ listener[msg.action](msg.state);
++ }
+ if (msg.action === 'onmetadatachanged') {
+ listener[msg.action](new MediaControllerMetadata(msg.metadata));
+ }
+ }
+ );
+
++var ServerInfoPlaylistUpdatedListener = new ListenerManager(
++ native_,
++ '_ServerInfoPlaylistUpdatedListener',
++ function(msg, listener) {
++ if (msg.action === 'onplaylistupdated') {
++ listener[msg.action](msg.serverName, new MediaControllerPlaylist(msg));
++ }
++ if (msg.action === 'onplaylistdeleted') {
++ listener[msg.action](msg.serverName, msg.name);
++ }
++ }
++);
+
var EditManager = function() {
- this.isAllowed = false;
+ this.isAllowed = false;
};
EditManager.prototype.allow = function() {
};
var MediaControllerPlaybackState = {
- PLAY: 'PLAY',
- PAUSE: 'PAUSE',
- STOP: 'STOP',
- NEXT: 'NEXT',
- PREV: 'PREV',
- FORWARD: 'FORWARD',
- REWIND: 'REWIND'
+ PLAY: 'PLAY',
+ PAUSE: 'PAUSE',
+ STOP: 'STOP',
+ NEXT: 'NEXT',
+ PREV: 'PREV',
+ FORWARD: 'FORWARD',
+ REWIND: 'REWIND'
};
- REPEAT_OFF: "REPEAT_OFF",
- REPEAT_ONE: "REPEAT_ONE",
- REPEAT_ALL: "REPEAT_ALL"
+var MediaControllerRepeatState = {
- ALL: "ALL",
- ONE: "1",
- TWO: "2",
- THREE: "3",
- FOUR: "4",
- FIVE: "5",
- SIX: "6",
- SEVEN: "7",
- EIGHT: "8",
- NINE: "9",
- TEN: "10",
- ELEVEN: "11",
- TWELVE: "12",
- THIRTEEN: "13",
- FOURTEEN: "14",
- FIFTEEN: "15",
- SIXTEEN: "16",
- SEVENTEEN: "17",
- EIGHTEEN: "18",
- NINETEEN: "19"
++ REPEAT_OFF: 'REPEAT_OFF',
++ REPEAT_ONE: 'REPEAT_ONE',
++ REPEAT_ALL: 'REPEAT_ALL'
+};
+
+var MediaControllerContentAgeRating = {
++ ALL: 'ALL',
++ ONE: '1',
++ TWO: '2',
++ THREE: '3',
++ FOUR: '4',
++ FIVE: '5',
++ SIX: '6',
++ SEVEN: '7',
++ EIGHT: '8',
++ NINE: '9',
++ TEN: '10',
++ ELEVEN: '11',
++ TWELVE: '12',
++ THIRTEEN: '13',
++ FOURTEEN: '14',
++ FIFTEEN: '15',
++ SIXTEEN: '16',
++ SEVENTEEN: '17',
++ EIGHTEEN: '18',
++ NINETEEN: '19'
+};
+
var MediaControllerContentType = {
- IMAGE: "IMAGE",
- MUSIC: "MUSIC",
- VIDEO: "VIDEO",
- OTHER: "OTHER",
- UNDECIDED: "UNDECIDED"
+ IMAGE: 'IMAGE',
+ MUSIC: 'MUSIC',
+ VIDEO: 'VIDEO',
+ OTHER: 'OTHER',
+ UNDECIDED: 'UNDECIDED'
};
function MediaControllerManager() {}
};
var MediaControllerPlaybackInfo = function(data) {
- var _state = 'STOP';
- var _position = 0;
- var _shuffleMode = false;
- var _repeatMode = false;
- var _contentType = MediaControllerContentType.UNDECIDED;
- var _repeatState = MediaControllerRepeatState.REPEAT_OFF;
- var _ageRating = MediaControllerContentAgeRating.ALL;
- var _metadata = new MediaControllerMetadata();
- var _index = null;
- var _playlistName = null;
- Object.defineProperties(this, {
- state: {
- get: function() {
- return _state;
- },
- set: function(v) {
- _state = edit_.isAllowed && v ? v : _state;
- },
- enumerable: true
- },
- position: {
- get: function() {
- return _position;
- },
- set: function(v) {
- _position = edit_.isAllowed ? converter_.toLong(v) : _position;
- },
- enumerable: true
- },
- ageRating: {
- get: function() {
- return _ageRating;
+ var _state = 'STOP';
+ var _position = 0;
+ var _shuffleMode = false;
+ var _repeatMode = false;
++ var _contentType = MediaControllerContentType.UNDECIDED;
++ var _repeatState = MediaControllerRepeatState.REPEAT_OFF;
++ var _ageRating = MediaControllerContentAgeRating.ALL;
+ var _metadata = new MediaControllerMetadata();
++ var _index = null;
++ var _playlistName = null;
+ Object.defineProperties(this, {
+ state: {
+ get: function() {
+ return _state;
+ },
+ set: function(v) {
+ _state = edit_.isAllowed && v ? v : _state;
+ },
+ enumerable: true
},
- set: function(v) {
- _ageRating = edit_.isAllowed && v ? v : _ageRating;
+ position: {
+ get: function() {
+ return _position;
+ },
+ set: function(v) {
+ _position = edit_.isAllowed ? converter_.toLong(v) : _position;
+ },
+ enumerable: true
},
- enumerable: true
- },
- shuffleMode: {
- get: function() {
- return _shuffleMode;
- },
- set: function(v) {
- _shuffleMode = edit_.isAllowed ? converter_.toBoolean(v) : _shuffleMode;
- },
- enumerable: true
- },
- repeatMode: {
- get: function() {
- utils_.printDeprecationWarningFor('repeatMode', 'repeatState');
- return _repeatMode;
- },
- set: function(v) {
- _repeatMode = edit_.isAllowed ? converter_.toBoolean(v) : _repeatMode;
- },
- enumerable: true
- },
- repeatState: {
- get: function() {
- return _repeatState;
- },
- set: function(v) {
- _repeatState = edit_.isAllowed && v ? v : _repeatState;
- },
- enumerable: true
- },
- contentType: {
- get: function() {
- return _contentType;
- },
- set: function(v) {
- _contentType = edit_.isAllowed && v ? v : _contentType;
- },
- enumerable: true
- },
- metadata: {
- get: function() {
- return _metadata;
- },
- set: function(v) {
- _metadata = edit_.isAllowed && v ? new MediaControllerMetadata(v) : _metadata;
- },
- enumerable: true
- },
- index: {
- get: function() {
- return _index;
- },
- set: function(v) {
- _index = edit_.isAllowed && v ? v : _index;
- },
- enumerable: true
- },
- playlistName: {
- get: function() {
- return _playlistName;
- },
- set: function(v) {
- _playlistName = edit_.isAllowed && v ? v : _playlistName;
- },
- enumerable: true
- }
- });
++ ageRating: {
++ get: function() {
++ return _ageRating;
++ },
++ set: function(v) {
++ _ageRating = edit_.isAllowed && v ? v : _ageRating;
++ },
++ enumerable: true
++ },
+ shuffleMode: {
+ get: function() {
+ return _shuffleMode;
+ },
+ set: function(v) {
+ _shuffleMode = edit_.isAllowed ? converter_.toBoolean(v) : _shuffleMode;
+ },
+ enumerable: true
+ },
+ repeatMode: {
+ get: function() {
++ utils_.printDeprecationWarningFor('repeatMode', 'repeatState');
+ return _repeatMode;
+ },
+ set: function(v) {
+ _repeatMode = edit_.isAllowed ? converter_.toBoolean(v) : _repeatMode;
+ },
+ enumerable: true
+ },
++ repeatState: {
++ get: function() {
++ return _repeatState;
++ },
++ set: function(v) {
++ _repeatState = edit_.isAllowed && v ? v : _repeatState;
++ },
++ enumerable: true
++ },
++ contentType: {
++ get: function() {
++ return _contentType;
++ },
++ set: function(v) {
++ _contentType = edit_.isAllowed && v ? v : _contentType;
++ },
++ enumerable: true
++ },
+ metadata: {
+ get: function() {
+ return _metadata;
+ },
+ set: function(v) {
+ _metadata =
+ edit_.isAllowed && v ? new MediaControllerMetadata(v) : _metadata;
+ },
+ enumerable: true
++ },
++ index: {
++ get: function() {
++ return _index;
++ },
++ set: function(v) {
++ _index = edit_.isAllowed && v ? v : _index;
++ },
++ enumerable: true
++ },
++ playlistName: {
++ get: function() {
++ return _playlistName;
++ },
++ set: function(v) {
++ _playlistName = edit_.isAllowed && v ? v : _playlistName;
++ },
++ enumerable: true
+ }
+ });
- if (data instanceof _global.Object) {
- for (var prop in data) {
- if (data.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
- this[prop] = data[prop];
- }
+ if (data instanceof _global.Object) {
+ for (var prop in data) {
+ if (data.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
+ this[prop] = data[prop];
+ }
+ }
}
- }
};
function MediaControllerServer(data) {
- var _iconURI = null;
-
- Object.defineProperties(this, {
- playbackInfo: {
- value: new MediaControllerPlaybackInfo(data),
- writable: false,
- enumerable: true
- },
- iconURI: {
- get: function() {
- return _iconURI;
- },
- set: function(v) {
- _iconURI = edit_.isAllowed ? (v ? v : null) : _iconURI;
- },
- enumerable: true
- }
- });
++ var _iconURI = null;
++
+ Object.defineProperties(this, {
+ playbackInfo: {
+ value: new MediaControllerPlaybackInfo(data),
+ writable: false,
+ enumerable: true
++ },
++ iconURI: {
++ get: function() {
++ return _iconURI;
++ },
++ set: function(v) {
++ _iconURI = edit_.isAllowed ? (v ? v : null) : _iconURI;
++ },
++ enumerable: true
+ }
+ });
}
MediaControllerServer.prototype.updatePlaybackState = function(state) {
- var args = validator_.validateArgs(arguments, [
- {name: 'state', type: types_.ENUM, values: Object.keys(MediaControllerPlaybackState)}
- ]);
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'state',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerPlaybackState)
+ }
+ ]);
- var data = {
- state: args.state
- };
+ var data = {
+ state: args.state
+ };
- var result = native_.callSync('MediaControllerServer_updatePlaybackState', data);
+ var result = native_.callSync('MediaControllerServer_updatePlaybackState', data);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
- edit_.allow();
- this.playbackInfo.state = args.state;
- edit_.disallow();
+ edit_.allow();
+ this.playbackInfo.state = args.state;
+ edit_.disallow();
};
- var args = validator_.validateArgs(arguments, [
- {name: 'iconURI', type: types_.STRING, nullable: true}
- ]);
-
- var data = {
- iconURI: args.iconURI
- };
-
- var result = native_.callSync('MediaControllerServer_updateIconURI', data);
- if (native_.isFailure(result)) {
- throw new WebAPIException(WebAPIException.UNKNOWN_ERR, native_.getErrorObject(result).message);
- }
-
- edit_.allow();
- this.iconURI = args.iconURI;
- edit_.disallow();
+MediaControllerServer.prototype.updateIconURI = function(iconURI) {
++ var args = validator_.validateArgs(arguments, [
++ { name: 'iconURI', type: types_.STRING, nullable: true }
++ ]);
++
++ var data = {
++ iconURI: args.iconURI
++ };
++
++ var result = native_.callSync('MediaControllerServer_updateIconURI', data);
++ if (native_.isFailure(result)) {
++ throw new WebAPIException(
++ WebAPIException.UNKNOWN_ERR,
++ native_.getErrorObject(result).message
++ );
++ }
++
++ edit_.allow();
++ this.iconURI = args.iconURI;
++ edit_.disallow();
+};
+
MediaControllerServer.prototype.updatePlaybackPosition = function(position) {
- var args = validator_.validateArgs(arguments, [
- {name: 'position', type: types_.UNSIGNED_LONG_LONG}
- ]);
+ var args = validator_.validateArgs(arguments, [
+ { name: 'position', type: types_.UNSIGNED_LONG_LONG }
+ ]);
- var data = {
- position: args.position
- };
+ var data = {
+ position: args.position
+ };
- var result = native_.callSync('MediaControllerServer_updatePlaybackPosition', data);
+ var result = native_.callSync('MediaControllerServer_updatePlaybackPosition', data);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
- edit_.allow();
- this.playbackInfo.position = args.position;
- edit_.disallow();
+ edit_.allow();
+ this.playbackInfo.position = args.position;
+ edit_.disallow();
};
- {name: 'rating', type: types_.ENUM, values: Object.values(MediaControllerContentAgeRating)}
+MediaControllerServer.prototype.updatePlaybackAgeRating = function(rating) {
+ var args = validator_.validateArgs(arguments, [
- var args = validator_.validateArgs(arguments, [
- {name: 'contentType', type: types_.ENUM, values: Object.values(MediaControllerContentType)}
- ]);
-
- var data = {
- contentType: args.contentType
- };
-
- var result = native_.callSync('MediaControllerServer_updatePlaybackContentType', data);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
-
- edit_.allow();
- this.playbackInfo.contentType = args.contentType;
- edit_.disallow();
- }
++ {
++ name: 'rating',
++ type: types_.ENUM,
++ values: Object.values(MediaControllerContentAgeRating)
++ }
+ ]);
+
+ var data = {
+ rating: args.rating
+ };
+
+ var result = native_.callSync('MediaControllerServer_updatePlaybackAgeRating', data);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ edit_.allow();
+ this.playbackInfo.ageRating = args.rating;
+ edit_.disallow();
+};
+
+MediaControllerServer.prototype.updatePlaybackContentType = function(contentType) {
++ var args = validator_.validateArgs(arguments, [
++ {
++ name: 'contentType',
++ type: types_.ENUM,
++ values: Object.values(MediaControllerContentType)
++ }
++ ]);
++
++ var data = {
++ contentType: args.contentType
++ };
++
++ var result = native_.callSync(
++ 'MediaControllerServer_updatePlaybackContentType',
++ data
++ );
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
++
++ edit_.allow();
++ this.playbackInfo.contentType = args.contentType;
++ edit_.disallow();
++};
+
MediaControllerServer.prototype.updateShuffleMode = 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_updateShuffleMode', data);
+ var result = native_.callSync('MediaControllerServer_updateShuffleMode', data);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
- edit_.allow();
- this.playbackInfo.shuffleMode = args.mode;
- edit_.disallow();
+ edit_.allow();
+ this.playbackInfo.shuffleMode = args.mode;
+ edit_.disallow();
};
MediaControllerServer.prototype.updateRepeatMode = function(mode) {
- utils_.printDeprecationWarningFor('updateRepeatMode()', 'updateRepeatState()');
- var args = validator_.validateArgs(arguments, [
- {name: 'mode', type: types_.BOOLEAN}
- ]);
++ utils_.printDeprecationWarningFor('updateRepeatMode()', 'updateRepeatState()');
+ 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_updateRepeatMode', data);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
- edit_.allow();
- this.playbackInfo.repeatMode = args.mode;
- this.playbackInfo.repeatState = args.mode ? MediaControllerRepeatState.REPEAT_ALL : MediaControllerRepeatState.REPEAT_OFF;
- edit_.disallow();
+ edit_.allow();
+ this.playbackInfo.repeatMode = args.mode;
++ this.playbackInfo.repeatState = args.mode
++ ? MediaControllerRepeatState.REPEAT_ALL
++ : MediaControllerRepeatState.REPEAT_OFF;
++ edit_.disallow();
+};
+
+MediaControllerServer.prototype.updateRepeatState = function() {
- var args = validator_.validateArgs(arguments, [
- {name: 'state', type: types_.ENUM, values: Object.keys(MediaControllerRepeatState)}
- ]);
-
- var data = {
- state: args.state
- };
-
- var result = native_.callSync('MediaControllerServer_updateRepeatState', data);
-
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
-
- edit_.allow();
- this.playbackInfo.repeatState = args.state;
- if (MediaControllerRepeatState.REPEAT_ONE !== args.state) {
- this.playbackInfo.repeatMode = args.state === MediaControllerRepeatState.REPEAT_ALL;
- }
- edit_.disallow();
++ var args = validator_.validateArgs(arguments, [
++ {
++ name: 'state',
++ type: types_.ENUM,
++ values: Object.keys(MediaControllerRepeatState)
++ }
++ ]);
++
++ var data = {
++ state: args.state
++ };
++
++ var result = native_.callSync('MediaControllerServer_updateRepeatState', data);
++
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
++
++ edit_.allow();
++ this.playbackInfo.repeatState = args.state;
++ if (MediaControllerRepeatState.REPEAT_ONE !== args.state) {
++ this.playbackInfo.repeatMode =
++ args.state === MediaControllerRepeatState.REPEAT_ALL;
++ }
+ edit_.disallow();
};
MediaControllerServer.prototype.updateMetadata = function(metadata) {
- var args = validator_.validateArgs(arguments, [
- {name: 'metadata', type: types_.PLATFORM_OBJECT, values: MediaControllerMetadata}
- ]);
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'metadata',
+ type: types_.PLATFORM_OBJECT,
+ values: MediaControllerMetadata
+ }
+ ]);
- var data = {
- metadata: args.metadata
- };
+ var data = {
+ metadata: args.metadata
+ };
- var result = native_.callSync('MediaControllerServer_updateMetadata', data);
+ var result = native_.callSync('MediaControllerServer_updateMetadata', data);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
- edit_.allow();
- this.playbackInfo.metadata = args.metadata;
- edit_.disallow();
+ 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',
- 'onrepeatstaterequest',
- 'onplaybackitemrequest'
- ]
- }]);
-
- if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) {
- var result = native_.callSync('MediaControllerServer_addChangeRequestPlaybackInfoListener', {
- listenerId: ServerPlaybackInfoListener.listenerName
- });
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
+ MediaControllerServer.prototype.addChangeRequestPlaybackInfoListener = function(
+ listener
+ ) {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'listener',
+ type: types_.LISTENER,
+ values: [
+ 'onplaybackstaterequest',
+ 'onplaybackpositionrequest',
+ 'onshufflemoderequest',
- 'onrepeatmoderequest'
++ 'onrepeatmoderequest',
++ 'onrepeatstaterequest',
++ 'onplaybackitemrequest'
+ ]
+ }
+ ]);
+
+ if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerServer_addChangeRequestPlaybackInfoListener',
+ {
+ listenerId: ServerPlaybackInfoListener.listenerName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
}
- }
- return ServerPlaybackInfoListener.addListener(args.listener);
+ return ServerPlaybackInfoListener.addListener(args.listener);
};
- MediaControllerServer.prototype.removeChangeRequestPlaybackInfoListener = function(watchId) {
- var args = validator_.validateArgs(arguments, [
- {name: 'watchId', type: types_.LONG}
- ]);
+ MediaControllerServer.prototype.removeChangeRequestPlaybackInfoListener = function(
+ watchId
+ ) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
- ServerPlaybackInfoListener.removeListener(args.watchId);
+ ServerPlaybackInfoListener.removeListener(args.watchId);
- if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) {
- native_.callSync('MediaControllerServer_removeCommandListener');
- }
+ if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) {
+ native_.callSync('MediaControllerServer_removeCommandListener');
+ }
};
MediaControllerServer.prototype.addCommandListener = function(listener) {
};
MediaControllerServer.prototype.removeCommandListener = function(watchId) {
- var args = validator_.validateArgs(arguments, [
- {name: 'watchId', type: types_.LONG}
- ]);
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
- ServerCommandListener.removeListener(args.watchId);
+ ServerCommandListener.removeListener(args.watchId);
- if (type_.isEmptyObject(ServerCommandListener.listeners)) {
- native_.callSync('MediaControllerServer_removeCommandListener');
- }
+ if (type_.isEmptyObject(ServerCommandListener.listeners)) {
+ native_.callSync('MediaControllerServer_removeCommandListener');
+ }
};
- var args = validator_.validateArgs(arguments, [
- {name: 'name', type: types_.STRING}
- ]);
+MediaControllerServer.prototype.createPlaylist = function(name) {
- var data = {
- name: args.name
- };
++ var args = validator_.validateArgs(arguments, [
++ { name: 'name', type: types_.STRING }
++ ]);
+
- var result = native_.callSync('MediaControllerServer_createPlaylist', data);
++ var data = {
++ name: args.name
++ };
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
++ var result = native_.callSync('MediaControllerServer_createPlaylist', data);
+
- return new MediaControllerPlaylist(native_.getResultObject(result));
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
+
- MediaControllerServer.prototype.savePlaylist = function(playlist, successCallback, errorCallback) {
- var args = validator_.validateArgs(arguments, [
- {name: 'playlist', type: types_.PLATFORM_OBJECT, values: MediaControllerPlaylist},
- {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true},
- {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
- ]);
++ return new MediaControllerPlaylist(native_.getResultObject(result));
+};
+
- var data = {
- name: args.playlist.name
- };
++MediaControllerServer.prototype.savePlaylist = function(
++ playlist,
++ successCallback,
++ errorCallback
++) {
++ var args = validator_.validateArgs(arguments, [
++ {
++ name: 'playlist',
++ type: types_.PLATFORM_OBJECT,
++ values: MediaControllerPlaylist
++ },
++ {
++ name: 'successCallback',
++ type: types_.FUNCTION,
++ optional: true,
++ nullable: true
++ },
++ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
++ ]);
++
++ var data = {
++ name: args.playlist.name
++ };
++
++ var callback = function(result) {
++ if (native_.isFailure(result)) {
++ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
++ return;
++ }
++ native_.callIfPossible(args.successCallback);
++ };
+
- var callback = function(result) {
++ var result = native_.call('MediaControllerServer_savePlaylist', data, callback);
+
- native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
- return;
+ if (native_.isFailure(result)) {
- native_.callIfPossible(args.successCallback);
- };
++ throw native_.getErrorObject(result);
+ }
- var result = native_.call('MediaControllerServer_savePlaylist', data, callback);
++};
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- };
++MediaControllerServer.prototype.deletePlaylist = function(
++ name,
++ successCallback,
++ errorCallback
++) {
++ var args = validator_.validateArgs(arguments, [
++ { name: 'name', type: types_.STRING },
++ {
++ name: 'successCallback',
++ type: types_.FUNCTION,
++ optional: true,
++ nullable: true
++ },
++ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
++ ]);
+
- MediaControllerServer.prototype.deletePlaylist = function(name, successCallback, errorCallback) {
- var args = validator_.validateArgs(arguments, [
- {name: 'name', type: types_.STRING},
- {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true},
- {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
- ]);
++ var data = {
++ name: args.name
++ };
+
- var data = {
- name: args.name
- };
++ var callback = function(result) {
++ if (native_.isFailure(result)) {
++ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
++ return;
++ }
++ native_.callIfPossible(args.successCallback);
++ };
+
- var callback = function(result) {
++ var result = native_.call('MediaControllerServer_deletePlaylist', data, callback);
+
- native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
- return;
+ if (native_.isFailure(result)) {
- native_.callIfPossible(args.successCallback);
- };
-
- var result = native_.call('MediaControllerServer_deletePlaylist', data, callback);
-
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
++ throw native_.getErrorObject(result);
+ }
- var args = validator_.validateArgs(arguments, [
- {name: 'playlistName', type: types_.STRING},
- {name: 'index', type: types_.STRING}
- ]);
-
- var data = {
- playlistName: args.playlistName,
- index: args.index
- };
-
- var result = native_.callSync('MediaControllerServer_updatePlaybackItem', data);
-
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
-
- edit_.allow();
- this.playbackInfo.index = args.index;
- this.playbackInfo.playlistName = args.playlistName;
- edit_.disallow();
- };
+};
+
+MediaControllerServer.prototype.updatePlaybackItem = function(playlistName, index) {
- MediaControllerServer.prototype.getAllPlaylists = function(successCallback, errorCallback) {
- var args = validator_.validateArgs(arguments, [
- {name: 'successCallback', type: types_.FUNCTION, optional: false, nullable: false},
- {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
- ]);
++ var args = validator_.validateArgs(arguments, [
++ { name: 'playlistName', type: types_.STRING },
++ { name: 'index', type: types_.STRING }
++ ]);
+
- var callback = function(result) {
++ var data = {
++ playlistName: args.playlistName,
++ index: args.index
++ };
++
++ var result = native_.callSync('MediaControllerServer_updatePlaybackItem', data);
+
- native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
- return;
+ if (native_.isFailure(result)) {
- var data = native_.getResultObject(result);
- var playlists = [];
++ throw native_.getErrorObject(result);
+ }
- for(var i = 0; i < data.length; i++) {
- playlists.push(new MediaControllerPlaylist(data[i]));
- }
+
- native_.callIfPossible(args.successCallback, playlists);
- };
++ edit_.allow();
++ this.playbackInfo.index = args.index;
++ this.playbackInfo.playlistName = args.playlistName;
++ edit_.disallow();
++};
+
- var result = native_.call('MediaControllerServer_getAllPlaylists', {}, callback);
++MediaControllerServer.prototype.getAllPlaylists = function(
++ successCallback,
++ errorCallback
++) {
++ var args = validator_.validateArgs(arguments, [
++ {
++ name: 'successCallback',
++ type: types_.FUNCTION,
++ optional: false,
++ nullable: false
++ },
++ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
++ ]);
+
- 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 data = native_.getResultObject(result);
++ var playlists = [];
+
- function MediaControllerClient() {}
++ for (var i = 0; i < data.length; i++) {
++ playlists.push(new MediaControllerPlaylist(data[i]));
++ }
+
- 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}
- ]);
++ native_.callIfPossible(args.successCallback, playlists);
++ };
+
- var callback = function(result) {
++ var result = native_.call('MediaControllerServer_getAllPlaylists', {}, callback);
+
- 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]));
+ if (native_.isFailure(result)) {
- native_.callIfPossible(args.successCallback, info);
- };
++ throw native_.getErrorObject(result);
+ }
++};
++
+ function MediaControllerClient() {}
+
+ 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 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('MediaControllerClient_findServers', {}, callback);
+ native_.call('MediaControllerClient_findServers', {}, callback);
};
MediaControllerClient.prototype.getLatestServerInfo = function() {
+ var result = native_.callSync('MediaControllerClient_getLatestServerInfo', {});
- var result = native_.callSync('MediaControllerClient_getLatestServerInfo', {});
-
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
- var serverInfo = native_.getResultObject(result);
- if (serverInfo) {
- if ('NONE' === serverInfo.state) {
- serverInfo.state = 'INACTIVE';
+ var serverInfo = native_.getResultObject(result);
+ if (serverInfo) {
+ if ('NONE' === serverInfo.state) {
+ serverInfo.state = 'INACTIVE';
+ }
+ serverInfo = new MediaControllerServerInfo(serverInfo);
}
- serverInfo = new MediaControllerServerInfo(serverInfo);
- }
- return serverInfo;
+ return serverInfo;
};
-
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
- },
- iconURI: {
- get: function() {
- var result = native_.callSync('MediaControllerServerInfo_getIconURI', {name: this.name});
- if (native_.isFailure(result)) {
- throw new native_.getErrorObject(result);
+ 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
++ },
++ iconURI: {
++ get: function() {
++ var result = native_.callSync('MediaControllerServerInfo_getIconURI', {
++ name: this.name
++ });
++ if (native_.isFailure(result)) {
++ throw new native_.getErrorObject(result);
++ }
++ var data = native_.getResultObject(result);
++ return data.iconURI;
++ }.bind(this),
++ set: function() {},
++ enumerable: true
}
- var data = native_.getResultObject(result);
- return data.iconURI;
- }.bind(this),
- set: function() {},
- enumerable: true
- }
- });
+ });
}
+ 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 }
+ ]);
- 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}
- ]);
-
- var data = {
- name: this.name,
- state: args.state
- };
+ 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);
- };
+ 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);
+ 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);
- }
+ 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 }
+ ]);
- var callback = function(result) {
- if (native_.isFailure(result)) {
- native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
- return;
+ if (args.position < 0) {
+ throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
}
- native_.callIfPossible(args.successCallback);
- };
- var data = {
- position: args.position,
- name: this.name
- };
+ 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,
+ name: this.name
+ };
- native_.call('MediaControllerServerInfo_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}
- ]);
+ 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 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_sendShuffleMode', data, callback);
+ var data = {
+ mode: args.mode,
+ name: this.name
+ };
+ native_.call('MediaControllerServerInfo_sendShuffleMode', data, callback);
};
- MediaControllerServerInfo.prototype.sendRepeatMode = function(mode, successCallback, errorCallback) {
- utils_.printDeprecationWarningFor('sendRepeatMode()', 'sendRepeatState()');
- 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}
- ]);
+ MediaControllerServerInfo.prototype.sendRepeatMode = function(
+ mode,
+ successCallback,
+ errorCallback
+ ) {
++ utils_.printDeprecationWarningFor('sendRepeatMode()', 'sendRepeatState()');
+ 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,
- name: this.name
- };
- native_.call('MediaControllerServerInfo_sendRepeatMode', data, callback);
+ 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);
};
- var args = validator_.validateArgs(arguments, [
- {name: 'state', type: types_.ENUM, values: Object.keys(MediaControllerRepeatState)},
- {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true},
- {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
- ]);
+MediaControllerServerInfo.prototype.sendRepeatState = function() {
- var callback = function(result) {
- if (native_.isFailure(result)) {
- native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
- return;
- }
- native_.callIfPossible(args.successCallback);
- };
-
- var data = {
- state: args.state,
- name: this.name
- };
- native_.call('MediaControllerServerInfo_sendRepeatState', data, callback);
++ var args = validator_.validateArgs(arguments, [
++ {
++ name: 'state',
++ type: types_.ENUM,
++ values: Object.keys(MediaControllerRepeatState)
++ },
++ {
++ name: 'successCallback',
++ type: types_.FUNCTION,
++ optional: true,
++ nullable: true
++ },
++ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
++ ]);
+
- 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 callback = function(result) {
++ if (native_.isFailure(result)) {
++ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
++ return;
++ }
++ native_.callIfPossible(args.successCallback);
++ };
++
++ var data = {
++ state: args.state,
++ name: this.name
++ };
++ native_.call('MediaControllerServerInfo_sendRepeatState', 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 callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ native_.callIfPossible(
+ args.successCallback,
+ native_.getResultObject(result).data
+ );
+ };
- var callback = function(result) {
- if (native_.isFailure(result)) {
- native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
- return;
++ var bundle;
++ if (args.data instanceof tizen.Bundle) {
++ bundle = args.data;
++ } else {
++ bundle = new tizen.Bundle(args.data);
+ }
- native_.callIfPossible(args.successCallback, native_.getResultObject(result).data);
- };
-
- var bundle;
- if (args.data instanceof tizen.Bundle) {
- bundle = args.data;
- } else {
- bundle = new tizen.Bundle(args.data);
- }
-
- var nativeData = {
- command: args.command,
- data: bundle,
- name: this.name,
- listenerId: ReplyCommandListener.listenerName
- };
-
- var replyListenerId = ReplyCommandListener.addListener(callback);
- var result = native_.callSync('MediaControllerServerInfo_sendCommand', nativeData);
-
- ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
++
+ var nativeData = {
+ command: args.command,
- data: args.data,
++ data: bundle,
+ name: this.name,
+ listenerId: ReplyCommandListener.listenerName
+ };
+
+ var replyListenerId = ReplyCommandListener.addListener(callback);
+ var result = native_.callSync('MediaControllerServerInfo_sendCommand', nativeData);
+
+ ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
};
MediaControllerServerInfo.prototype.addServerStatusChangeListener = function(listener) {
};
MediaControllerServerInfo.prototype.addPlaybackInfoChangeListener = function(listener) {
- var args = validator_.validateArgs(arguments, [{
- name: 'listener',
- type: types_.LISTENER,
- values: [
- 'onplaybackchanged',
- 'onshufflemodechanged',
- 'onrepeatmodechanged',
- 'onrepeatstatechanged',
- 'onmetadatachanged'
- ]
- }]);
-
- if (type_.isEmptyObject(ServerInfoPlaybackInfoListener.listeners)) {
- var result = native_.callSync(
- 'MediaControllerServerInfo_addPlaybackInfoChangeListener', {
- listenerId: ServerInfoPlaybackInfoListener.listenerName
- });
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'listener',
+ type: types_.LISTENER,
+ values: [
+ 'onplaybackchanged',
+ 'onshufflemodechanged',
+ 'onrepeatmodechanged',
++ 'onrepeatstatechanged',
+ 'onmetadatachanged'
+ ]
+ }
+ ]);
+
+ if (type_.isEmptyObject(ServerInfoPlaybackInfoListener.listeners)) {
+ var result = native_.callSync(
+ 'MediaControllerServerInfo_addPlaybackInfoChangeListener',
+ {
+ listenerId: ServerInfoPlaybackInfoListener.listenerName
+ }
+ );
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
}
- }
- return ServerInfoPlaybackInfoListener.addServerInfoListener(args.listener, this.name);
+ return ServerInfoPlaybackInfoListener.addServerInfoListener(args.listener, this.name);
};
MediaControllerServerInfo.prototype.removePlaybackInfoChangeListener = function(watchId) {
- var args = validator_.validateArgs(arguments, [
- {name: 'watchId', type: types_.LONG}
- ]);
+ var args = validator_.validateArgs(arguments, [
+ { name: 'watchId', type: types_.LONG }
+ ]);
- ServerInfoPlaybackInfoListener.removeServerInfoListener(args.watchId);
+ ServerInfoPlaybackInfoListener.removeServerInfoListener(args.watchId);
- if (type_.isEmptyObject(ServerInfoPlaybackInfoListener.listeners)) {
- native_.callSync('MediaControllerServerInfo_removePlaybackInfoChangeListener');
- }
+ if (type_.isEmptyObject(ServerInfoPlaybackInfoListener.listeners)) {
+ native_.callSync('MediaControllerServerInfo_removePlaybackInfoChangeListener');
+ }
};
- MediaControllerServerInfo.prototype.getAllPlaylists = function(successCallback, errorCallback) {
- var args = validator_.validateArgs(arguments, [
- {name: 'successCallback', type: types_.FUNCTION, optional: false, nullable: false},
- {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
- ]);
++MediaControllerServerInfo.prototype.getAllPlaylists = function(
++ successCallback,
++ errorCallback
++) {
++ var args = validator_.validateArgs(arguments, [
++ {
++ name: 'successCallback',
++ type: types_.FUNCTION,
++ optional: false,
++ nullable: false
++ },
++ { 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;
- }
- var data = native_.getResultObject(result);
- var playlists = [];
++ var callback = function(result) {
++ if (native_.isFailure(result)) {
++ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
++ return;
++ }
++ var data = native_.getResultObject(result);
++ var playlists = [];
++
++ for (var i = 0; i < data.length; i++) {
++ playlists.push(new MediaControllerPlaylist(data[i]));
++ }
++
++ native_.callIfPossible(args.successCallback, playlists);
++ };
+
- for(var i = 0; i < data.length; i++) {
- playlists.push(new MediaControllerPlaylist(data[i]));
++ var result = native_.call(
++ 'MediaControllerServerInfo_getAllPlaylists',
++ { name: this.name },
++ callback
++ );
++
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
+ }
++};
+
- native_.callIfPossible(args.successCallback, playlists);
- };
++MediaControllerServerInfo.prototype.sendPlaybackItem = function(
++ playlistName,
++ index,
++ state,
++ position
++) {
++ var args = validator_.validateArgs(arguments, [
++ { name: 'playlistName', type: types_.STRING },
++ { name: 'index', type: types_.STRING },
++ {
++ name: 'state',
++ type: types_.ENUM,
++ values: Object.keys(MediaControllerPlaybackState)
++ },
++ { name: 'position', type: types_.UNSIGNED_LONG_LONG }
++ ]);
+
- var result = native_.call('MediaControllerServerInfo_getAllPlaylists', {name:this.name}, callback);
++ var data = {
++ name: this.name,
++ playlistName: args.playlistName,
++ index: args.index,
++ state: args.state,
++ position: args.position
++ };
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- }
++ var result = native_.callSync('MediaControllerServerInfo_sendPlaybackItem', data);
+
- MediaControllerServerInfo.prototype.sendPlaybackItem = function(playlistName, index, state, position) {
- var args = validator_.validateArgs(arguments, [
- {name: 'playlistName', type: types_.STRING},
- {name: 'index', type: types_.STRING},
- {name: 'state', type: types_.ENUM, values: Object.keys(MediaControllerPlaybackState)},
- {name: 'position', type: types_.UNSIGNED_LONG_LONG}
- ]);
-
- var data = {
- name: this.name,
- playlistName: args.playlistName,
- index: args.index,
- state: args.state,
- position: args.position
- };
-
- var result = native_.callSync('MediaControllerServerInfo_sendPlaybackItem', data);
-
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
+};
+
+MediaControllerServerInfo.prototype.addPlaylistUpdatedListener = function(listener) {
- var args = validator_.validateArgs(arguments, [{
- name: 'listener',
- type: types_.LISTENER,
- values: [
- 'onplaylistupdated',
- 'onplaylistdeleted'
- ]
- }]);
-
- if (type_.isEmptyObject(ServerInfoPlaylistUpdatedListener.listeners)) {
- var result = native_.callSync(
- 'MediaControllerServerInfo_addPlaylistUpdatedListener', {
- listenerId: ServerInfoPlaylistUpdatedListener.listenerName
- });
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
++ var args = validator_.validateArgs(arguments, [
++ {
++ name: 'listener',
++ type: types_.LISTENER,
++ values: ['onplaylistupdated', 'onplaylistdeleted']
++ }
++ ]);
++
++ if (type_.isEmptyObject(ServerInfoPlaylistUpdatedListener.listeners)) {
++ var result = native_.callSync(
++ 'MediaControllerServerInfo_addPlaylistUpdatedListener',
++ {
++ listenerId: ServerInfoPlaylistUpdatedListener.listenerName
++ }
++ );
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
+ }
- }
+
- return ServerInfoPlaylistUpdatedListener.addListener(args.listener, this.name);
++ return ServerInfoPlaylistUpdatedListener.addListener(args.listener, this.name);
+};
+
+MediaControllerServerInfo.prototype.removePlaylistUpdatedListener = function(watchId) {
- var args = validator_.validateArgs(arguments, [
- {name: 'watchId', type: types_.LONG}
- ]);
++ var args = validator_.validateArgs(arguments, [
++ { name: 'watchId', type: types_.LONG }
++ ]);
+
- ServerInfoPlaylistUpdatedListener.removeListener(args.watchId);
++ ServerInfoPlaylistUpdatedListener.removeListener(args.watchId);
+
- if (type_.isEmptyObject(ServerInfoPlaylistUpdatedListener.listeners)) {
- var result = native_.callSync('MediaControllerServerInfo_removePlaylistUpdatedListener');
++ if (type_.isEmptyObject(ServerInfoPlaylistUpdatedListener.listeners)) {
++ var result = native_.callSync(
++ 'MediaControllerServerInfo_removePlaylistUpdatedListener'
++ );
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
+ }
- }
+};
+
+var MediaControllerPlaylistItem = function(data) {
- var _index = "";
- var _metadata = new MediaControllerMetadata();
- Object.defineProperties(this, {
- index: {
- get: function() {
- return _index;
- },
- set: function(v) {
- _index = edit_.isAllowed && v ? v : _index;
- },
- enumerable: true
- },
- metadata: {
- get: function() {
- return _metadata;
- },
- set: function(v) {
- _metadata = edit_.isAllowed && v ? new MediaControllerMetadata(v) : _metadata;
- },
- enumerable: true
- }
- });
-
- edit_.allow();
- if (data instanceof _global.Object) {
- for (var prop in data) {
- if (data.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
- this[prop] = data[prop];
- }
++ var _index = '';
++ var _metadata = new MediaControllerMetadata();
++ Object.defineProperties(this, {
++ index: {
++ get: function() {
++ return _index;
++ },
++ set: function(v) {
++ _index = edit_.isAllowed && v ? v : _index;
++ },
++ enumerable: true
++ },
++ metadata: {
++ get: function() {
++ return _metadata;
++ },
++ set: function(v) {
++ _metadata =
++ edit_.isAllowed && v ? new MediaControllerMetadata(v) : _metadata;
++ },
++ enumerable: true
++ }
++ });
++
++ edit_.allow();
++ if (data instanceof _global.Object) {
++ for (var prop in data) {
++ if (data.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
++ this[prop] = data[prop];
++ }
++ }
+ }
- }
- edit_.disallow();
++ edit_.disallow();
+};
+
+function MediaControllerPlaylist(data) {
- var _name = "";
-
- Object.defineProperties(this, {
- name: {
- get: function() {
- return _name;
- },
- set: function(v) {
- _name = edit_.isAllowed && v ? v : _name;
- },
- enumerable: true
- }
- });
- edit_.allow();
- if (data instanceof _global.Object) {
- for (var prop in data) {
- if (data.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
- this[prop] = data[prop];
- }
++ var _name = '';
++
++ Object.defineProperties(this, {
++ name: {
++ get: function() {
++ return _name;
++ },
++ set: function(v) {
++ _name = edit_.isAllowed && v ? v : _name;
++ },
++ enumerable: true
++ }
++ });
++ edit_.allow();
++ if (data instanceof _global.Object) {
++ for (var prop in data) {
++ if (data.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
++ this[prop] = data[prop];
++ }
++ }
+ }
- }
- edit_.disallow();
++ edit_.disallow();
+}
+
+MediaControllerPlaylist.prototype.addItem = function(index, metadata) {
- var args = validator_.validateArgs(arguments, [
- {name: 'index', type: types_.STRING},
- {name: 'metadata', type: types_.DICTIONARY}
- ]);
-
- var data = {
- index: args.index,
- metadata: args.metadata,
- name: this.name
- };
-
- var result = native_.callSync('MediaControllerPlaylist_addItem', data);
-
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- }
++ var args = validator_.validateArgs(arguments, [
++ { name: 'index', type: types_.STRING },
++ { name: 'metadata', type: types_.DICTIONARY }
++ ]);
+
- MediaControllerPlaylist.prototype.getItems = function(successCallback, errorCallback) {
- var args = validator_.validateArgs(arguments, [
- {name: 'successCallback', type: types_.FUNCTION, optional: false, nullable: false},
- {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
- ]);
++ var data = {
++ index: args.index,
++ metadata: args.metadata,
++ name: this.name
++ };
+
- var data = {
- name: this.name
- };
++ var result = native_.callSync('MediaControllerPlaylist_addItem', data);
+
- var callback = function(result) {
+ if (native_.isFailure(result)) {
- native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
- return;
++ throw native_.getErrorObject(result);
+ }
- var data = native_.getResultObject(result);
- var items = [];
++};
+
- for(var i = 0; i < data.length; i++) {
- items.push(new MediaControllerPlaylistItem(data[i]));
- }
++MediaControllerPlaylist.prototype.getItems = function(successCallback, errorCallback) {
++ var args = validator_.validateArgs(arguments, [
++ {
++ name: 'successCallback',
++ type: types_.FUNCTION,
++ optional: false,
++ nullable: false
++ },
++ { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
++ ]);
+
- native_.callIfPossible(args.successCallback, items);
- };
++ var data = {
++ name: this.name
++ };
+
- var result = native_.call('MediaControllerPlaylist_getItems', data, callback);
++ var callback = function(result) {
++ if (native_.isFailure(result)) {
++ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
++ return;
++ }
++ var data = native_.getResultObject(result);
++ var items = [];
+
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- }
++ for (var i = 0; i < data.length; i++) {
++ items.push(new MediaControllerPlaylistItem(data[i]));
++ }
++
++ native_.callIfPossible(args.successCallback, items);
++ };
++
++ var result = native_.call('MediaControllerPlaylist_getItems', data, callback);
++
++ if (native_.isFailure(result)) {
++ throw native_.getErrorObject(result);
++ }
++};
+
exports = new MediaControllerManager();
};
PushManager.prototype.disconnectService = function() {
- privUtils_.warn('DEPRECATION WARNING: disconnectService() is deprecated and will be removed from next release. Use disconnect() instead.');
- var ret = native.callSync('Push_disconnectService', {});
- if (native.isFailure(ret)) {
- throw native.getErrorObject(ret);
- }
- listener2_4 = undefined;
- native.removeListener(NOTIFICATION_LISTENER);
+ privUtils_.warn(
- 'DEPRECATION WARNING: disconnectService() is deprecated and will be removed ' +
++ 'DEPRECATION WARNING: disconnectService() is deprecated and will be removed' +
+ 'from next release. Use disconnect() instead.'
+ );
+ var ret = native.callSync('Push_disconnectService', {});
+ if (native.isFailure(ret)) {
+ throw native.getErrorObject(ret);
+ }
+ listener2_4 = undefined;
+ native.removeListener(NOTIFICATION_LISTENER);
};
PushManager.prototype.disconnect = function() {
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
- }
- ]);
++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)
- );
- };
++ _sensorListeners[this.sensorType].getData(
++ args.successCallback,
++ errorWrapper.bind(args)
++ );
+};
//// LinearAccelerationSensor
var LinearAccelerationSensor = function(data) {
//enumeration SystemInfoPropertyId ////////////////////////////////////////////////////
var SystemInfoPropertyId = {
- BATTERY : 'BATTERY',
- CPU : 'CPU',
- STORAGE : 'STORAGE',
- DISPLAY : 'DISPLAY',
- DEVICE_ORIENTATION : 'DEVICE_ORIENTATION',
- BUILD : 'BUILD',
- LOCALE : 'LOCALE',
- NETWORK : 'NETWORK',
- WIFI_NETWORK : 'WIFI_NETWORK',
- ETHERNET_NETWORK : 'ETHERNET_NETWORK',
- CELLULAR_NETWORK : 'CELLULAR_NETWORK',
- NET_PROXY_NETWORK : 'NET_PROXY_NETWORK',
- SIM : 'SIM',
- PERIPHERAL : 'PERIPHERAL',
- MEMORY : 'MEMORY',
- CAMERA_FLASH : 'CAMERA_FLASH',
- ADS : 'ADS',
- SERVICE_COUNTRY : 'SERVICE_COUNTRY'
+ BATTERY: 'BATTERY',
+ CPU: 'CPU',
+ STORAGE: 'STORAGE',
+ DISPLAY: 'DISPLAY',
+ DEVICE_ORIENTATION: 'DEVICE_ORIENTATION',
+ BUILD: 'BUILD',
+ LOCALE: 'LOCALE',
+ NETWORK: 'NETWORK',
+ WIFI_NETWORK: 'WIFI_NETWORK',
+ ETHERNET_NETWORK: 'ETHERNET_NETWORK',
+ CELLULAR_NETWORK: 'CELLULAR_NETWORK',
+ NET_PROXY_NETWORK: 'NET_PROXY_NETWORK',
+ SIM: 'SIM',
+ PERIPHERAL: 'PERIPHERAL',
+ MEMORY: 'MEMORY',
+ CAMERA_FLASH: 'CAMERA_FLASH',
- ADS: 'ADS'
++ ADS: 'ADS',
++ SERVICE_COUNTRY: 'SERVICE_COUNTRY'
};
var SystemInfoPropertyIdToFeature = {
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 ' +
++ 'DEPRECATION WARNING: SystemInfoStorageUnit.isRemoveable is ' +
+ 'deprecated and will be removed from next release. ' +
+ 'Use SystemInfoStorageUnit.isRemovable instead.'
+ );
return _isRemovable;
},
set: function() {}
});
}
- serviceCountry : {value: data.serviceCountry, writable: false, enumerable: true},
+function SystemInfoServiceCountry(data) {
+ Object.defineProperties(this, {
++ serviceCountry: { value: data.serviceCountry, writable: false, enumerable: true }
+ });
+}
+
SystemInfoCameraFlash.prototype.setBrightness = function(brightness) {
- var args = validator_.validateArgs(arguments, [
- {name: 'brightness', type: types_.DOUBLE}
- ]);
- if (args.brightness < 0 || args.brightness > 1)
- throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR,
- 'Value is not between 0 and 1');
- args.brightness = args.brightness * this.levels;
-
- var result = native_.callSync('SystemInfo_setBrightness', args);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- this.brightness = result;
+ var args = validator_.validateArgs(arguments, [
+ { name: 'brightness', type: types_.DOUBLE }
+ ]);
+ if (args.brightness < 0 || args.brightness > 1)
+ throw new WebAPIException(
+ WebAPIException.INVALID_VALUES_ERR,
+ 'Value is not between 0 and 1'
+ );
+ args.brightness = args.brightness * this.levels;
+
+ var result = native_.callSync('SystemInfo_setBrightness', args);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ this.brightness = result;
};
//class SystemInfo ////////////////////////////////////////////////////
/*
* 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.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:
*/
}
}
- function _systeminfoServiceCountryListenerCallback(eventObj) {
++function _systeminfoServiceCountryListenerCallback(eventObj) {
+ var property = _serviceCountryStr;
+ var callbacks = _propertyContainer[property].callbacks;
+
+ for (var watchId in callbacks) {
+ if (callbacks.hasOwnProperty(watchId)) {
+ var listener = callbacks[watchId];
- var propObj = !listener.isArrayType ?
- _createProperty(property, eventObj.result.array[0]) :
- _createPropertyArray(property, eventObj.result);
++ var propObj = !listener.isArrayType
++ ? _createProperty(property, eventObj.result.array[0])
++ : _createPropertyArray(property, eventObj.result);
+ callbacks[watchId].callback(propObj);
+ }
+ }
+}
+
var _propertyContainer = {
- 'BATTERY' : {
- callbacks : {},
- constructor : SystemInfoBattery,
- broadcastFunction : _systeminfoBatteryListenerCallback,
- signalLabel : 'SystemInfoBatteryChangeBroadcast'
- },
- 'CPU' : {
- callbacks : {},
- constructor : SystemInfoCpu,
- broadcastFunction : _systeminfoCpuListenerCallback,
- signalLabel : 'SystemInfoCpuChangeBroadcast'
- },
- 'STORAGE' : {
- callbacks : {},
- constructor : SystemInfoStorage,
- broadcastFunction : _systeminfoStorageListenerCallback,
- signalLabel : 'SystemInfoStorageChangeBroadcast'
- },
- 'DISPLAY' : {
- callbacks : {},
- constructor : SystemInfoDisplay,
- broadcastFunction : _systeminfoDisplayListenerCallback,
- signalLabel : 'SystemInfoDisplayChangeBroadcast'
- },
- 'DEVICE_ORIENTATION' : {
- callbacks : {},
- constructor : SystemInfoDeviceOrientation,
- broadcastFunction : _systeminfoDeviceOrientationListenerCallback,
- signalLabel : 'SystemInfoDeviceOrientationChangeBroadcast'
- },
- 'BUILD' : {
- callbacks : {}, //adding callbacks for build is not possible
- constructor : SystemInfoBuild,
- broadcastFunction : function(){},
- signalLabel : ''
- },
- 'LOCALE' : {
- callbacks : {},
- constructor : SystemInfoLocale,
- broadcastFunction : _systeminfoLocaleListenerCallback,
- signalLabel : 'SystemInfoLocaleChangeBroadcast'
- },
- 'NETWORK' : {
- callbacks : {},
- constructor : SystemInfoNetwork,
- broadcastFunction : _systeminfoNetworkListenerCallback,
- signalLabel : 'SystemInfoNetworkChangeBroadcast'
- },
- 'WIFI_NETWORK' : {
- callbacks : {},
- constructor : SystemInfoWifiNetwork,
- broadcastFunction : _systeminfoWifiNetworkListenerCallback,
- signalLabel : 'SystemInfoWifiNetworkChangeBroadcast'
- },
- 'ETHERNET_NETWORK' : {
- callbacks : {},
- constructor : SystemInfoEthernetNetwork,
- broadcastFunction : _systeminfoEthernetNetworkListenerCallback,
- signalLabel : 'SystemInfoEthernetNetworkChangeBroadcast'
- },
- 'CELLULAR_NETWORK' : {
- callbacks : {},
- constructor : SystemInfoCellularNetwork,
- broadcastFunction : _systeminfoCellularNetworkListenerCallback,
- signalLabel : 'SystemInfoCellularNetworkChangeBroadcast'
- },
- 'NET_PROXY_NETWORK' : {
- callbacks : {},
- constructor : SystemInfoNetProxyNetwork,
- broadcastFunction : _systeminfoNetProxyNetworkListenerCallback,
- signalLabel : 'SystemInfoNetProxyNetworkChangeBroadcast'
- },
- 'SIM' : {
- callbacks : {},
- constructor : SystemInfoSIM,
- broadcastFunction : _systeminfoSimListenerCallback,
- signalLabel : 'SystemInfoSimChangeBroadcast'
- },
- 'PERIPHERAL' : {
- callbacks : {},
- constructor : SystemInfoPeripheral,
- broadcastFunction : _systeminfoPeripheralListenerCallback,
- signalLabel : 'SystemInfoPeripheralChangeBroadcast'
- },
- 'MEMORY' : {
- callbacks : {},
- constructor : SystemInfoMemory,
- broadcastFunction : _systeminfoMemoryListenerCallback,
- signalLabel : 'SystemInfoMemoryChangeBroadcast'
- },
- 'CAMERA_FLASH' : {
- callbacks : {},
- constructor : SystemInfoCameraFlash,
- broadcastFunction : _systeminfoCameraFlashListenerCallback,
- signalLabel : 'SystemInfoCameraFlashChangeBroadcast'
- },
- 'ADS' : {
- callbacks : {}, //adding callbacks for ADS is not possible
- constructor : SystemInfoADS,
- broadcastFunction : function(){},
- signalLabel : ''
- },
- 'SERVICE_COUNTRY' : {
- callbacks : {},
- constructor : SystemInfoServiceCountry,
- broadcastFunction : _systeminfoServiceCountryListenerCallback,
- signalLabel : 'SystemInfoServiceCountryChangeBroadcast'
- }
+ BATTERY: {
+ callbacks: {},
+ constructor: SystemInfoBattery,
+ broadcastFunction: _systeminfoBatteryListenerCallback,
+ signalLabel: 'SystemInfoBatteryChangeBroadcast'
+ },
+ CPU: {
+ callbacks: {},
+ constructor: SystemInfoCpu,
+ broadcastFunction: _systeminfoCpuListenerCallback,
+ signalLabel: 'SystemInfoCpuChangeBroadcast'
+ },
+ STORAGE: {
+ callbacks: {},
+ constructor: SystemInfoStorage,
+ broadcastFunction: _systeminfoStorageListenerCallback,
+ signalLabel: 'SystemInfoStorageChangeBroadcast'
+ },
+ DISPLAY: {
+ callbacks: {},
+ constructor: SystemInfoDisplay,
+ broadcastFunction: _systeminfoDisplayListenerCallback,
+ signalLabel: 'SystemInfoDisplayChangeBroadcast'
+ },
+ DEVICE_ORIENTATION: {
+ callbacks: {},
+ constructor: SystemInfoDeviceOrientation,
+ broadcastFunction: _systeminfoDeviceOrientationListenerCallback,
+ signalLabel: 'SystemInfoDeviceOrientationChangeBroadcast'
+ },
+ BUILD: {
+ callbacks: {}, //adding callbacks for build is not possible
+ constructor: SystemInfoBuild,
+ broadcastFunction: function() {},
+ signalLabel: ''
+ },
+ LOCALE: {
+ callbacks: {},
+ constructor: SystemInfoLocale,
+ broadcastFunction: _systeminfoLocaleListenerCallback,
+ signalLabel: 'SystemInfoLocaleChangeBroadcast'
+ },
+ NETWORK: {
+ callbacks: {},
+ constructor: SystemInfoNetwork,
+ broadcastFunction: _systeminfoNetworkListenerCallback,
+ signalLabel: 'SystemInfoNetworkChangeBroadcast'
+ },
+ WIFI_NETWORK: {
+ callbacks: {},
+ constructor: SystemInfoWifiNetwork,
+ broadcastFunction: _systeminfoWifiNetworkListenerCallback,
+ signalLabel: 'SystemInfoWifiNetworkChangeBroadcast'
+ },
+ ETHERNET_NETWORK: {
+ callbacks: {},
+ constructor: SystemInfoEthernetNetwork,
+ broadcastFunction: _systeminfoEthernetNetworkListenerCallback,
+ signalLabel: 'SystemInfoEthernetNetworkChangeBroadcast'
+ },
+ CELLULAR_NETWORK: {
+ callbacks: {},
+ constructor: SystemInfoCellularNetwork,
+ broadcastFunction: _systeminfoCellularNetworkListenerCallback,
+ signalLabel: 'SystemInfoCellularNetworkChangeBroadcast'
+ },
+ NET_PROXY_NETWORK: {
+ callbacks: {},
+ constructor: SystemInfoNetProxyNetwork,
+ broadcastFunction: _systeminfoNetProxyNetworkListenerCallback,
+ signalLabel: 'SystemInfoNetProxyNetworkChangeBroadcast'
+ },
+ SIM: {
+ callbacks: {},
+ constructor: SystemInfoSIM,
+ broadcastFunction: _systeminfoSimListenerCallback,
+ signalLabel: 'SystemInfoSimChangeBroadcast'
+ },
+ PERIPHERAL: {
+ callbacks: {},
+ constructor: SystemInfoPeripheral,
+ broadcastFunction: _systeminfoPeripheralListenerCallback,
+ signalLabel: 'SystemInfoPeripheralChangeBroadcast'
+ },
+ MEMORY: {
+ callbacks: {},
+ constructor: SystemInfoMemory,
+ broadcastFunction: _systeminfoMemoryListenerCallback,
+ signalLabel: 'SystemInfoMemoryChangeBroadcast'
+ },
+ CAMERA_FLASH: {
+ callbacks: {},
+ constructor: SystemInfoCameraFlash,
+ broadcastFunction: _systeminfoCameraFlashListenerCallback,
+ signalLabel: 'SystemInfoCameraFlashChangeBroadcast'
+ },
+ ADS: {
+ callbacks: {}, //adding callbacks for ADS is not possible
+ constructor: SystemInfoADS,
+ broadcastFunction: function() {},
+ signalLabel: ''
++ },
++ SERVICE_COUNTRY: {
++ callbacks: {},
++ constructor: SystemInfoServiceCountry,
++ broadcastFunction: _systeminfoServiceCountryListenerCallback,
++ signalLabel: 'SystemInfoServiceCountryChangeBroadcast'
+ }
};
/// It common function to be called when listener would be triggered
--- /dev/null
- key5: [1,2,3],
- key6: [[1,2,3],[4,5,6]],
+function TestDefaultCtor() {
+ var bundle = new tizen.Bundle();
+ var counter = 0;
+ bundle.forEach(function(key, value, type) {
+ counter++;
+ });
+ assertEqual(0, counter, 'bundle should be empty');
+}
+
+function TestJsonCtor() {
+ var json = {
+ key1: 'value',
+ key2: ['value1', 'value2'],
+ key3: new Uint8Array([1, 2, 3]),
+ key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
- assertArrayEqual(bundle.data.key3, new Uint8Array([1,2,3]), 'invalid value of key3');
++ key5: [1, 2, 3],
++ key6: [[1, 2, 3], [4, 5, 6]],
+ key7: [],
+ key8: null,
+ key9: {}
+ };
+
+ var bundle = new tizen.Bundle(json);
+
+ assertEqual(bundle.data.key1, 'value', 'invalid value of key1');
+ assertArrayEqual(bundle.data.key2, ['value1', 'value2'], 'invalid value of key2');
- assertArrayEqual(bundle.data.key4[0], new Uint8Array([1,2,3]), 'invalud value of key4[0]');
- assertArrayEqual(bundle.data.key4[1], new Uint8Array([4,5,6]), 'invalud value of key4[1]');
- assertArrayEqual(bundle.data.key5, new Uint8Array([1,2,3]), 'invalid value of key5');
++ assertArrayEqual(
++ bundle.data.key3,
++ new Uint8Array([1, 2, 3]),
++ 'invalid value of key3'
++ );
+ assertEqual(bundle.data.key4.length, 2, 'not enough elements in key4');
- assertArrayEqual(bundle.data.key6[0], new Uint8Array([1,2,3]), 'invalud value of key6[0]');
- assertArrayEqual(bundle.data.key6[1], new Uint8Array([4,5,6]), 'invalud value of key6[1]');
++ assertArrayEqual(
++ bundle.data.key4[0],
++ new Uint8Array([1, 2, 3]),
++ 'invalud value of key4[0]'
++ );
++ assertArrayEqual(
++ bundle.data.key4[1],
++ new Uint8Array([4, 5, 6]),
++ 'invalud value of key4[1]'
++ );
++ assertArrayEqual(
++ bundle.data.key5,
++ new Uint8Array([1, 2, 3]),
++ 'invalid value of key5'
++ );
+ assertEqual(bundle.data.key6.length, 2, 'invalid length of key6');
- key6: [1,2,3],
- key7: [[1,2,3],[4,5,6]]
++ assertArrayEqual(
++ bundle.data.key6[0],
++ new Uint8Array([1, 2, 3]),
++ 'invalud value of key6[0]'
++ );
++ assertArrayEqual(
++ bundle.data.key6[1],
++ new Uint8Array([4, 5, 6]),
++ 'invalud value of key6[1]'
++ );
+ assertArrayEqual(bundle.data.key7, [], 'invalid value of key7');
+ assertEqual(bundle.data.key8, 'null', 'invalid value of key8');
+ assertEqual(bundle.data.key9, '[object Object]', 'invalid value of key9');
+}
+
+function TestSetter() {
+ var bundle = new tizen.Bundle();
+ bundle.set('string', 'hello, world');
+ assertEqual(bundle.data['string'], 'hello, world', 'invalid string value');
+
+ bundle.set('stringArray', ['hello', 'world']);
+ assertArrayEqual(
+ bundle.data['stringArray'],
+ ['hello', 'world'],
+ 'invalid string array value'
+ );
+
+ bundle.set('bytes', new Uint8Array([1, 2, 3, 4]));
+ assertArrayEqual(bundle.data['bytes'], [1, 2, 3, 4], 'invalid bytes value');
+
+ bundle.set('bytesArray', [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]);
+ assertEqual(bundle.data['bytesArray'].length, 2, 'wrong number of byte streams');
+ assertArrayEqual(bundle.data['bytesArray'][0], [1, 2, 3], 'wrong byte stream');
+ assertArrayEqual(bundle.data['bytesArray'][1], [4, 5, 6], 'wrong byte stream');
+
+ bundle.set('other', function() {});
+ assertEqual(
+ bundle.typeOf('other') == tizen.BundleValueType.STRING,
+ true,
+ 'other type should be converted to string'
+ );
+ assertEqual(bundle.data['other'], 'function () {}', 'invalid value for other type');
+
+ bundle.set('someKey', undefined);
+ assertEqual(bundle.data['someKey'], 'undefined');
+}
+
+function TestGetters() {
+ var json = {
+ key1: 'value',
+ key2: ['value1', 'value2'],
+ key3: new Uint8Array([1, 2, 3]),
+ key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]
+ };
+
+ var bundle = new tizen.Bundle(json);
+
+ var strVal = bundle.get('key1');
+ assertEqual(strVal, 'value', 'string getter returned invalid value');
+
+ var strArrVal = bundle.get('key2');
+ assertArrayEqual(
+ strArrVal,
+ ['value1', 'value2'],
+ 'string array getter returned invalid value'
+ );
+
+ var bytesVal = bundle.get('key3');
+ assertArrayEqual(bytesVal, [1, 2, 3], 'bytes getter returned invalid value');
+
+ var bytesArrVal = bundle.get('key4');
+ assertEqual(bytesArrVal.length, 2, 'wrong number of byte streams');
+ assertArrayEqual(bytesArrVal[0], [1, 2, 3], 'byte stream invalid');
+ assertArrayEqual(bytesArrVal[1], [4, 5, 6], 'byte stream invalid');
+
+ try {
+ var notVal = bundle.get('not-a-key');
+ assertEqual(true, false, 'expected exception was not thrown');
+ } catch (err) {
+ assertEqual(err.code, WebAPIException.NOT_FOUND_ERR, 'expected NOT_FOUND_ERR');
+ }
+}
+
+function TestTypeOf() {
+ var json = {
+ key1: 'value',
+ key2: ['value1', 'value2'],
+ key3: new Uint8Array([1, 2, 3]),
+ key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
+ key5: [],
- assertEqual(bundle.typeOf('key1'),tizen.BundleValueType.STRING,'expected STRING type');
- assertEqual(bundle.typeOf('key2'),tizen.BundleValueType.STRING_ARRAY,'expected STRING_ARRAY type');
- assertEqual(bundle.typeOf('key3'),tizen.BundleValueType.BYTES,'expected BYTES type');
- assertEqual(bundle.typeOf('key4'), tizen.BundleValueType.BYTES_ARRAY,'expected BYTES_ARRAY');
- assertEqual(bundle.typeOf('key5'), tizen.BundleValueType.STRING_ARRAY,'empty array should be treated like STRING_ARRAY');
- assertEqual(bundle.typeOf('key6'), tizen.BundleValueType.BYTES, 'expected BYTES type');
- assertEqual(bundle.typeOf('key7'), tizen.BundleValueType.BYTES_ARRAY, 'expected BYTES_ARRAY type');
++ key6: [1, 2, 3],
++ key7: [[1, 2, 3], [4, 5, 6]]
+ };
+
+ var bundle = new tizen.Bundle(json);
- var result = (new tizen.Bundle(json)).toJSON();
++ assertEqual(
++ bundle.typeOf('key1'),
++ tizen.BundleValueType.STRING,
++ 'expected STRING type'
++ );
++ assertEqual(
++ bundle.typeOf('key2'),
++ tizen.BundleValueType.STRING_ARRAY,
++ 'expected STRING_ARRAY type'
++ );
++ assertEqual(
++ bundle.typeOf('key3'),
++ tizen.BundleValueType.BYTES,
++ 'expected BYTES type'
++ );
++ assertEqual(
++ bundle.typeOf('key4'),
++ tizen.BundleValueType.BYTES_ARRAY,
++ 'expected BYTES_ARRAY'
++ );
++ assertEqual(
++ bundle.typeOf('key5'),
++ tizen.BundleValueType.STRING_ARRAY,
++ 'empty array should be treated like STRING_ARRAY'
++ );
++ assertEqual(
++ bundle.typeOf('key6'),
++ tizen.BundleValueType.BYTES,
++ 'expected BYTES type'
++ );
++ assertEqual(
++ bundle.typeOf('key7'),
++ tizen.BundleValueType.BYTES_ARRAY,
++ 'expected BYTES_ARRAY type'
++ );
+
+ try {
+ type = bundle.typeOf('notKey');
+ assertEqual(false, true, 'exception was not thrown');
+ } catch (err) {
+ assertEqual(
+ err.code,
+ WebAPIException.NOT_FOUND_ERR,
+ 'expected NOT_FOUND_ERR exception'
+ );
+ }
+}
+
+function TestForEach() {
+ var json = {
+ key1: 'value',
+ key2: ['value1', 'value2'],
+ key3: new Uint8Array([1, 2, 3]),
+ key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]
+ };
+
+ var bundle = new tizen.Bundle(json);
+ var assertions = {
+ key1: {
+ active: true,
+ check: function(key, value, type) {
+ assertEqual(value, 'value', 'invalid value for key ' + key);
+ assertEqual(type, tizen.BundleValueType.STRING, 'should be STRING');
+ }
+ },
+ key2: {
+ active: true,
+ check: function(key, value, type) {
+ assertArrayEqual(
+ value,
+ ['value1', 'value2'],
+ 'invalid value for key ' + key
+ );
+ assertEqual(
+ type,
+ tizen.BundleValueType.STRING_ARRAY,
+ 'should be STRING_ARRAY'
+ );
+ }
+ },
+ key3: {
+ active: true,
+ check: function(key, value, type) {
+ assertArrayEqual(value, [1, 2, 3], 'invalid byte stream');
+ assertEqual(type, tizen.BundleValueType.BYTES, 'should be BYTES');
+ }
+ },
+ key4: {
+ active: true,
+ check: function(key, value, type) {
+ assertEqual(value.length, 2, 'invalid number of byte streams');
+ assertArrayEqual(value[0], [1, 2, 3], 'invalid byte stream');
+ assertArrayEqual(value[1], [4, 5, 6], 'invalid byte stream');
+ assertEqual(type, tizen.BundleValueType.BYTES_ARRAY);
+ }
+ }
+ };
+
+ bundle.forEach(function(key, value, type) {
+ assertEqual(assertions[key].active, true, 'inactive assertion triggered');
+ assertions[key].check(key, value, type);
+ assertions[key].active = false;
+ });
+
+ for (var id in assertions) {
+ if (assertions.hasOwnProperty(id)) {
+ assertEqual(false, assertions[id].active, 'unused assertion with id ' + id);
+ }
+ }
+}
+
+function TestToJson() {
+ var json = {
+ key1: 'value',
+ key2: ['value1', 'value2'],
+ key3: new Uint8Array([1, 2, 3]),
+ key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]
+ };
+
- assertArrayEqual(json.key2, result.key2, 'key2 differs');
++ var result = new tizen.Bundle(json).toJSON();
+ assertEqual(json.key1, result.key1, 'key1 differs');
- key5: [1,2,3],
- key6: [[1,2,3],[4,5,6]]
++ assertArrayEqual(json.key2, result.key2, 'key2 differs');
+ assertEqual(true, Array.isArray(result.key3), 'key3 not an array');
+ assertEqual(result.key4.length, json.key4.length, 'key4 length differs');
+ assertEqual(true, Array.isArray(result.key4[0]), 'key4[0] element not an array');
+ assertEqual(true, Array.isArray(result.key4[1]), 'key4[1] element not an array');
+ assertArrayEqual(json.key4[0], result.key4[0], 'key4[0] differs');
+ assertArrayEqual(json.key4[1], result.key4[1], 'key4[1] differs');
+}
+
+function TestToString() {
+ var json = {
+ key1: 'value',
+ key2: ['value1', 'value2'],
+ key3: new Uint8Array([1, 2, 3]),
+ key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
- var expected = '{"key1":"value","key2":["value1","value2"],"key3":[1,2,3],"key4":[[1,2,3],[4,5,6]],"key5":[1,2,3],"key6":[[1,2,3],[4,5,6]]}'
++ key5: [1, 2, 3],
++ key6: [[1, 2, 3], [4, 5, 6]]
+ };
+ var bundle = new tizen.Bundle(json);
++ var expected =
++ '{"key1":"value","key2":["value1","value2"],"key3":[1,2,3],' +
++ '"key4":[[1,2,3],[4,5,6]],"key5":[1,2,3],"key6":[[1,2,3],[4,5,6]]}';
+
+ assertEqual(bundle.toString(), expected, 'string forms differ');
+}
+
+var testcases = [
+ TestDefaultCtor,
+ TestJsonCtor,
+ TestSetter,
+ TestGetters,
+ TestTypeOf,
+ TestForEach,
+ TestToJson,
+ TestToString
+];
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-/*eslint-disable */
++/* eslint-disable */
// Tizen API Specification:
-//https://developer.tizen.org/dev-guide/2.3.0/org.tizen.mobile.web.device.apireference/tizen/tizen.html
-/*eslint-enable */
+// https://developer.tizen.org/dev-guide/2.3.0/org.tizen.mobile.web.device.apireference/tizen/tizen.html
++/* eslint-enable */
// WebAPIException and WebAPIError definition moved to src/utils/utils_api.js
// for compliance reasons. You can find more info there.
* Represents a point (latitude and longitude) in the map coordinate system.
*/
exports.SimpleCoordinates = function(lat, lng) {
+ xwalk.utils.validator.isConstructorCall(this, exports.SimpleCoordinates);
- xwalk.utils.validator.isConstructorCall(this, exports.SimpleCoordinates);
-
- var latitude = 0;
- var longitude = 0;
+ var latitude = 0;
+ var longitude = 0;
- function latSetter(lat) {
- var tmp = Number(lat);
- if (!isNaN(tmp)) {
- if (tmp > 90) tmp = 90;
- else if (tmp < -90) tmp = -90;
+ function latSetter(lat) {
+ var tmp = Number(lat);
+ if (!isNaN(tmp)) {
+ if (tmp > 90) tmp = 90;
+ else if (tmp < -90) tmp = -90;
- latitude = tmp;
+ latitude = tmp;
+ }
}
- }
- latSetter(lat);
+ latSetter(lat);
- function lonSetter(lon) {
- var tmp = Number(lon);
- if (!isNaN(tmp)) {
- if (tmp > 180) tmp = 180;
- else if (tmp < -180) tmp = -180;
+ function lonSetter(lon) {
+ var tmp = Number(lon);
+ if (!isNaN(tmp)) {
+ if (tmp > 180) tmp = 180;
+ else if (tmp < -180) tmp = -180;
- longitude = tmp;
- }
- }
-
- lonSetter(lng);
-
- Object.defineProperties(this, {
- latitude: {
- enumerable: true, set: latSetter, get: function() {
- return latitude;
- }
- },
- longitude: {
- enumerable: true, set: lonSetter, get: function() {
- return longitude;
- }
+ longitude = tmp;
+ }
}
- });
+
+ lonSetter(lng);
+
+ Object.defineProperties(this, {
+ latitude: {
+ enumerable: true,
+ set: latSetter,
+ get: function() {
+ return latitude;
+ }
+ },
+ longitude: {
+ enumerable: true,
+ set: lonSetter,
+ get: function() {
+ return longitude;
+ }
+ }
+ });
};
exports.SimpleCoordinates.prototype.constructor = exports.SimpleCoordinates;
-
+
- if (xwalk.utils.type.isByteStream(value) ||
- xwalk.utils.type.isLegacyByteStream(value)) {
+function forEachOwnProperty(obj, callback) {
+ for (var prop in obj) {
+ if (obj.hasOwnProperty(prop)) {
+ callback(prop, obj[prop]);
+ }
+ }
+}
+
+var BundleValueType = {
+ STRING: 'STRING',
+ STRING_ARRAY: 'STRING_ARRAY',
+ BYTES: 'BYTES',
+ BYTES_ARRAY: 'BYTES_ARRAY'
+};
+exports.BundleValueType = BundleValueType;
+
+function getValueType(value) {
+ if (xwalk.utils.type.isString(value)) {
+ return BundleValueType.STRING;
+ }
+ if (xwalk.utils.type.isStringArray(value)) {
+ return BundleValueType.STRING_ARRAY;
+ }
- if (xwalk.utils.type.isByteStreamArray(value) ||
- xwalk.utils.type.isLegacyByteStreamArray(value)) {
++ if (
++ xwalk.utils.type.isByteStream(value) ||
++ xwalk.utils.type.isLegacyByteStream(value)
++ ) {
+ return BundleValueType.BYTES;
+ }
- this.data[key] = convertToBundleValue(value);
++ if (
++ xwalk.utils.type.isByteStreamArray(value) ||
++ xwalk.utils.type.isLegacyByteStreamArray(value)
++ ) {
+ return BundleValueType.BYTES_ARRAY;
+ }
+}
+
+exports.Bundle = function(json) {
+ xwalk.utils.validator.isConstructorCall(this, exports.Bundle);
+ this.data = {};
+
+ if (xwalk.utils.type.isObject(json)) {
+ forEachOwnProperty(
+ json,
+ function(key, value) {
+ this.set(key, value);
+ }.bind(this)
+ );
+ }
+};
+exports.Bundle.prototype.constructor = exports.Bundle;
+
+exports.Bundle.prototype.set = function(key, value) {
- case undefined:
++ this.data[key] = convertToBundleValue(value);
+};
+
+function convertToBundleValue(value) {
+ var converted = value;
+ switch (getValueType(value)) {
- case BundleValueType.BYTES:
++ case undefined:
+ converted = xwalk.utils.converter.toString(value);
+ break;
- case BundleValueType.BYTES_ARRAY:
++ case BundleValueType.BYTES:
+ converted = new Uint8Array(value);
+ break;
- value.forEach((function (stream) {
- converted.push(new Uint8Array(stream));
- }).bind(this));
++ case BundleValueType.BYTES_ARRAY:
+ converted = [];
- throw new WebAPIException(WebAPIException.NOT_FOUND_ERR);
++ value.forEach(
++ function(stream) {
++ converted.push(new Uint8Array(stream));
++ }.bind(this)
++ );
+ break;
+ }
+ return converted;
+}
+
+exports.Bundle.prototype.get = function(key) {
+ if (!this.data.hasOwnProperty(key)) {
+ throw new WebAPIException(WebAPIException.NOT_FOUND_ERR);
+ }
+ return this.data[key];
+};
+
+exports.Bundle.prototype.typeOf = function(key) {
+ if (!this.data.hasOwnProperty(key)) {
- json[key] = [].slice.call(value);
- }
- else if (type == BundleValueType.BYTES_ARRAY) {
- json[key] = [];
- value.forEach(function(stream) {
- json[key].push([].slice.call(stream));
- });
- }
- else {
- json[key] = value;
++ throw new WebAPIException(WebAPIException.NOT_FOUND_ERR);
+ }
+ return getValueType(this.data[key]);
+};
+
+exports.Bundle.prototype.forEach = function(callback) {
+ forEachOwnProperty(
+ this.data,
+ function(key, value) {
+ callback(key, value, this.typeOf(key));
+ }.bind(this)
+ );
+};
+
+exports.Bundle.prototype.toJSON = function() {
+ var json = {};
+ this.forEach(function(key, value, type) {
+ if (type == BundleValueType.BYTES) {
-
++ json[key] = [].slice.call(value);
++ } else if (type == BundleValueType.BYTES_ARRAY) {
++ json[key] = [];
++ value.forEach(function(stream) {
++ json[key].push([].slice.call(stream));
++ });
++ } else {
++ json[key] = value;
+ }
+ });
+ return json;
+};
+
+exports.Bundle.prototype.toString = function() {
+ return JSON.stringify(this);
+};
var validator = xwalk.utils.validator;
var types = validator.Types;
var mandatoryMap = {
- "ArrowLeft" : {
- keyName : "Left",
- keyCode : 37
- },
- "ArrowUp" : {
- keyName : "Up",
- keyCode : 38
- },
- "ArrowRight" : {
- keyName : "Right",
- keyCode : 39
- },
- "ArrowDown" : {
- keyName : "Down",
- keyCode : 40
- },
- "Enter" : {
- keyName : "Return",
- keyCode : 13
- },
- "Back" : {
- keyName : "XF86Back",
- keyCode : 10009
- },
+ ArrowLeft: {
+ keyName: 'Left',
+ keyCode: 37
+ },
+ ArrowUp: {
+ keyName: 'Up',
+ keyCode: 38
+ },
+ ArrowRight: {
+ keyName: 'Right',
+ keyCode: 39
+ },
+ ArrowDown: {
+ keyName: 'Down',
+ keyCode: 40
+ },
+ Enter: {
+ keyName: 'Return',
+ keyCode: 13
+ },
+ Back: {
+ keyName: 'XF86Back',
+ keyCode: 10009
+ }
};
var map = {
- "VolumeUp": {
- keyName: "XF86AudioRaiseVolume",
- keyCode: 447
- },
- "VolumeDown": {
- keyName: "XF86AudioLowerVolume",
- keyCode: 448
- },
- "VolumeMute": {
- keyName: "XF86AudioMute",
- keyCode: 449
- },
- "ChannelUp": {
- keyName: "XF86RaiseChannel",
- keyCode: 427
- },
- "ChannelDown": {
- keyName: "XF86LowerChannel",
- keyCode: 428
- },
- "ColorF0Red": {
- keyName: "XF86Red",
- keyCode: 403
- },
- "ColorF1Green": {
- keyName: "XF86Green",
- keyCode: 404
- },
- "ColorF2Yellow": {
- keyName: "XF86Yellow",
- keyCode: 405
- },
- "ColorF3Blue": {
- keyName: "XF86Blue",
- keyCode: 406
- },
- "Menu": {
- keyName: "XF86SysMenu",
- keyCode: 10133
- },
- "Tools": {
- keyName: "XF86SimpleMenu",
- keyCode: 10135
- },
- "Info": {
- keyName: "XF86Info",
- keyCode: 457
- },
- "Exit": {
- keyName: "XF86Exit",
- keyCode: 10182
- },
- "Search": {
- keyName: "XF86Search",
- keyCode: 10225
- },
- "Guide": {
- keyName: "XF86ChannelGuide",
- keyCode: 458
- },
- "MediaRewind": {
- keyName: "XF86AudioRewind",
- keyCode: 412
- },
- "MediaPause": {
- keyName: "XF86AudioPause",
- keyCode: 19
- },
- "MediaFastForward": {
- keyName: "XF86AudioNext",
- keyCode: 417
- },
- "MediaRecord": {
- keyName: "XF86AudioRecord",
- keyCode: 416
- },
- "MediaPlay": {
- keyName: "XF86AudioPlay",
- keyCode: 415
- },
- "MediaStop": {
- keyName: "XF86AudioStop",
- keyCode: 413
- },
- "MediaPlayPause": {
- keyName: "XF86PlayBack",
- keyCode: 10252
- },
- "MediaTrackPrevious": {
- keyName: "XF86PreviousChapter",
- keyCode: 10232
- },
- "MediaTrackNext": {
- keyName: "XF86NextChapter",
- keyCode: 10233
- },
- "Source": {
- keyName: "XF86Display",
- keyCode: 10072
- },
- "PictureSize": {
- keyName: "XF86PictureSize",
- keyCode: 10140
- },
- "PreviousChannel": {
- keyName: "XF86PreviousChannel",
- keyCode: 10190
- },
- "ChannelList": {
- keyName: "XF86ChannelList",
- keyCode: 10073
- },
- "E-Manual": {
- keyName: "XF86EManual",
- keyCode: 10146
- },
- "MTS": {
- keyName: "XF86MTS",
- keyCode: 10195
- },
- "3D": {
- keyName: "XF863D",
- keyCode: 10199
- },
- "Soccer": {
- keyName: "XF86SoccerMode",
- keyCode: 10228
- },
- "Caption": {
- keyName: "XF86Caption",
- keyCode: 10221
- },
- "Teletext": {
- keyName: "XF86TTXMIX",
- keyCode: 10200
- },
- "Extra": {
- keyName: "XF86ExtraApp",
- keyCode: 10253
- },
- "0": {
- keyName: "0",
- keyCode: 48
- },
- "1": {
- keyName: "1",
- keyCode: 49
- },
- "2": {
- keyName: "2",
- keyCode: 50
- },
- "3": {
- keyName: "3",
- keyCode: 51
- },
- "4": {
- keyName: "4",
- keyCode: 52
- },
- "5": {
- keyName: "5",
- keyCode: 53
- },
- "6": {
- keyName: "6",
- keyCode: 54
- },
- "7": {
- keyName: "7",
- keyCode: 55
- },
- "8": {
- keyName: "8",
- keyCode: 56
- },
- "9": {
- keyName: "9",
- keyCode: 57
- },
- "Minus": {
- keyName: "minus",
- keyCode: 189
- },
+ VolumeUp: {
+ keyName: 'XF86AudioRaiseVolume',
+ keyCode: 447
+ },
+ VolumeDown: {
+ keyName: 'XF86AudioLowerVolume',
+ keyCode: 448
+ },
+ VolumeMute: {
+ keyName: 'XF86AudioMute',
+ keyCode: 449
+ },
+ ChannelUp: {
+ keyName: 'XF86RaiseChannel',
+ keyCode: 427
+ },
+ ChannelDown: {
+ keyName: 'XF86LowerChannel',
+ keyCode: 428
+ },
+ ColorF0Red: {
+ keyName: 'XF86Red',
+ keyCode: 403
+ },
+ ColorF1Green: {
+ keyName: 'XF86Green',
+ keyCode: 404
+ },
+ ColorF2Yellow: {
+ keyName: 'XF86Yellow',
+ keyCode: 405
+ },
+ ColorF3Blue: {
+ keyName: 'XF86Blue',
+ keyCode: 406
+ },
+ Menu: {
+ keyName: 'XF86SysMenu',
+ keyCode: 10133
+ },
+ Tools: {
+ keyName: 'XF86SimpleMenu',
+ keyCode: 10135
+ },
+ Info: {
+ keyName: 'XF86Info',
+ keyCode: 457
+ },
+ Exit: {
+ keyName: 'XF86Exit',
+ keyCode: 10182
+ },
+ Search: {
+ keyName: 'XF86Search',
+ keyCode: 10225
+ },
+ Guide: {
+ keyName: 'XF86ChannelGuide',
+ keyCode: 458
+ },
+ MediaRewind: {
+ keyName: 'XF86AudioRewind',
+ keyCode: 412
+ },
+ MediaPause: {
+ keyName: 'XF86AudioPause',
+ keyCode: 19
+ },
+ MediaFastForward: {
+ keyName: 'XF86AudioNext',
+ keyCode: 417
+ },
+ MediaRecord: {
+ keyName: 'XF86AudioRecord',
+ keyCode: 416
+ },
+ MediaPlay: {
+ keyName: 'XF86AudioPlay',
+ keyCode: 415
+ },
+ MediaStop: {
+ keyName: 'XF86AudioStop',
+ keyCode: 413
+ },
+ MediaPlayPause: {
+ keyName: 'XF86PlayBack',
+ keyCode: 10252
+ },
+ MediaTrackPrevious: {
+ keyName: 'XF86PreviousChapter',
+ keyCode: 10232
+ },
+ MediaTrackNext: {
+ keyName: 'XF86NextChapter',
+ keyCode: 10233
+ },
+ Source: {
+ keyName: 'XF86Display',
+ keyCode: 10072
+ },
+ PictureSize: {
+ keyName: 'XF86PictureSize',
+ keyCode: 10140
+ },
+ PreviousChannel: {
+ keyName: 'XF86PreviousChannel',
+ keyCode: 10190
+ },
+ ChannelList: {
+ keyName: 'XF86ChannelList',
+ keyCode: 10073
+ },
+ 'E-Manual': {
+ keyName: 'XF86EManual',
+ keyCode: 10146
+ },
+ MTS: {
+ keyName: 'XF86MTS',
+ keyCode: 10195
+ },
+ '3D': {
+ keyName: 'XF863D',
+ keyCode: 10199
+ },
+ Soccer: {
+ keyName: 'XF86SoccerMode',
+ keyCode: 10228
+ },
+ Caption: {
+ keyName: 'XF86Caption',
+ keyCode: 10221
+ },
+ Teletext: {
+ keyName: 'XF86TTXMIX',
+ keyCode: 10200
+ },
+ Extra: {
+ keyName: 'XF86ExtraApp',
+ keyCode: 10253
+ },
+ '0': {
+ keyName: '0',
+ keyCode: 48
+ },
+ '1': {
+ keyName: '1',
+ keyCode: 49
+ },
+ '2': {
+ keyName: '2',
+ keyCode: 50
+ },
+ '3': {
+ keyName: '3',
+ keyCode: 51
+ },
+ '4': {
+ keyName: '4',
+ keyCode: 52
+ },
+ '5': {
+ keyName: '5',
+ keyCode: 53
+ },
+ '6': {
+ keyName: '6',
+ keyCode: 54
+ },
+ '7': {
+ keyName: '7',
+ keyCode: 55
+ },
+ '8': {
+ keyName: '8',
+ keyCode: 56
+ },
+ '9': {
+ keyName: '9',
+ keyCode: 57
+ },
+ Minus: {
+ keyName: 'minus',
+ keyCode: 189
+ }
};
-
function TVInputDeviceKey(dict) {
- for (var key in dict) {
- if (dict.hasOwnProperty(key)) {
- Object.defineProperty(this, key, {
- value: dict[key],
- enumerable: true
- });
+ for (var key in dict) {
+ if (dict.hasOwnProperty(key)) {
+ Object.defineProperty(this, key, {
+ value: dict[key],
+ enumerable: true
+ });
+ }
}
- }
- Object.freeze(this);
+ Object.freeze(this);
}
-
/**
- * This class provides access to the API functionalities through the tizen.tvinputdevice interface.
- * This class provides access to the API functionalities through
- * the tizen.tvinputdevice interface.
++ * This class provides access to the API functionalities through the
++ * tizen.tvinputdevice interface.
* @constructor
*/
function TVInputDeviceManager() {
* @deprecated Used only by validateArguments()
*/
var signature_to_type = {
- 'n': 'number',
- 'f': 'function',
- 'b': 'boolean',
- 's': 'string',
- 'o': 'object'
+ n: 'number',
+ f: 'function',
+ b: 'boolean',
+ s: 'string',
+ o: 'object'
};
-
+/**
+ * @brief CommonListenerManager constructor function.
+ * @param nativeMgr NativeManager handle.
+ * @param managerName Name which will be used as native listener name.
- * @param onIdNotFound Callback without arguments invoked when trying to remove not existing listener. If unspecified it is replaced by empty function.
++ * @param onIdNotFound Callback without arguments invoked when trying to remove not
++ * existing listener. If unspecified it is replaced by empty
++ * function.
+ */
+var CommonListenerManager = function(nativeMgr, managerName, onIdNotFound) {
- this.listeners = {}
- this.nextId = 1;
- this.numberOfListeners = 0;
- this.name = managerName;
- this.native = nativeMgr;
- this.hasNativeListener = false;
- if (onIdNotFound === undefined) {
- this.idNotFoundBehavior = function() {};
- } else {
- this.idNotFoundBehavior = onIdNotFound;
- }
- }
++ this.listeners = {};
++ this.nextId = 1;
++ this.numberOfListeners = 0;
++ this.name = managerName;
++ this.native = nativeMgr;
++ this.hasNativeListener = false;
++ if (onIdNotFound === undefined) {
++ this.idNotFoundBehavior = function() {};
++ } else {
++ this.idNotFoundBehavior = onIdNotFound;
++ }
++};
+
+/**
+ * @brief Callback for native listener, which invokes all existing listeners.
+ * @param msg native Arguments object for native listener callback.
+ */
+CommonListenerManager.prototype.onListenerCalled = function(msg) {
- for (var watchId in this.listeners) {
- if (this.listeners.hasOwnProperty(watchId)) {
- this.listeners[watchId](msg);
++ for (var watchId in this.listeners) {
++ if (this.listeners.hasOwnProperty(watchId)) {
++ this.listeners[watchId](msg);
++ }
+ }
- }
+};
+
+/**
+ * @brief Registers new listener.
+ * @param callback Callback function taking single argument.
+ * @retval integer listener id. Use it later to remove listener.
+ */
+CommonListenerManager.prototype.addListener = function(callback) {
- if (!this.hasNativeListener) {
- this.native.addListener(this.name, this.onListenerCalled.bind(this));
- this.hasNativeListener = true;
- }
- var id = this.nextId++;
- this.listeners[id] = callback;
- this.numberOfListeners++;
- return id;
- }
++ if (!this.hasNativeListener) {
++ this.native.addListener(this.name, this.onListenerCalled.bind(this));
++ this.hasNativeListener = true;
++ }
++ var id = this.nextId++;
++ this.listeners[id] = callback;
++ this.numberOfListeners++;
++ return id;
++};
+
+/**
+ * @brief Remove previously registered listener.
+ *
+ * If listener for given id is not found, onIdNotFound callback is invoked.
+ *
+ * @param watchId Listener id returned by addListener.
+ * @retval onIdNotFoundCallback return value.
+ */
+CommonListenerManager.prototype.removeListener = function(watchId) {
- if (this.listeners.hasOwnProperty(watchId)) {
- delete this.listeners[watchId];
- this.numberOfListeners--;
- if (this.numberOfListeners == 0) {
- this.native.removeListener(this.name);
- this.hasNativeListener = false;
- this.nextId = 1;
++ if (this.listeners.hasOwnProperty(watchId)) {
++ delete this.listeners[watchId];
++ this.numberOfListeners--;
++ if (this.numberOfListeners == 0) {
++ this.native.removeListener(this.name);
++ this.hasNativeListener = false;
++ this.nextId = 1;
++ }
++ } else {
++ return this.idNotFoundBehavior();
+ }
- } else {
- return this.idNotFoundBehavior();
- }
- }
++};
+
var DateConverter = function() {};
DateConverter.prototype.toTZDate = function(v, isAllDay) {
var _dateConverter = new DateConverter();
- ACCOUNT_READ: 'http://tizen.org/privilege/account.read',
- ACCOUNT_WRITE: 'http://tizen.org/privilege/account.write',
- ALARM: 'http://tizen.org/privilege/alarm.get',
- APPLICATION_INFO: 'http://tizen.org/privilege/application.info',
- APPLICATION_LAUNCH: 'http://tizen.org/privilege/application.launch',
- APPMANAGER_CERTIFICATE: 'http://tizen.org/privilege/appmanager.certificate',
- APPMANAGER_KILL: 'http://tizen.org/privilege/appmanager.kill',
- BLUETOOTH_ADMIN: 'http://tizen.org/privilege/bluetooth.admin',
- BLUETOOTH_GAP: 'http://tizen.org/privilege/bluetooth.gap',
- BLUETOOTH_HEALTH: 'http://tizen.org/privilege/bluetooth.health',
- BLUETOOTH_SPP: 'http://tizen.org/privilege/bluetooth.spp',
- BLUETOOTHMANAGER: 'http://tizen.org/privilege/bluetoothmanager',
- BLUETOOTH: 'http://tizen.org/privilege/bluetooth',
- BOOKMARK_READ: 'http://tizen.org/privilege/bookmark.read',
- BOOKMARK_WRITE: 'http://tizen.org/privilege/bookmark.write',
- CALENDAR_READ: 'http://tizen.org/privilege/calendar.read',
- CALENDAR_WRITE: 'http://tizen.org/privilege/calendar.write',
- CALLHISTORY_READ: 'http://tizen.org/privilege/callhistory.read',
- CALLHISTORY_WRITE: 'http://tizen.org/privilege/callhistory.write',
- CONTACT_READ: 'http://tizen.org/privilege/contact.read',
- CONTACT_WRITE: 'http://tizen.org/privilege/contact.write',
- CONTENT_READ: 'http://tizen.org/privilege/content.read',
- CONTENT_WRITE: 'http://tizen.org/privilege/content.write',
- DATACONTROL_CONSUMER: 'http://tizen.org/privilege/datacontrol.consumer',
- DATASYNC: 'http://tizen.org/privilege/datasync',
- DOWNLOAD: 'http://tizen.org/privilege/download',
- FILESYSTEM_READ: 'http://tizen.org/privilege/filesystem.read',
- FILESYSTEM_WRITE: 'http://tizen.org/privilege/filesystem.write',
- HAPTIC: 'http://tizen.org/privilege/haptic',
- HEALTHINFO: 'http://tizen.org/privilege/healthinfo',
- INTERNET: 'http://tizen.org/privilege/internet',
- LED: 'http://tizen.org/privilege/led',
- LOCATION: 'http://tizen.org/privilege/location',
- MEDIACONTROLLER_SERVER: 'http://tizen.org/privilege/mediacontroller.server',
- MEDIACONTROLLER_CLIENT: 'http://tizen.org/privilege/mediacontroller.client',
- MESSAGING_READ: 'http://tizen.org/privilege/messaging.read',
- MESSAGING_WRITE: 'http://tizen.org/privilege/messaging.write',
- NETWORKBEARERSELECTION: 'http://tizen.org/privilege/networkbearerselection',
- NFC_ADMIN: 'http://tizen.org/privilege/nfc.admin',
- NFC_CARDEMULATION: 'http://tizen.org/privilege/nfc.cardemulation',
- NFC_COMMON: 'http://tizen.org/privilege/nfc.common',
- NFC_P2P: 'http://tizen.org/privilege/nfc.p2p',
- NFC_TAG: 'http://tizen.org/privilege/nfc.tag',
- NOTIFICATION: 'http://tizen.org/privilege/notification',
- PACKAGE_INFO: 'http://tizen.org/privilege/packagemanager.info',
- PACKAGEMANAGER_INSTALL: 'http://tizen.org/privilege/packagemanager.install',
- POWER: 'http://tizen.org/privilege/power',
- PUSH: 'http://tizen.org/privilege/push',
- SECUREELEMENT: 'http://tizen.org/privilege/secureelement',
- SETTING_ADMIN: 'http://tizen.org/privilege/systemsettings.admin',
- SETTING: 'http://tizen.org/privilege/setting',
- SYSTEM: 'http://tizen.org/privilege/system',
- SYSTEMMANAGER: 'http://tizen.org/privilege/systemmanager',
- TELEPHONY: 'http://tizen.org/privilege/telephony',
- VOLUME_SET: 'http://tizen.org/privilege/volume.set',
- WEBSETTING: 'http://tizen.org/privilege/websetting',
- TV_INPUT_DEVICE: 'http://tizen.org/privilege/tv.inputdevice'
+/**
+ * Cynara(since tizen 3.0) only support native privilege.
+ * simply web privilege convert native privilege for checking access.
+ */
+var _privilege = {
++ ACCOUNT_READ: 'http://tizen.org/privilege/account.read',
++ ACCOUNT_WRITE: 'http://tizen.org/privilege/account.write',
++ ALARM: 'http://tizen.org/privilege/alarm.get',
++ APPLICATION_INFO: 'http://tizen.org/privilege/application.info',
++ APPLICATION_LAUNCH: 'http://tizen.org/privilege/application.launch',
++ APPMANAGER_CERTIFICATE: 'http://tizen.org/privilege/appmanager.certificate',
++ APPMANAGER_KILL: 'http://tizen.org/privilege/appmanager.kill',
++ BLUETOOTH_ADMIN: 'http://tizen.org/privilege/bluetooth.admin',
++ BLUETOOTH_GAP: 'http://tizen.org/privilege/bluetooth.gap',
++ BLUETOOTH_HEALTH: 'http://tizen.org/privilege/bluetooth.health',
++ BLUETOOTH_SPP: 'http://tizen.org/privilege/bluetooth.spp',
++ BLUETOOTHMANAGER: 'http://tizen.org/privilege/bluetoothmanager',
++ BLUETOOTH: 'http://tizen.org/privilege/bluetooth',
++ BOOKMARK_READ: 'http://tizen.org/privilege/bookmark.read',
++ BOOKMARK_WRITE: 'http://tizen.org/privilege/bookmark.write',
++ CALENDAR_READ: 'http://tizen.org/privilege/calendar.read',
++ CALENDAR_WRITE: 'http://tizen.org/privilege/calendar.write',
++ CALLHISTORY_READ: 'http://tizen.org/privilege/callhistory.read',
++ CALLHISTORY_WRITE: 'http://tizen.org/privilege/callhistory.write',
++ CONTACT_READ: 'http://tizen.org/privilege/contact.read',
++ CONTACT_WRITE: 'http://tizen.org/privilege/contact.write',
++ CONTENT_READ: 'http://tizen.org/privilege/content.read',
++ CONTENT_WRITE: 'http://tizen.org/privilege/content.write',
++ DATACONTROL_CONSUMER: 'http://tizen.org/privilege/datacontrol.consumer',
++ DATASYNC: 'http://tizen.org/privilege/datasync',
++ DOWNLOAD: 'http://tizen.org/privilege/download',
++ FILESYSTEM_READ: 'http://tizen.org/privilege/filesystem.read',
++ FILESYSTEM_WRITE: 'http://tizen.org/privilege/filesystem.write',
++ HAPTIC: 'http://tizen.org/privilege/haptic',
++ HEALTHINFO: 'http://tizen.org/privilege/healthinfo',
++ INTERNET: 'http://tizen.org/privilege/internet',
++ LED: 'http://tizen.org/privilege/led',
++ LOCATION: 'http://tizen.org/privilege/location',
++ MEDIACONTROLLER_SERVER: 'http://tizen.org/privilege/mediacontroller.server',
++ MEDIACONTROLLER_CLIENT: 'http://tizen.org/privilege/mediacontroller.client',
++ MESSAGING_READ: 'http://tizen.org/privilege/messaging.read',
++ MESSAGING_WRITE: 'http://tizen.org/privilege/messaging.write',
++ NETWORKBEARERSELECTION: 'http://tizen.org/privilege/networkbearerselection',
++ NFC_ADMIN: 'http://tizen.org/privilege/nfc.admin',
++ NFC_CARDEMULATION: 'http://tizen.org/privilege/nfc.cardemulation',
++ NFC_COMMON: 'http://tizen.org/privilege/nfc.common',
++ NFC_P2P: 'http://tizen.org/privilege/nfc.p2p',
++ NFC_TAG: 'http://tizen.org/privilege/nfc.tag',
++ NOTIFICATION: 'http://tizen.org/privilege/notification',
++ PACKAGE_INFO: 'http://tizen.org/privilege/packagemanager.info',
++ PACKAGEMANAGER_INSTALL: 'http://tizen.org/privilege/packagemanager.install',
++ POWER: 'http://tizen.org/privilege/power',
++ PUSH: 'http://tizen.org/privilege/push',
++ SECUREELEMENT: 'http://tizen.org/privilege/secureelement',
++ SETTING_ADMIN: 'http://tizen.org/privilege/systemsettings.admin',
++ SETTING: 'http://tizen.org/privilege/setting',
++ SYSTEM: 'http://tizen.org/privilege/system',
++ SYSTEMMANAGER: 'http://tizen.org/privilege/systemmanager',
++ TELEPHONY: 'http://tizen.org/privilege/telephony',
++ VOLUME_SET: 'http://tizen.org/privilege/volume.set',
++ WEBSETTING: 'http://tizen.org/privilege/websetting',
++ TV_INPUT_DEVICE: 'http://tizen.org/privilege/tv.inputdevice'
+};
+
+Object.freeze(_privilege);
+
/** @constructor */
function Utils() {
- Object.defineProperty(this, 'privilege', {
- value: _privilege,
- writable: false,
- enumerable: true,
- configurable: false
- });
- /**
- * Cynara(since tizen 3.0) only support native privilege.
- * simply web privilege convert native privilege for checking access.
- */
- var privilege = {
- ACCOUNT_READ: 'http://tizen.org/privilege/account.read',
- ACCOUNT_WRITE: 'http://tizen.org/privilege/account.write',
- ALARM: 'http://tizen.org/privilege/alarm.get',
- APPLICATION_INFO: 'http://tizen.org/privilege/application.info',
- APPLICATION_LAUNCH: 'http://tizen.org/privilege/application.launch',
- APPMANAGER_CERTIFICATE: 'http://tizen.org/privilege/appmanager.certificate',
- APPMANAGER_KILL: 'http://tizen.org/privilege/appmanager.kill',
- BLUETOOTH_ADMIN: 'http://tizen.org/privilege/bluetooth.admin',
- BLUETOOTH_GAP: 'http://tizen.org/privilege/bluetooth.gap',
- BLUETOOTH_HEALTH: 'http://tizen.org/privilege/bluetooth.health',
- BLUETOOTH_SPP: 'http://tizen.org/privilege/bluetooth.spp',
- BLUETOOTHMANAGER: 'http://tizen.org/privilege/bluetoothmanager',
- BLUETOOTH: 'http://tizen.org/privilege/bluetooth',
- BOOKMARK_READ: 'http://tizen.org/privilege/bookmark.read',
- BOOKMARK_WRITE: 'http://tizen.org/privilege/bookmark.write',
- CALENDAR_READ: 'http://tizen.org/privilege/calendar.read',
- CALENDAR_WRITE: 'http://tizen.org/privilege/calendar.write',
- CALLHISTORY_READ: 'http://tizen.org/privilege/callhistory.read',
- CALLHISTORY_WRITE: 'http://tizen.org/privilege/callhistory.write',
- CONTACT_READ: 'http://tizen.org/privilege/contact.read',
- CONTACT_WRITE: 'http://tizen.org/privilege/contact.write',
- CONTENT_READ: 'http://tizen.org/privilege/content.write',
- CONTENT_WRITE: 'http://tizen.org/privilege/content.write',
- DATACONTROL_CONSUMER: 'http://tizen.org/privilege/datacontrol.consumer',
- DATASYNC: 'http://tizen.org/privilege/datasync',
- DOWNLOAD: 'http://tizen.org/privilege/download',
- FILESYSTEM_READ: 'http://tizen.org/privilege/filesystem.read',
- FILESYSTEM_WRITE: 'http://tizen.org/privilege/filesystem.write',
- HAPTIC: 'http://tizen.org/privilege/haptic',
- HEALTHINFO: 'http://tizen.org/privilege/healthinfo',
- INTERNET: 'http://tizen.org/privilege/internet',
- LED: 'http://tizen.org/privilege/led',
- LOCATION: 'http://tizen.org/privilege/location',
- MEDIACONTROLLER_SERVER: 'http://tizen.org/privilege/mediacontroller.server',
- MEDIACONTROLLER_CLIENT: 'http://tizen.org/privilege/mediacontroller.client',
- MESSAGING_READ: 'http://tizen.org/privilege/messaging.read',
- MESSAGING_WRITE: 'http://tizen.org/privilege/messaging.write',
- NETWORKBEARERSELECTION: 'http://tizen.org/privilege/networkbearerselection',
- NFC_ADMIN: 'http://tizen.org/privilege/nfc.admin',
- NFC_CARDEMULATION: 'http://tizen.org/privilege/nfc.cardemulation',
- NFC_COMMON: 'http://tizen.org/privilege/nfc.common',
- NFC_P2P: 'http://tizen.org/privilege/nfc.p2p',
- NFC_TAG: 'http://tizen.org/privilege/nfc.tag',
- NOTIFICATION: 'http://tizen.org/privilege/notification',
- PACKAGE_INFO: 'http://tizen.org/privilege/packagemanager.info',
- PACKAGEMANAGER_INSTALL: 'http://tizen.org/privilege/packagemanager.install',
- POWER: 'http://tizen.org/privilege/power',
- PUSH: 'http://tizen.org/privilege/push',
- SECUREELEMENT: 'http://tizen.org/privilege/secureelement',
- SETTING_ADMIN: 'http://tizen.org/privilege/systemsettings.admin',
- SETTING: 'http://tizen.org/privilege/setting',
- SYSTEM: 'http://tizen.org/privilege/system',
- SYSTEMMANAGER: 'http://tizen.org/privilege/systemmanager',
- TELEPHONY: 'http://tizen.org/privilege/telephony',
- VOLUME_SET: 'http://tizen.org/privilege/volume.set',
- WEBSETTING: 'http://tizen.org/privilege/websetting',
- TV_INPUT_DEVICE: 'http://tizen.org/privilege/tv.inputdevice'
- };
-
- Object.freeze(privilege);
-
+ Object.defineProperty(this, 'privilege', {
- value: privilege,
++ value: _privilege,
+ writable: false,
+ enumerable: true,
+ configurable: false
+ });
}
Utils.prototype.error = console.error.bind(console);
};
Utils.prototype.getPkgApiVersion = function() {
- var result = native_.callSync('Utils_getPkgApiVersion');
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- return native_.getResultObject(result);
+ var result = native_.callSync('Utils_getPkgApiVersion');
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ return native_.getResultObject(result);
};
- if (Object.values(_privilege).indexOf(toCheck) < 0) {
- return false;
- }
- return true;
- }
+var isPrivilege = function(toCheck) {
++ if (Object.values(_privilege).indexOf(toCheck) < 0) {
++ return false;
++ }
++ return true;
++};
+
Utils.prototype.checkPrivilegeAccess = function(privilege) {
- if (!isPrivilege(privilege)) {
- xwalk.utils.error('Privilege ' + privilege + ' does not exist. Please fix your code.');
- throw new WebAPIException(WebAPIException.SECURITY_ERR);
- }
-
- 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;
++ if (!isPrivilege(privilege)) {
++ xwalk.utils.error(
++ 'Privilege ' + privilege + ' does not exist. Please fix your code.'
++ );
++ throw new WebAPIException(WebAPIException.SECURITY_ERR);
+ }
- }
+
- if (arr_ver.length > arr_app_ver.length) {
- return true;
- }
- return false;
- }
+ 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;
+ }
+ }
+
+ if (arr_ver.length > arr_app_ver.length) {
+ return true;
+ }
+ 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 (!this.isAppVersionEarlierThan(new_ver)) {
+ this.checkPrivilegeAccess(new_priv);
+ } else if (old_priv != undefined) {
+ this.checkPrivilegeAccess(old_priv);
+ }
+ };
- 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.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);
- }
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
};
Utils.prototype.checkProfile = function() {
- var result = native_.callSync('Utils_checkProfile', {});
+ var result = native_.callSync('Utils_checkProfile', {});
- return native_.getResultObject(result);
+ return native_.getResultObject(result);
};
- if (_type.isUndefined(replacement)) {
- this.warn('DEPRECATION WARNING: ' + name + ' is deprecated and using it is not recommended.');
- } else {
- this.warn('DEPRECATION WARNING: ' + name + ' is deprecated and using it is not recommended.'
- + "Try using " + replacement + " instead.");
- }
+Utils.prototype.printDeprecationWarningFor = function(name, replacement) {
++ if (_type.isUndefined(replacement)) {
++ this.warn(
++ 'DEPRECATION WARNING: ' +
++ name +
++ ' is deprecated and using it is not recommended.'
++ );
++ } else {
++ this.warn(
++ 'DEPRECATION WARNING: ' +
++ name +
++ ' is deprecated and using it is not recommended.' +
++ 'Try using ' +
++ replacement +
++ ' instead.'
++ );
++ }
+};
+
/////////////////////////////////////////////////////////////////////////////
/** @constructor */
var Type = function() {};
};
Type.prototype.isArray = function(obj) {
- return Array.isArray(obj);
+ return Array.isArray(obj);
};
- return Number.isInteger(value) && 0 <= value && value <= 255;
+Type.prototype.isOctet = function(value) {
- return value instanceof Uint8Array;
++ return Number.isInteger(value) && 0 <= value && value <= 255;
+};
+
+Type.prototype.isByteStream = function(value) {
- return Array.isArray(value) && value.every(this.isByteStream);
++ return value instanceof Uint8Array;
+};
+
+Type.prototype.isByteStreamArray = function(value) {
- return Array.isArray(value) && value.every(this.isOctet);
++ return Array.isArray(value) && value.every(this.isByteStream);
+};
+
+Type.prototype.isLegacyByteStream = function(value) {
- return (
- Array.isArray(value) &&
- value.every((function(x) {
- return this.isLegacyByteStream(x);
- }).bind(this))
- );
++ return Array.isArray(value) && value.every(this.isOctet);
+};
+
+Type.prototype.isLegacyByteStreamArray = function(value) {
++ return (
++ Array.isArray(value) &&
++ value.every(
++ function(x) {
++ return this.isLegacyByteStream(x);
++ }.bind(this)
++ )
++ );
+};
+
Type.prototype.isFunction = function(obj) {
- return typeof obj === 'function';
+ return typeof obj === 'function';
};
Type.prototype.isNumber = function(obj) {
};
Type.prototype.isString = function(obj) {
- return typeof obj === 'string';
+ return typeof obj === 'string';
};
- return Array.isArray(value) &&
- value.every(this.isString);
+Type.prototype.isStringArray = function(value) {
++ return Array.isArray(value) && value.every(this.isString);
+};
+
Type.prototype.isDate = function(obj) {
- return obj instanceof Date;
+ return obj instanceof Date;
};
Type.prototype.isNull = function(obj) {
* {
* 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
++ * values: Validator.Types.DOUBLE // converts elements, only primitive
++ * // types are supported
* }
* ]
* @code
* @param {Function} instance
*/
Validator.prototype.isConstructorCall = function(obj, instance) {
- if (!(obj instanceof instance) || obj._previouslyConstructed) {
- // There is no TypeError exception in Tizen 2.3.0 API spec but it's required by current TCTs.
- // For Tizen compliance it's wrapped into WebAPIException.
- throw new WebAPIException('TypeError', 'Constructor cannot be called as function.');
- }
+ if (!(obj instanceof instance) || obj._previouslyConstructed) {
- // There is no TypeError exception in Tizen 2.3.0 API spec but it's required by
- // current TCTs.
- // For Tizen compliance it's wrapped into WebAPIException.
++ // There is no TypeError exception in Tizen 2.3.0 API spec but it's required
++ // by current TCTs. For Tizen compliance it's wrapped into WebAPIException.
+ throw new WebAPIException(
+ 'TypeError',
+ 'Constructor cannot be called as function.'
+ );
+ }
- Object.defineProperty(obj, '_previouslyConstructed', {
- value: true,
- writable: false,
- enumerable: false
- });
+ Object.defineProperty(obj, '_previouslyConstructed', {
+ value: true,
+ writable: false,
+ enumerable: false
+ });
};
-
/**
* @deprecated Use isConstructorCall() instead.
*/
/////////////////////////////////////////////////////////////////////////////
/** @constructor */
var NativeManager = function(extension) {
-
- /**
- * @type {string}
- * @const
- */
- this.CALLBACK_ID_KEY = 'callbackId';
-
- /**
- * @type {string}
- * @const
- */
- this.LISTENER_ID_KEY = 'listenerId';
-
- /**
- * @type {Object}
- * @private
- */
- var extension_ = extension;
-
- /**
- * @type {number}
- * @private
- */
- var replyId_ = 0;
-
- /**
- * Map of async reply callbacks.
- *
- * @type {Object.<number, function>}
- * @protected
- */
- this.callbacks_ = {};
-
- /**
- * Map of registered listeners.
- *
- * @type {Object.<string, function>}
- * @protected
- */
- this.listeners_ = {};
-
- _validator.isConstructorCall(this, NativeManager);
-
- // TODO: Remove mockup if WRT implements sendRuntimeMessage
- // This is temporary mockup!
- extension.sendRuntimeMessage = extension.sendRuntimeMessage || function() {
- xwalk.utils.error('Runtime did not implement extension.sendRuntimeMessage!');
- throw new WebAPIException(WebAPIException.UNKNOWN_ERR,
- 'Runtime did not implement extension.sendRuntimeMessage!');
- };
-
- extension.sendRuntimeAsyncMessage = extension.sendRuntimeAsyncMessage || function() {
- xwalk.utils.error('Runtime did not implement extension.sendRuntimeAsyncMessage!');
- throw new WebAPIException(WebAPIException.UNKNOWN_ERR,
- 'Runtime did not implement extension.sendRuntimeAsyncMessage!');
- };
-
- extension.sendRuntimeSyncMessage = extension.sendRuntimeSyncMessage || function() {
- xwalk.utils.error('Runtime did not implement extension.sendRuntimeSyncMessage!');
- throw new WebAPIException(WebAPIException.UNKNOWN_ERR,
- 'Runtime did not implement extension.sendRuntimeSyncMessage!');
- };
-
- // check extension prototype
- if (!extension || !extension.internal ||
- !_type.isFunction(extension.postMessage) ||
- !_type.isFunction(extension.internal.sendSyncMessage) ||
- !_type.isFunction(extension.sendRuntimeMessage) ||
- !_type.isFunction(extension.sendRuntimeAsyncMessage) ||
- !_type.isFunction(extension.sendRuntimeSyncMessage) ||
- !_type.isFunction(extension.setMessageListener)) {
- throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR,
- 'Wrong extension object passed');
- }
-
- Object.defineProperties(this, {
- nextReplyId: {
- get: function() {
- return ++replyId_;
- },
- enumerable: false
- },
- extension: {
- get: function() {
- return extension_;
- },
- enumerable: true
- }
- });
-
- extension_.setMessageListener(function(json) {
- try {
- var msg = JSON_.parse(json);
- } catch (error) {
- // Because of special handling of power lock in chromium, the special signals:
- // - __DisableChromiumInternalPowerLock
- // - __EnableChromiumInternalPowerLock
- // could occur. In such cases we are silently ignroing those messages.
- // TODO This is workaround for missing patch in chromium-efl package which should handle
- // this special message and don't forward it to webapi JS. After chromium-efl will
- // be updated, below checking should be removed.
- if (json.substring(0,2) === '__') {
- return;
- }
- xwalk.utils.error('Ignoring message - Invalid JSON received: ' + json);
- return;
- }
- var id;
-
- if (msg.hasOwnProperty(this.CALLBACK_ID_KEY)) {
- id = msg[this.CALLBACK_ID_KEY];
- delete msg[this.CALLBACK_ID_KEY];
-
- if (!_type.isFunction(this.callbacks_[id])) {
- xwalk.utils.error('Wrong callback identifier. Ignoring message.');
- return;
- }
-
- var f = this.callbacks_[id];
- setTimeout(function() {
- try {
- f(msg);
- } catch (e) {
- xwalk.utils.error('########## exception');
- xwalk.utils.error(e);
- }
- }, 0);
- delete this.callbacks_[id];
-
- return;
+ /**
+ * @type {string}
+ * @const
+ */
+ this.CALLBACK_ID_KEY = 'callbackId';
+
+ /**
+ * @type {string}
+ * @const
+ */
+ this.LISTENER_ID_KEY = 'listenerId';
+
+ /**
+ * @type {Object}
+ * @private
+ */
+ var extension_ = extension;
+
+ /**
+ * @type {number}
+ * @private
+ */
+ var replyId_ = 0;
+
+ /**
+ * Map of async reply callbacks.
+ *
+ * @type {Object.<number, function>}
+ * @protected
+ */
+ this.callbacks_ = {};
+
+ /**
+ * Map of registered listeners.
+ *
+ * @type {Object.<string, function>}
+ * @protected
+ */
+ this.listeners_ = {};
+
+ _validator.isConstructorCall(this, NativeManager);
+
+ // TODO: Remove mockup if WRT implements sendRuntimeMessage
+ // This is temporary mockup!
+ extension.sendRuntimeMessage =
+ extension.sendRuntimeMessage ||
+ function() {
+ xwalk.utils.error('Runtime did not implement extension.sendRuntimeMessage!');
+ throw new WebAPIException(
+ WebAPIException.UNKNOWN_ERR,
+ 'Runtime did not implement extension.sendRuntimeMessage!'
+ );
+ };
+
+ extension.sendRuntimeAsyncMessage =
+ extension.sendRuntimeAsyncMessage ||
+ function() {
+ xwalk.utils.error(
+ 'Runtime did not implement extension.sendRuntimeAsyncMessage!'
+ );
+ throw new WebAPIException(
+ WebAPIException.UNKNOWN_ERR,
+ 'Runtime did not implement extension.sendRuntimeAsyncMessage!'
+ );
+ };
+
+ extension.sendRuntimeSyncMessage =
+ extension.sendRuntimeSyncMessage ||
+ function() {
+ xwalk.utils.error(
+ 'Runtime did not implement extension.sendRuntimeSyncMessage!'
+ );
+ throw new WebAPIException(
+ WebAPIException.UNKNOWN_ERR,
+ 'Runtime did not implement extension.sendRuntimeSyncMessage!'
+ );
+ };
+
+ // check extension prototype
+ if (
+ !extension ||
+ !extension.internal ||
+ !_type.isFunction(extension.postMessage) ||
+ !_type.isFunction(extension.internal.sendSyncMessage) ||
+ !_type.isFunction(extension.sendRuntimeMessage) ||
+ !_type.isFunction(extension.sendRuntimeAsyncMessage) ||
+ !_type.isFunction(extension.sendRuntimeSyncMessage) ||
+ !_type.isFunction(extension.setMessageListener)
+ ) {
+ throw new WebAPIException(
+ WebAPIException.TYPE_MISMATCH_ERR,
+ 'Wrong extension object passed'
+ );
}
- if (msg.hasOwnProperty(this.LISTENER_ID_KEY)) {
- id = msg[this.LISTENER_ID_KEY];
- delete msg[this.LISTENER_ID_KEY];
-
- if (!_type.isFunction(this.listeners_[id])) {
- xwalk.utils.error('Wrong listener identifier. Ignoring message.');
- return;
- }
-
- var f = this.listeners_[id];
- setTimeout(function() {
- try {
- f(msg);
- } catch (e) {
- xwalk.utils.error('########## exception');
- xwalk.utils.error(e);
+ Object.defineProperties(this, {
+ nextReplyId: {
+ get: function() {
+ return ++replyId_;
+ },
+ enumerable: false
+ },
+ extension: {
+ get: function() {
+ return extension_;
+ },
+ enumerable: true
}
- }, 0);
-
- return;
- }
+ });
+
+ extension_.setMessageListener(
+ function(json) {
+ try {
+ var msg = JSON_.parse(json);
+ } catch (error) {
+ // Because of special handling of power lock in chromium, the special
+ // signals:
+ // - __DisableChromiumInternalPowerLock
+ // - __EnableChromiumInternalPowerLock
+ // could occur. In such cases we are silently ignroing those messages.
+ // TODO This is workaround for missing patch in chromium-efl package
- // which should handle this special message and don't forward it to
++ // which should handle this special message and don't forward it to
+ // webapi JS. After chromium-efl will be updated, below checking should
+ // be removed.
+ if (json.substring(0, 2) === '__') {
+ return;
+ }
+ xwalk.utils.error('Ignoring message - Invalid JSON received: ' + json);
+ return;
+ }
+ var id;
+
+ if (msg.hasOwnProperty(this.CALLBACK_ID_KEY)) {
+ id = msg[this.CALLBACK_ID_KEY];
+ delete msg[this.CALLBACK_ID_KEY];
+
+ if (!_type.isFunction(this.callbacks_[id])) {
+ xwalk.utils.error('Wrong callback identifier. Ignoring message.');
+ return;
+ }
+
+ var f = this.callbacks_[id];
+ setTimeout(function() {
+ try {
+ f(msg);
+ } catch (e) {
+ xwalk.utils.error('########## exception');
+ xwalk.utils.error(e);
+ }
+ }, 0);
+ delete this.callbacks_[id];
+
+ return;
+ }
- xwalk.utils.error('Missing callback or listener identifier. Ignoring message.');
+ if (msg.hasOwnProperty(this.LISTENER_ID_KEY)) {
+ id = msg[this.LISTENER_ID_KEY];
+ delete msg[this.LISTENER_ID_KEY];
+
+ if (!_type.isFunction(this.listeners_[id])) {
+ xwalk.utils.error('Wrong listener identifier. Ignoring message.');
+ return;
+ }
+
+ var f = this.listeners_[id];
+ setTimeout(function() {
+ try {
+ f(msg);
+ } catch (e) {
+ xwalk.utils.error('########## exception');
+ xwalk.utils.error(e);
+ }
+ }, 0);
+
+ return;
+ }
- }.bind(this));
+ xwalk.utils.error(
+ 'Missing callback or listener identifier. Ignoring message.'
+ );
+ }.bind(this)
+ );
};
NativeManager.prototype.call = function(cmd, args, callback) {
* @param {string} name An error type.
*/
var WebAPIException = function(code, message, name) {
- var code_ = 0;
- var name_ = code_to_name[code];
- var message_ = 'Unknown error';
+ var code_ = 0;
+ var name_ = code_to_name[code];
+ var message_ = 'Unknown error';
- switch (arguments.length) {
+ switch (arguments.length) {
case 1:
- var error = arguments[0];
- if (__isObject(error)) {
- code_ = error.code;
- name_ = error.name;
- message_ = error.message;
- if (__isUndefined(code_) && !__isUndefined(name_))
- code_ = name_to_code[name_];
- if (__isUndefined(name_) && !__isUndefined(code_))
- name_ = code_to_name[code_];
- } else if (__isNumber(error)) {
- // backward compatibility with crosswalk implementation
- code_ = error;
- name_ = code_to_name[code];
- message_ = name_;
- }
- break;
- case 2:
- if (__isNumber(arguments[0])) {
- code_ = arguments[0];
- if (!__isUndefined(code_to_name[code_])) {
- name_ = code_to_name[code_];
+ var error = arguments[0];
+ if (__isObject(error)) {
+ code_ = error.code;
+ name_ = error.name;
+ message_ = error.message;
+ if (__isUndefined(code_) && !__isUndefined(name_))
+ code_ = name_to_code[name_];
+ if (__isUndefined(name_) && !__isUndefined(code_))
+ name_ = code_to_name[code_];
+ } else if (__isNumber(error)) {
+ // backward compatibility with crosswalk implementation
+ code_ = error;
+ name_ = code_to_name[code];
+ message_ = name_;
}
- } else {
- name_ = String(arguments[0]);
- if (!__isUndefined(name_to_code[name_])) {
- code_ = name_to_code[name_];
+ break;
+ case 2:
+ if (__isNumber(arguments[0])) {
+ code_ = arguments[0];
+ if (!__isUndefined(code_to_name[code_])) {
+ name_ = code_to_name[code_];
+ }
+ } else {
+ name_ = String(arguments[0]);
+ if (!__isUndefined(name_to_code[name_])) {
+ code_ = name_to_code[name_];
+ }
}
- }
- message_ = String(arguments[1]);
- break;
+ message_ = String(arguments[1]);
+ break;
case 3:
- // backward compatibility with crosswalk implementation
- code_ = Number(arguments[0]);
- message_ = String(arguments[1]);
- name_ = String(arguments[2]);
- break;
+ // backward compatibility with crosswalk implementation
+ code_ = Number(arguments[0]);
+ message_ = String(arguments[1]);
+ name_ = String(arguments[2]);
+ break;
default:
- return;
- }
+ return;
+ }
- if (code_ > errors.DATA_CLONE_ERR) {
- code_ = 0;
- }
+ if (code_ > errors.DATA_CLONE_ERR) {
+ code_ = 0;
+ }
- // attributes
- Object.defineProperties(this, {
- code: {value: code_, writable: false, enumerable: true},
- name: {value: name_, writable: false, enumerable: true},
- message: {value: message_, writable: false, enumerable: true}
- });
+ // attributes
+ Object.defineProperties(this, {
+ code: { value: code_, writable: false, enumerable: true },
+ name: { value: name_, writable: false, enumerable: true },
+ message: { value: message_, writable: false, enumerable: true }
+ });
- this.constructor.prototype.__proto__ = Error.prototype;
- Error.captureStackTrace && Error.captureStackTrace(this, this.constructor); // V8-specific code
+ this.constructor.prototype.__proto__ = Error.prototype;
- Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
+ // V8-specific code
++ Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
};
WebAPIException.prototype.toString = function() {
Object.freeze(exports.utils);
Object.freeze(Utils.prototype);
Object.freeze(NativeManager.prototype);
-
+Object.freeze(CommonListenerManager.prototype);
};
WidgetInstance.prototype.getContent = function() {
- var args = validator.validateMethod(arguments, [{
- name : 'successCallback',
- type : types.FUNCTION,
- }, {
- name : 'errorCallback',
- type : types.FUNCTION,
- }]);
-
- var callArgs = {};
- callArgs.widgetId = this.widget.id;
- callArgs.instanceId = this.id;
-
- var callback = function(result) {
+ var args = validator.validateMethod(arguments, [
+ {
+ name: 'successCallback',
+ type: types.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: types.FUNCTION
+ }
+ ]);
+
+ var callArgs = {};
+ callArgs.widgetId = this.widget.id;
+ callArgs.instanceId = this.id;
+
+ var callback = function(result) {
+ if (native.isFailure(result)) {
+ args.errorCallback(native.getErrorObject(result));
+ } else {
+ args.successCallback(native.getResultObject(result));
+ }
+ };
+
+ var result = native.call('WidgetInstance_getContent', callArgs, callback);
if (native.isFailure(result)) {
- args.errorCallback(native.getErrorObject(result));
- } else {
- args.successCallback(native.getResultObject(result));
+ throw native.getErrorObject(result);
}
- };
-
- var result = native.call('WidgetInstance_getContent', callArgs, callback);
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- }
};
-
+var widgetToListenerManagerMapping = {};
+
function Widget(data) {
- if (!widgetToListenerManagerMapping.hasOwnProperty(data.id)) {
- widgetToListenerManagerMapping[data.id] = new xwalk.utils.CommonListenerManager(
- native, 'WidgetStateChangeCallback_' + data.id);
- }
- Object.defineProperties(this, {
- id: {
- value: data.id,
- writable: false,
- enumerable: true
- },
- applicationId: {
- value: data.applicationId,
- writable: false,
- enumerable: true
- },
- setupApplicationId: {
- value: data.setupApplicationId ? data.setupApplicationId : null,
- writable: false,
- enumerable: true
- },
- packageId: {
- value: data.packageId,
- writable: false,
- enumerable: true
- },
- noDisplay: {
- value: data.noDisplay,
- writable: false,
- enumerable: true
++ if (!widgetToListenerManagerMapping.hasOwnProperty(data.id)) {
++ widgetToListenerManagerMapping[data.id] = new xwalk.utils.CommonListenerManager(
++ native,
++ 'WidgetStateChangeCallback_' + data.id
++ );
+ }
- });
- };
+ Object.defineProperties(this, {
+ id: {
+ value: data.id,
+ writable: false,
+ enumerable: true
+ },
+ applicationId: {
+ value: data.applicationId,
+ writable: false,
+ enumerable: true
+ },
+ setupApplicationId: {
+ value: data.setupApplicationId ? data.setupApplicationId : null,
+ writable: false,
+ enumerable: true
+ },
+ packageId: {
+ value: data.packageId,
+ writable: false,
+ enumerable: true
+ },
+ noDisplay: {
+ value: data.noDisplay,
+ writable: false,
+ enumerable: true
+ }
+ });
+ }
Widget.prototype.getName = function() {
- var args = validator.validateMethod(arguments, [{
- name : 'locale',
- type : types.STRING,
- optional : true,
- nullable : true
- }]);
-
- var callArgs = {};
- callArgs.widgetId = this.id;
-
- if (args.locale) {
- callArgs.locale = args.locale;
- }
-
- var ret = native.callSync('Widget_getName', callArgs);
-
- if (native.isFailure(ret)) {
- throw native.getErrorObject(ret);
- } else {
- return native.getResultObject(ret);
- }
+ var args = validator.validateMethod(arguments, [
+ {
+ name: 'locale',
+ type: types.STRING,
+ optional: true,
+ nullable: true
+ }
+ ]);
+
+ var callArgs = {};
+ callArgs.widgetId = this.id;
+
+ if (args.locale) {
+ callArgs.locale = args.locale;
+ }
+
+ var ret = native.callSync('Widget_getName', callArgs);
+
+ if (native.isFailure(ret)) {
+ throw native.getErrorObject(ret);
+ } else {
+ return native.getResultObject(ret);
+ }
};
Widget.prototype.getInstances = function() {
};
Widget.prototype.getVariants = function() {
- var args = validator.validateMethod(arguments, [{
- name : 'successCallback',
- type : types.FUNCTION,
- }, {
- name : 'errorCallback',
- type : types.FUNCTION,
- optional : true,
- nullable : true
- }]);
-
- var callback = function(result) {
+ var args = validator.validateMethod(arguments, [
+ {
+ 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 {
+ var variants = createObjects(result, WidgetVariant);
+ args.successCallback(variants);
+ }
+ };
+
+ var callArgs = {};
+ callArgs.widgetId = this.id;
+
+ var result = native.call('Widget_getVariants', callArgs, callback);
if (native.isFailure(result)) {
- native.callIfPossible(args.errorCallback, native.getErrorObject(result));
- } else {
- var variants = createObjects(result, WidgetVariant);
- args.successCallback(variants);
+ throw native.getErrorObject(result);
}
- };
-
- var callArgs = {};
- callArgs.widgetId = this.id;
-
- var result = native.call('Widget_getVariants', 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;
-}
-
-ListenerManager.prototype.onListenerCalled = function(msg) {
- for (var watchId in this.listeners) {
- if (this.listeners.hasOwnProperty(watchId)) {
- this.listeners[watchId](this.native.getResultObject(msg));
- }
- }
-};
-
-ListenerManager.prototype.addListener = function(callback) {
- var id = this.nextId;
- if (!this.nativeSet) {
- this.native.addListener(this.listenerName, this.onListenerCalled.bind(this));
- this.nativeSet = true;
- }
- this.listeners[id] = callback;
- ++this.nextId;
- return id;
-};
-
-ListenerManager.prototype.removeListener = function(watchId) {
- if (this.listeners.hasOwnProperty(watchId)) {
- delete this.listeners[watchId];
- }
-};
-
-var WIDGET_STATE_CHANGE_LISTENER = 'WidgetStateChangeCallback';
-var widgetStateChangeListener = new ListenerManager(native, WIDGET_STATE_CHANGE_LISTENER);
-
Widget.prototype.addStateChangeListener = function() {
- var args = validator.validateMethod(arguments, [{
- name : 'eventCallback',
- type : types.FUNCTION,
- }]);
-
- if (widgetToListenerManagerMapping[this.id].numberOfListeners == 0) {
- var result = native.callSync('Widget_addStateChangeListener', {widgetId : this.id});
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- }
- }
-
- var func = function(msg) {
- var result = native.getResultObject(msg);
- if (result.widgetId === this.id) {
- args.eventCallback(new WidgetInstance(result, this), result.event);
+ var args = validator.validateMethod(arguments, [
+ {
+ name: 'eventCallback',
+ type: types.FUNCTION
+ }
+ ]);
+
- var result = native.callSync('Widget_addStateChangeListener', { widgetId: this.id });
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
++ if (widgetToListenerManagerMapping[this.id].numberOfListeners == 0) {
++ var result = native.callSync('Widget_addStateChangeListener', {
++ widgetId: this.id
++ });
++ if (native.isFailure(result)) {
++ throw native.getErrorObject(result);
++ }
}
- }.bind(this);
- return widgetToListenerManagerMapping[this.id].addListener(func);
+ var func = function(msg) {
- if (msg.widgetId === this.id) {
- args.eventCallback(new WidgetInstance(msg, this), msg.event);
++ var result = native.getResultObject(msg);
++ if (result.widgetId === this.id) {
++ args.eventCallback(new WidgetInstance(result, this), result.event);
+ }
+ }.bind(this);
+
- return widgetStateChangeListener.addListener(func);
++ return widgetToListenerManagerMapping[this.id].addListener(func);
};
Widget.prototype.removeStateChangeListener = function() {
- var args = validator.validateMethod(arguments, [{
- name : 'watchId',
- type : types.LONG,
- }]);
-
- widgetToListenerManagerMapping[this.id].removeListener(args.watchId);
- if (widgetToListenerManagerMapping[this.id].numberOfListeners == 0) {
- var result = native.callSync('Widget_removeStateChangeListener', {widgetId : this.id});
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- }
- }
+ var args = validator.validateMethod(arguments, [
+ {
+ name: 'watchId',
+ type: types.LONG
+ }
+ ]);
+
- widgetStateChangeListener.removeListener(args.watchId);
-
- var result = native.callSync('Widget_removeStateChangeListener', {
- widgetId: this.id
- });
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
++ widgetToListenerManagerMapping[this.id].removeListener(args.watchId);
++ if (widgetToListenerManagerMapping[this.id].numberOfListeners == 0) {
++ var result = native.callSync('Widget_removeStateChangeListener', {
++ widgetId: this.id
++ });
++ if (native.isFailure(result)) {
++ throw native.getErrorObject(result);
++ }
+ }
};
- function WidgetServiceManager() {
- };
+ function WidgetServiceManager() {}
WidgetServiceManager.prototype.getWidget = function() {
- var args = validator.validateMethod(arguments, [{
- name : 'widgetId',
- type : types.STRING,
- }]);
+ var args = validator.validateMethod(arguments, [
+ {
+ name: 'widgetId',
+ type: types.STRING
+ }
+ ]);
- var callArgs = {};
- callArgs.widgetId = args.widgetId;
+ var callArgs = {};
+ callArgs.widgetId = args.widgetId;
- var ret = native.callSync('WidgetServiceManager_getWidget', callArgs);
+ var ret = native.callSync('WidgetServiceManager_getWidget', callArgs);
- if (native.isFailure(ret)) {
- throw native.getErrorObject(ret);
- } else {
- return new Widget(native.getResultObject(ret));
- }
+ if (native.isFailure(ret)) {
+ throw native.getErrorObject(ret);
+ } else {
+ return new Widget(native.getResultObject(ret));
+ }
};
WidgetServiceManager.prototype.getWidgets = function() {