org.symbian.tools.wrttools.previewer/preview/script/lib/device.js
changeset 337 afe6a53c0ed4
parent 333 895153411a80
equal deleted inserted replaced
336:131c321bf080 337:afe6a53c0ed4
    37 	 * @return {Object} service object  
    37 	 * @return {Object} service object  
    38 	 */
    38 	 */
    39 	getServiceObject: function(provider, Interface){
    39 	getServiceObject: function(provider, Interface){
    40 
    40 
    41 		if (!device.implementation.context)
    41 		if (!device.implementation.context)
    42 			throw 'device implementation object not instantiated!'
    42 			throw 'device implementation object not instantiated!';
    43 
    43 
    44 		if (device.implementation.options.enabled) 
    44 		if (device.implementation.options.enabled) 
    45 			return device.implementation.getInterface(provider, Interface);
    45 			return device.implementation.getInterface(provider, Interface);
    46 		else {
    46 		else {
    47 			device.implementation.context.notify('device SAPI is disabled.');
    47 			device.implementation.context.notify('device SAPI is disabled.');
    58  * @param {String} 		version - version number (default: current version)
    58  * @param {String} 		version - version number (default: current version)
    59  * @return {Object} 	returns new implementation context object 
    59  * @return {Object} 	returns new implementation context object 
    60  * @constructor 		
    60  * @constructor 		
    61  */
    61  */
    62 device.implementation = function(version){
    62 device.implementation = function(version){
    63 
       
    64 	this.version = version || '';
    63 	this.version = version || '';
    65 	
    64 	
    66 	// set context to current object
    65 	// set context to current object
    67 	device.implementation.context = this;	
    66 	device.implementation.context = this;	
    68 
       
    69 	var libpath = 'preview/script/lib/',
       
    70 		datapath = 'preview/data/';
       
    71 	
       
    72 	// load implementation files
       
    73 	// this is done async by the browser engine, so be aware of sync conditions!!
       
    74 	if (version == '1')
       
    75 		loadSAPI(libpath + 'sapi1/');
       
    76 	else if (!version)
       
    77 		loadSAPI();
       
    78 	else
       
    79 		throw 'unsuppported SAPI version!';
       
    80 	
       
    81 	function loadSAPI(path){
       
    82 		var path = path || (libpath + "sapi/");
       
    83 		
       
    84 		// load API
       
    85 //		loadScript(path + "AppManager.js");
       
    86 //		loadScript(path + "Calendar.js");
       
    87 //		loadScript(path + "Contact.js");
       
    88 //		loadScript(path + "Landmarks.js");
       
    89 //		loadScript(path + "Location.js");
       
    90 //		loadScript(path + "Logging.js");
       
    91 //		loadScript(path + "MediaManagement.js");
       
    92 //		loadScript(path + "Messaging.js");
       
    93 //		loadScript(path + "Sensor.js");
       
    94 //		loadScript(path + "SysInfo.js");
       
    95 		
       
    96 		// load sample data
       
    97 //		loadScript(datapath + "appManager_data.js");
       
    98 //		loadScript(datapath + "calendar_data.js");
       
    99 //		loadScript(datapath + "contact_data.js");
       
   100 //		loadScript(datapath + "landmarks_data.js");
       
   101 //		loadScript(datapath + "location_data.js");
       
   102 //		loadScript(datapath + "logging_data.js");
       
   103 //		loadScript(datapath + "mediaManagement_data.js");
       
   104 //		loadScript(datapath + "messaging_data.js");
       
   105 //		loadScript(datapath + "sensor_data.js");
       
   106 //		loadScript(datapath + "sysInfo_data.js");
       
   107 	}
       
   108 	
       
   109 	function loadScript(src){
       
   110 		var head = document.getElementsByTagName("head")[0] || document.documentElement, 
       
   111 			script = document.createElement("script");
       
   112 		
       
   113 		script.type = "text/javascript";
       
   114 		script.src = src;
       
   115 		head.appendChild(script);
       
   116 	}
       
   117 };
    67 };
   118 
    68 
   119 (function(){
    69 (function(){
   120 device.implementation.prototype = {
    70 device.implementation.prototype = {
   121 	
    71 	
   190 	 		* getNext
   140 	 		* getNext
   191 	 		*/
   141 	 		*/
   192 			getNext : function(){
   142 			getNext : function(){
   193 				return index < data.length ? data[index++] : undefined;
   143 				return index < data.length ? data[index++] : undefined;
   194 			}
   144 			}
   195 		}
   145 		};
   196 	},
   146 	},
   197 	
   147 	
   198 	
   148 	
   199 	/**
   149 	/**
   200 	 * internal __methods__
   150 	 * internal __methods__
   318 	// extended text string functionality 
   268 	// extended text string functionality 
   319 	_t: function(str){
   269 	_t: function(str){
   320 		
   270 		
   321 		str = typeof str != 'undefined' ? String(str) : '';
   271 		str = typeof str != 'undefined' ? String(str) : '';
   322 		return new StringEx(str);
   272 		return new StringEx(str);
   323 	}		
   273 	}
   324 };
   274 };
   325 
   275 
   326 	/**
   276 	/**
   327 	 * extended String object (available only within device.implementation.context through _t() method)
   277 	 * extended String object (available only within device.implementation.context through _t() method)
   328 	 */ 
   278 	 */ 
   524 	}
   474 	}
   525 	var listener = device.implementation.listeners[provider][eventType];
   475 	var listener = device.implementation.listeners[provider][eventType];
   526 
   476 
   527 	// call the provider's handler
   477 	// call the provider's handler
   528 	listener.handler(listener.transactionID, listener.criteria, listener.callback, data);
   478 	listener.handler(listener.transactionID, listener.criteria, listener.callback, data);
   529 }
   479 };
   530 
       
   531 
       
   532 
   480 
   533 /*
   481 /*
   534  * ERROR CODES
   482  * ERROR CODES
   535  */
   483  */
   536 device.implementation.ERR_SUCCESS			 		= 0;
   484 device.implementation.ERR_SUCCESS			 		= 0;