|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Defination of class CCalendarInterface |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // sysinfo service interface |
|
20 var __device_sysinfo_service_entry = {"name": null, |
|
21 "version": null, |
|
22 "proto": __device_sysinfo, |
|
23 "descriptor": __device_sysinfo_descriptor, |
|
24 "providers": [{"descriptor": __sp_sysinfo_descriptor, "instance": __sp_sysinfo_instance}] |
|
25 }; |
|
26 |
|
27 |
|
28 // Private location prototype: called from service factory |
|
29 function __device_sysinfo(provider){ |
|
30 //alert("in provider"); |
|
31 //Private properties |
|
32 this.provider = provider; |
|
33 //Read-only properties |
|
34 this.interfaceName = provider.descriptor.interfaceName; |
|
35 this.version = provider.descriptor.version; |
|
36 //Extended methods |
|
37 this.getChannelList = __device_channels_get; |
|
38 this.getChannel = __device_sysinfo_get; |
|
39 this.startChannel = __device_sysinfo_setNotifier; |
|
40 this.stopChannel = __device_sysinfo_cancelNotifier; |
|
41 |
|
42 this.cancel = __device_sysinfo_cancel; |
|
43 } |
|
44 |
|
45 function __device_sysinfo_descriptor(provider){ |
|
46 this.interfaceName = provider.interfaceName; |
|
47 this.version = provider.version; |
|
48 } |
|
49 function __device_channels_get(){ |
|
50 return this.provider.getChannelList(); |
|
51 } |
|
52 |
|
53 function __device_sysinfo_get(channel, sysinfo_cb, ErrorCallback){ |
|
54 return this.provider.getChannel(channel, sysinfo_cb, ErrorCallback); |
|
55 } |
|
56 |
|
57 function __device_sysinfo_setNotifier( sysinfo_cb,channel, trigger, ErrorCallback){ |
|
58 return this.provider.startChannel(sysinfo_cb,channel,trigger, ErrorCallback); |
|
59 } |
|
60 |
|
61 function __device_sysinfo_cancelNotifier(channel){ |
|
62 return this.provider.stopChannel(channel); |
|
63 } |
|
64 |
|
65 function __device_sysinfo_cancel(id) { |
|
66 return this.provider.cancel(id); |
|
67 } |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 // S60 sp-based sysinfo provider |
|
74 /* |
|
75 var DATA_NOT_FOUND_ERR = 101; |
|
76 var DATA_OUT_OF_RANGE_ERR = 105; |
|
77 var NOT_ALLOWED_ERR = 106; |
|
78 //var error = new DeviceAPIError(); |
|
79 var error = new DeviceException(); |
|
80 */ |
|
81 function __sp_sysinfo_descriptor(){ |
|
82 //Read-only properties |
|
83 this.interfaceName = "sysinfo"; |
|
84 if(window.__Service_Interface_Ver) |
|
85 this.version =__Service_Interface_Ver; |
|
86 else |
|
87 this.version =1.0; |
|
88 //Class-static properties |
|
89 } |
|
90 |
|
91 function __sp_sysinfo_instance(){//alert("in instance"); |
|
92 //Descriptor |
|
93 this.descriptor = new __sp_sysinfo_descriptor(); |
|
94 //Extended methods |
|
95 this.getChannelList = __sp_channel_descriptors_get; |
|
96 this.getChannel = __sp_sysinfo_get; |
|
97 this.getChannelCb = __sp_sysinfo_get_cb; |
|
98 |
|
99 this.startChannel = __sp_sysinfo_setNotifier; |
|
100 this.stopChannel = __sp_sysinfo_cancelNotifier; |
|
101 this.cancel = __sp_sysinfo_cancel; |
|
102 this.error = new DeviceException(0, "Dummy"); |
|
103 try { |
|
104 //__device_debug("Trying sysinfo service"); |
|
105 this.so = device.getServiceObject('Service.SysInfo', 'ISysInfo'); |
|
106 //alert( this.so); |
|
107 //__device_debug("Got sysinfo service object: "); |
|
108 } |
|
109 catch (e) { |
|
110 this.so = null; |
|
111 //alert( this.so); |
|
112 __device_handle_exception(e, "Sysinfo service not available"); |
|
113 } |
|
114 } |
|
115 // Data format is |
|
116 // { |
|
117 // Entity: Network, Device, Features, Battery |
|
118 // Key: SignalStrength, RegistrationStatus, CurrentNetwork, CellID | IMEI|| ChargingStatus, BatteryStrength |
|
119 // [SystemData]: params |
|
120 // } |
|
121 |
|
122 function __sp_channel_descriptors_get(){ |
|
123 |
|
124 var __sp_channel_descriptors = [{ |
|
125 name: 'Charging', |
|
126 data: [{ |
|
127 name: 'chargingStatus', |
|
128 range: 'true or false', |
|
129 description: 'Charging(true) ,Not charging(false)', |
|
130 }], |
|
131 style: ["Sync", "Oneshot", "Notification"] |
|
132 }, { |
|
133 name: 'BluetoothOn', |
|
134 data: [{ |
|
135 name: 'btOn', |
|
136 range: 'true or false', |
|
137 description: 'BluetoothOn(true) ,BluetoothOff(false)', |
|
138 }], |
|
139 style: ["Sync", "Oneshot", "Notification"] |
|
140 }, { |
|
141 name: 'PhoneLanguage', |
|
142 data: [{ |
|
143 name: 'phoneLanguage', |
|
144 range: "", |
|
145 description: "", |
|
146 }], |
|
147 style: ["Sync", "Oneshot"] |
|
148 }, { |
|
149 name: 'ProductType', |
|
150 data: [{ |
|
151 name: 'productType', |
|
152 range: "", |
|
153 description: "", |
|
154 }], |
|
155 style: ["Sync", "Oneshot"] |
|
156 }, { |
|
157 name: 'FirmwareVersion', |
|
158 data: [{ |
|
159 name: 'firmwareVersion', |
|
160 range: "", |
|
161 description: "", |
|
162 }], |
|
163 style: ["Sync", "Oneshot"] |
|
164 }, { |
|
165 name: 'BatteryLevel', |
|
166 data: [{ |
|
167 name: "batteryLevel ", |
|
168 range: '0-100', |
|
169 description: 'Percent battery charge' |
|
170 }], |
|
171 style: ["Async", "Oneshot", "Notification"] |
|
172 }, { |
|
173 name: 'SignalStrength', |
|
174 data: [{ |
|
175 name: "signalStrength", |
|
176 range: '0-100', |
|
177 description: 'Signal Strength in Percentage' |
|
178 }], |
|
179 style: ["Async", "Oneshot", "Notification"] |
|
180 }, { |
|
181 name: 'Network', |
|
182 data: [{ |
|
183 name: "networkName ", |
|
184 description: "Network name" |
|
185 }, { |
|
186 name: "networkStatus", |
|
187 range: "Available,Current,Forbidden", |
|
188 description: "" |
|
189 }, { |
|
190 name: "networkMode", |
|
191 range: "ModeGsm,ModeCdma,ModeWcdma", |
|
192 description: "" |
|
193 }, { |
|
194 name: "mobileCountryCode", |
|
195 range: "", |
|
196 description: "" |
|
197 }, { |
|
198 name: "mobileNetworkCode", |
|
199 range: "", |
|
200 description: "" |
|
201 }, { |
|
202 name: "locationStatus", |
|
203 range: "True, False", |
|
204 description: "" |
|
205 }, { |
|
206 name: "areaCode", |
|
207 range: "", |
|
208 description: "" |
|
209 }, { |
|
210 name: "cellID", |
|
211 range: "", |
|
212 description: "" |
|
213 }], |
|
214 style: ["Async", "Oneshot", "Notification"] |
|
215 } , { |
|
216 name: 'IMEI', |
|
217 data: [{ |
|
218 name: "imei", |
|
219 range: "", |
|
220 description: "" |
|
221 }], |
|
222 style: ["Sync", "Oneshot"] |
|
223 } , { |
|
224 name: 'OutOfMemory', |
|
225 data: [{ |
|
226 name: "oomDrive", |
|
227 range: "", |
|
228 description: "" |
|
229 }], |
|
230 style: ["NA", "NA", "Notification"] |
|
231 }, { |
|
232 name: 'DeviceOrientation', |
|
233 data: [{ |
|
234 name: "deviceOrientation", |
|
235 range: "Landscape,Portrait", |
|
236 description: "" |
|
237 }], |
|
238 style: ["Sync", "Oneshot"] |
|
239 }, { |
|
240 name: 'RoamingFlag', |
|
241 data: [{ |
|
242 name: "roamingFlag", |
|
243 range: "", |
|
244 description: "" |
|
245 }], |
|
246 style: ["Sync", "Oneshot"] |
|
247 }, { |
|
248 name: 'DeviceInputMethod', |
|
249 data: [{ |
|
250 name: "deviceInputMethod", |
|
251 range: "Touch,NonTouch,Hybrid", |
|
252 description: "" |
|
253 }], |
|
254 style: ["Sync", "Oneshot"] |
|
255 }, { |
|
256 name: 'HomeNetwork', |
|
257 data: [{ |
|
258 name: "networkName ", |
|
259 description: "Network name" |
|
260 }, { |
|
261 name: "networkStatus", |
|
262 range: "Available,Current,Forbidden", |
|
263 description: "" |
|
264 }, { |
|
265 name: "networkMode", |
|
266 range: "ModeGsm,ModeCdma,ModeWcdma", |
|
267 description: "" |
|
268 }, { |
|
269 name: "mobileCountryCode", |
|
270 range: "", |
|
271 description: "" |
|
272 }, { |
|
273 name: "mobileNetworkCode", |
|
274 range: "", |
|
275 description: "" |
|
276 }, { |
|
277 name: "locationStatus", |
|
278 range: "True, False", |
|
279 description: "" |
|
280 }, { |
|
281 name: "areaCode", |
|
282 range: "", |
|
283 description: "" |
|
284 }, { |
|
285 name: "cellID", |
|
286 range: "", |
|
287 description: "" |
|
288 }], |
|
289 style: ["Async", "Oneshot", "Notification"] |
|
290 }]; |
|
291 return __sp_channel_descriptors; |
|
292 } |
|
293 |
|
294 var max = 110; |
|
295 var min = 40; |
|
296 var diff = max-min; |
|
297 function __sp_device_sysinfo_toDecibel(trigger) { |
|
298 var percentage = trigger/100; |
|
299 var decibel = max - (percentage * diff); |
|
300 decibel = Math.round(decibel); |
|
301 return decibel; |
|
302 } |
|
303 |
|
304 function __sp_device_sysinfo_toPercentage(signalStatus) { |
|
305 if(signalStatus == 0){ |
|
306 return signalStatus; |
|
307 } |
|
308 else{ |
|
309 var numerator = max - signalStatus; |
|
310 var percentage = numerator/diff; |
|
311 percentage *= 100; |
|
312 percentage = Math.round(percentage); |
|
313 return percentage; |
|
314 } |
|
315 } |
|
316 |
|
317 function __sp_device_sysinfo_toBool(chargeStatus) { |
|
318 if(chargeStatus == 0){ |
|
319 return false; |
|
320 } |
|
321 else{ |
|
322 return true; |
|
323 } |
|
324 } |
|
325 |
|
326 function mappingVerification(errorCode) { |
|
327 if(errorCode == 1016 || errorCode == 1012 || errorCode == 1010 || errorCode == 1009 || errorCode == 1005 || errorCode == 1000 || errorCode == 1011 || errorCode == 1007 || errorCode == 1003 || errorCode == 1002){ |
|
328 return true; |
|
329 } |
|
330 else{ |
|
331 return false; |
|
332 } |
|
333 } |
|
334 |
|
335 function __sp_device_sysinfo_extract(sysinfo){ |
|
336 |
|
337 var channel = sysinfo.Key; |
|
338 //alert("inside extract , channel "+channel); |
|
339 var dataMap = {}; |
|
340 modifyObjectBaseProp(dataMap); |
|
341 try { |
|
342 switch (channel) { |
|
343 case "ChargingStatus": |
|
344 dataMap.chargingStatus = __sp_device_sysinfo_toBool(sysinfo.Status); |
|
345 break; |
|
346 |
|
347 case "BatteryStrength": |
|
348 dataMap.batteryLevel = sysinfo.Status; |
|
349 //alert(dataMap.batteryLevel); |
|
350 break; |
|
351 |
|
352 case "SignalStrength": |
|
353 dataMap.signalStrength = __sp_device_sysinfo_toPercentage(sysinfo.Status); |
|
354 break; |
|
355 |
|
356 case "CurrentNetwork": |
|
357 var status; |
|
358 var mode; |
|
359 switch(sysinfo.NetworkStatus) |
|
360 { |
|
361 case 0: |
|
362 status = "Available"; |
|
363 break; |
|
364 case 1: |
|
365 status = "Current"; |
|
366 break; |
|
367 case 2: |
|
368 status = "Forbidden"; |
|
369 break; |
|
370 default: |
|
371 status = "Unknown"; |
|
372 break; |
|
373 } |
|
374 |
|
375 switch(sysinfo.NetworkMode) { |
|
376 case 1: |
|
377 mode = "ModeGsm"; |
|
378 break; |
|
379 case 3: |
|
380 case 4: |
|
381 mode = "ModeCdma"; |
|
382 break; |
|
383 case 5: |
|
384 mode = "ModeWcdma"; |
|
385 break; |
|
386 default: |
|
387 mode = "Unknown"; |
|
388 break; |
|
389 } |
|
390 dataMap.networkName = sysinfo.NetworkName; |
|
391 dataMap.networkStatus = status; |
|
392 dataMap.networkMode = mode; |
|
393 dataMap.mobileCountryCode = sysinfo.CountryCode; |
|
394 dataMap.mobileNetworkCode = sysinfo.NetworkCode; |
|
395 dataMap.locationStatus = sysinfo.LocationStatus; |
|
396 dataMap.areaCode = sysinfo.AreaCode; |
|
397 dataMap.cellID = sysinfo.CellId; |
|
398 break; |
|
399 |
|
400 case "DisplayLanguage" : |
|
401 dataMap.phoneLanguage = sysinfo.StringData; |
|
402 break; |
|
403 |
|
404 case "BlueTooth" : |
|
405 dataMap.btOn = __sp_device_sysinfo_toBool(sysinfo.Status); |
|
406 break; |
|
407 |
|
408 case "ProductType": |
|
409 dataMap.productType = sysinfo.StringData; |
|
410 break; |
|
411 |
|
412 case "FirmwareVersion" : |
|
413 dataMap.firmwareVersion = sysinfo.StringData; |
|
414 break; |
|
415 |
|
416 case "DeviceInputMethod" : |
|
417 dataMap.deviceInputMethod = sysinfo.StringData; |
|
418 break; |
|
419 |
|
420 default : |
|
421 dataMap = sysinfo; |
|
422 break; |
|
423 } |
|
424 return dataMap; |
|
425 } |
|
426 |
|
427 catch (e) { |
|
428 __device_handle_exception(e, "__sp_device_sysinfo_extract: " + e); |
|
429 } |
|
430 } |
|
431 |
|
432 function __sp_sysinfo_get_cb(arg1, arg2, arg3){//alert("in callback of wrapper"); |
|
433 var success_cb ; |
|
434 var error_cb ; |
|
435 var CbObj; |
|
436 |
|
437 |
|
438 CbObj = glob_obj.getFromArray(arg1); |
|
439 |
|
440 |
|
441 |
|
442 if (CbObj) { |
|
443 success_cb = CbObj.success_cb; |
|
444 error_cb = CbObj.error_cb; |
|
445 } |
|
446 |
|
447 else { |
|
448 alert("Sysinfo: __sp_sysinfo_get_cb: Callback not found "); |
|
449 return; |
|
450 } |
|
451 |
|
452 var op = null; |
|
453 if(arg3.ErrorCode != 0){ |
|
454 var err_msg = splitErrorMessage(arg3.ErrorMessage); |
|
455 error_cb(new DeviceException(MapErrorCode[arg3.ErrorCode], "SysInfo:getChannel: "+err_msg )); |
|
456 } |
|
457 else if (arg3.ReturnValue) { |
|
458 //alert("returnvalue is"+arg3.ReturnValue); |
|
459 op = __sp_device_sysinfo_extract(arg3.ReturnValue); |
|
460 arg3.ReturnValue.close(); |
|
461 success_cb(op); |
|
462 } |
|
463 glob_obj.removeFromArray(arg1); |
|
464 } |
|
465 |
|
466 function __sp_sysinfo_get(channel, sysinfo_success_cb, ErrorCallback){ |
|
467 var so; |
|
468 var rval; |
|
469 |
|
470 |
|
471 //---------------Function not in use------------------- |
|
472 /*var cell_id_invoker = function(arg1, arg2, arg3){ |
|
473 var op = null; |
|
474 if (arg3.ReturnValue) { |
|
475 op = arg3.ReturnValue; |
|
476 arg3.ReturnValue.close(); |
|
477 } |
|
478 sysinfo_success_cb(arg1, arg3.ErrorCode, op); |
|
479 so.ISysInfo.Cancel(arg1); |
|
480 };*/ |
|
481 //----------------------------------------------------------- |
|
482 var async = false; |
|
483 var rdata = "Status"; |
|
484 var rvalSync; |
|
485 var sys_req = {}; |
|
486 modifyObjectBaseProp(sys_req); |
|
487 try { |
|
488 switch (channel) { |
|
489 case "Charging": |
|
490 sys_req.Entity = "Battery"; |
|
491 sys_req.Key = "ChargingStatus"; |
|
492 break; |
|
493 case "BatteryLevel": |
|
494 sys_req.Entity = "Battery"; |
|
495 sys_req.Key = "BatteryStrength"; |
|
496 async = true; |
|
497 break; |
|
498 case "SignalStrength": |
|
499 sys_req.Entity = "Network"; |
|
500 sys_req.Key = "SignalStrength"; |
|
501 async = true; |
|
502 break; |
|
503 case "Network": |
|
504 sys_req.Entity = "Network"; |
|
505 sys_req.Key = "CurrentNetwork"; |
|
506 async = true; |
|
507 break; |
|
508 case "PhoneLanguage": |
|
509 sys_req.Entity = "General"; |
|
510 sys_req.Key = "DisplayLanguage"; |
|
511 break; |
|
512 case "BluetoothOn": |
|
513 sys_req.Entity = "Connectivity"; |
|
514 sys_req.Key = "BlueTooth"; |
|
515 break; |
|
516 case "ProductType": |
|
517 sys_req.Entity = "Device"; |
|
518 sys_req.Key = "ProductType"; |
|
519 break; |
|
520 case "FirmwareVersion": |
|
521 sys_req.Entity = "Device"; |
|
522 sys_req.Key = "FirmwareVersion"; |
|
523 break; |
|
524 |
|
525 case "DeviceInputMethod": |
|
526 sys_req.Entity = "Device"; |
|
527 sys_req.Key = "DeviceInputMethod"; |
|
528 break; |
|
529 default: |
|
530 if (channel == null) { |
|
531 throw new DeviceException(this.error.MISSING_ARG_ERR, "SysInfo:getChannel:channel is missing" ); |
|
532 } |
|
533 else { |
|
534 if (typeof channel != "string"){ |
|
535 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:getChannel:channel is of invalid type"); |
|
536 } |
|
537 else { |
|
538 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:getChannel:channel is invalid"); |
|
539 } |
|
540 } |
|
541 } |
|
542 |
|
543 if (async) { |
|
544 if (sysinfo_success_cb == null) { |
|
545 throw new DeviceException( this.error.MISSING_ARG_ERR, "SysInfo:getChannel:callback is missing"); |
|
546 } |
|
547 if (typeof sysinfo_success_cb != "function"){ |
|
548 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:getChannel:callback is invalid" ); |
|
549 } |
|
550 if(ErrorCallback){ |
|
551 if(typeof(ErrorCallback) != 'function'){ |
|
552 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:getChannel: ErrorCallback is invalid" ); |
|
553 } |
|
554 } |
|
555 temp_scb = sysinfo_success_cb; |
|
556 temp_ecb = ErrorCallback; |
|
557 rval = this.so.ISysInfo.GetInfo(sys_req, this.getChannelCb); |
|
558 if (rval.TransactionID) { |
|
559 glob_obj.addToGlobalArray(rval.TransactionID, sysinfo_success_cb, ErrorCallback); |
|
560 } |
|
561 if (rval.ErrorCode != 0) { |
|
562 var doMap = mappingVerification(rval.ErrorCode); |
|
563 if(doMap) { |
|
564 switch(MapErrorCode[rval.ErrorCode]) |
|
565 { |
|
566 case this.error.MISSING_ARG_ERR : |
|
567 case this.error.INVALID_ARG_ERR : |
|
568 if(rval.ErrorMessage) { |
|
569 var err_msg = splitErrorMessage(rval.ErrorMessage); |
|
570 throw new DeviceException(MapErrorCode[rval.ErrorCode], "SysInfo: getChannel: "+err_msg ); |
|
571 } |
|
572 else { |
|
573 throw new DeviceException(MapErrorCode[rval.ErrorCode], "SysInfo:getChannel:Operation Failed" ); |
|
574 } |
|
575 break; |
|
576 default: |
|
577 sysinfo_success_cb(0) ; |
|
578 } |
|
579 } |
|
580 else { |
|
581 sysinfo_success_cb(0) ; |
|
582 } |
|
583 } |
|
584 |
|
585 return rval.TransactionID; |
|
586 } |
|
587 else { |
|
588 rval = this.so.ISysInfo.GetInfo(sys_req); |
|
589 if (rval.ErrorCode != 0) { |
|
590 if(rval.ErrorMessage) { |
|
591 var err_msg1 = splitErrorMessage(rval.ErrorMessage); |
|
592 throw new DeviceException(MapErrorCode[rval.ErrorCode], "SysInfo: getChannel: "+err_msg1 ); |
|
593 } |
|
594 else { |
|
595 throw new DeviceException(MapErrorCode[rval.ErrorCode], "SysInfo:getChannel:Operation Failed" ); |
|
596 } |
|
597 } |
|
598 rvalSync = __sp_device_sysinfo_extract(rval.ReturnValue); |
|
599 return rvalSync; |
|
600 } |
|
601 delete sys_req; |
|
602 } |
|
603 catch (e) { |
|
604 __device_handle_exception(e, "__sp_sysinfo_get: getChannel: " + e); |
|
605 } |
|
606 } |
|
607 |
|
608 // channels |
|
609 var __cell_id_channel = { |
|
610 scb: null, |
|
611 ecb: null, |
|
612 cancel_id: null |
|
613 }; |
|
614 |
|
615 function __cell_id_channel_cb(arg1, arg2, arg3){ |
|
616 var op = null; |
|
617 if(arg3.ErrorCode){ |
|
618 __cell_id_channel.ecb(arg3.ErrorCode); |
|
619 } |
|
620 else if (arg3.ReturnValue) { |
|
621 op = arg3.ReturnValue; |
|
622 arg3.ReturnValue.close(); |
|
623 __cell_id_channel.scb(op); |
|
624 } |
|
625 } |
|
626 |
|
627 var __charging_status_channel = { |
|
628 scb: null, |
|
629 ecb: null, |
|
630 cancel_id: null |
|
631 }; |
|
632 function __charging_status_channel_cb(arg1, arg2, arg3){ |
|
633 var op = null; |
|
634 if(arg3.ErrorCode){ |
|
635 __charging_status_channel.ecb(arg3.ErrorCode); |
|
636 } |
|
637 else if (arg3.ReturnValue) { |
|
638 op = __sp_device_sysinfo_extract(arg3.ReturnValue); |
|
639 arg3.ReturnValue.close(); |
|
640 __charging_status_channel.scb(op); |
|
641 } |
|
642 } |
|
643 |
|
644 |
|
645 var __net_coverage_channel = { |
|
646 scb: null, |
|
647 ecb: null, |
|
648 cancel_id: null |
|
649 }; |
|
650 function __net_coverage_channel_cb(arg1, arg2, arg3){ |
|
651 var op = null; |
|
652 if(arg3.ErrorCode){ |
|
653 __net_coverage_channel.ecb(arg3.ErrorCode); |
|
654 } |
|
655 else if (arg3.ReturnValue) { |
|
656 op = __sp_device_sysinfo_extract(arg3.ReturnValue); |
|
657 arg3.ReturnValue.close(); |
|
658 __net_coverage_channel.scb(op); |
|
659 } |
|
660 } |
|
661 |
|
662 var __battery_level_channel = { |
|
663 scb: null, |
|
664 ecb: null, |
|
665 cancel_id: null |
|
666 }; |
|
667 function __battery_level_channel_cb(arg1, arg2, arg3){ |
|
668 var op = null; |
|
669 if(arg3.ErrorCode){ |
|
670 __battery_level_channel.ecb(arg3.ErrorCode); |
|
671 } |
|
672 else if (arg3.ReturnValue) { |
|
673 op = __sp_device_sysinfo_extract(arg3.ReturnValue); |
|
674 arg3.ReturnValue.close(); |
|
675 __battery_level_channel.scb(op); |
|
676 } |
|
677 } |
|
678 |
|
679 var __bluetooth_on_channel = { |
|
680 scb: null, |
|
681 ecb: null, |
|
682 cancel_id: null |
|
683 }; |
|
684 function __bluetooth_on_channel_cb(arg1, arg2, arg3){ |
|
685 var op = null; |
|
686 if(arg3.ErrorCode){ |
|
687 __bluetooth_on_channel.ecb(arg3.ErrorCode); |
|
688 } |
|
689 else if (arg3.ReturnValue) { |
|
690 op = __sp_device_sysinfo_extract(arg3.ReturnValue); |
|
691 arg3.ReturnValue.close(); |
|
692 __bluetooth_on_channel.scb(op); |
|
693 } |
|
694 } |
|
695 |
|
696 |
|
697 var __signal_channel = { |
|
698 scb: null, |
|
699 ecb: null, |
|
700 cancel_id: null |
|
701 }; |
|
702 |
|
703 |
|
704 function __signal_channel_cb(arg1, arg2, arg3){ |
|
705 |
|
706 var op = null; |
|
707 if(arg3.ErrorCode){ |
|
708 __signal_channel.ecb(arg3.ErrorCode); |
|
709 } |
|
710 else if (arg3.ReturnValue) { |
|
711 op = __sp_device_sysinfo_extract(arg3.ReturnValue); |
|
712 arg3.ReturnValue.close(); |
|
713 __signal_channel.scb(op); |
|
714 } |
|
715 } |
|
716 |
|
717 |
|
718 function __sp_sysinfo_setNotifier(sysinfo_success_cb, channel_name, trigger, ErrorCallback){ |
|
719 var rval; |
|
720 var channel = null; |
|
721 var cb = null; |
|
722 var sys_req = {}; |
|
723 |
|
724 |
|
725 if (sysinfo_success_cb == null) { |
|
726 throw new DeviceException(this.error.MISSING_ARG_ERR, "SysInfo:startChannel:callback is missing" ); |
|
727 } |
|
728 if (typeof sysinfo_success_cb != "function") { |
|
729 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:startChannel:callback is invalid" ); |
|
730 } |
|
731 |
|
732 |
|
733 modifyObjectBaseProp(sys_req); |
|
734 try { |
|
735 switch (channel_name) { |
|
736 case "Charging": |
|
737 sys_req.Entity = "Battery"; |
|
738 sys_req.Key = "ChargingStatus"; |
|
739 channel = __charging_status_channel; |
|
740 cb = __charging_status_channel_cb; |
|
741 break; |
|
742 case "Network": |
|
743 sys_req.Entity = "Network"; |
|
744 sys_req.Key = "CurrentNetwork"; |
|
745 channel = __net_coverage_channel; |
|
746 cb = __net_coverage_channel_cb; |
|
747 break; |
|
748 case "BatteryLevel": |
|
749 sys_req.Entity = "Battery"; |
|
750 sys_req.Key = "BatteryStrength"; |
|
751 sys_req.SystemData = {}; |
|
752 modifyObjectBaseProp(sys_req.SystemData); |
|
753 if (trigger == null) { |
|
754 trigger = 50; |
|
755 } |
|
756 if(!(trigger>=0 && trigger<=100)){ |
|
757 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "SysInfo:startChannel:trigger is out of range" ); |
|
758 } |
|
759 if(typeof trigger != "number"){ |
|
760 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:startChannel:trigger is of invalid type" ); |
|
761 } |
|
762 sys_req.SystemData.Status = trigger; |
|
763 channel = __battery_level_channel; |
|
764 cb = __battery_level_channel_cb; |
|
765 break; |
|
766 case "SignalStrength": |
|
767 sys_req.Entity = "Network"; |
|
768 sys_req.Key = "SignalStrength"; |
|
769 sys_req.SystemData = {}; |
|
770 modifyObjectBaseProp(sys_req.SystemData); |
|
771 if (trigger != null) { |
|
772 if(!(trigger>=0 && trigger<=100)){ |
|
773 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "SysInfo:startChannel:trigger is out of range" ); |
|
774 } |
|
775 if(typeof trigger != "number"){ |
|
776 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:startChannel:trigger is of invalid type" ); |
|
777 } |
|
778 sys_req.SystemData.Status = __sp_device_sysinfo_toDecibel(trigger); |
|
779 } |
|
780 channel = __signal_channel; |
|
781 cb = __signal_channel_cb; |
|
782 break; |
|
783 case "BluetoothOn": |
|
784 sys_req.Entity = "Connectivity"; |
|
785 sys_req.Key = "BlueTooth"; |
|
786 channel = __bluetooth_on_channel; |
|
787 cb = __bluetooth_on_channel_cb; |
|
788 break; |
|
789 default: |
|
790 var error; |
|
791 if (channel_name == null) { |
|
792 throw new DeviceException(this.error.MISSING_ARG_ERR, "SysInfo:startChannel:channel is missing" ); |
|
793 } |
|
794 else { |
|
795 if (typeof channel_name != "string"){ |
|
796 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:startChannel:channel is of invalid type" ); |
|
797 } |
|
798 else { |
|
799 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:startChannel:channel is invalid" ); |
|
800 } |
|
801 } |
|
802 if(sys_req.SystemData){ |
|
803 delete sys_req.SystemData; |
|
804 } |
|
805 } |
|
806 |
|
807 channel.scb = sysinfo_success_cb; |
|
808 |
|
809 channel.ecb = ErrorCallback; |
|
810 |
|
811 if(channel.ecb){ |
|
812 if(typeof(channel.ecb) != 'function'){ |
|
813 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:startChannel: ErrorCallback is invalid" ); |
|
814 } |
|
815 } |
|
816 if (channel.cancel_id) { |
|
817 var cancelParams = {}; |
|
818 modifyObjectBaseProp(cancelParams); |
|
819 cancelParams.TransactionID = channel.cancel_id; |
|
820 this.so.ISysInfo.Cancel(cancelParams); |
|
821 channel.cancel_id = null; |
|
822 delete cancelParams; |
|
823 } |
|
824 temp_scb = sysinfo_success_cb; |
|
825 temp_ecb = ErrorCallback; |
|
826 rval = this.so.ISysInfo.GetNotification(sys_req, cb); |
|
827 |
|
828 delete sys_req; |
|
829 if (rval.ErrorCode != 0) { |
|
830 switch(MapErrorCode[rval.ErrorCode]) |
|
831 { |
|
832 case this.error.MISSING_ARG_ERR : |
|
833 case this.error.INVALID_ARG_ERR : |
|
834 if(rval.ErrorMessage) { |
|
835 var err_msg = splitErrorMessage(rval.ErrorMessage); |
|
836 throw new DeviceException(MapErrorCode[rval.ErrorCode], "SysInfo: startChannel: "+err_msg ); |
|
837 } |
|
838 else { |
|
839 throw new DeviceException(MapErrorCode[rval.ErrorCode], "SysInfo:startChannel:Operation Failed" ); |
|
840 } |
|
841 break; |
|
842 default: |
|
843 sysinfo_success_cb(0) ; |
|
844 } |
|
845 } |
|
846 channel.cancel_id = rval.TransactionID; |
|
847 return channel.cancel_id; |
|
848 } |
|
849 |
|
850 catch (e) { |
|
851 __device_handle_exception(e, "__sp_sysinfo_startChannel: " + e); |
|
852 } |
|
853 } |
|
854 |
|
855 function __sp_sysinfo_cancelNotifier(channel_name){ |
|
856 try { |
|
857 switch (channel_name) { |
|
858 case "CellId": |
|
859 channel = __cell_id_channel; |
|
860 break; |
|
861 case "Charging": |
|
862 channel = __charging_status_channel; |
|
863 break; |
|
864 case "Network": |
|
865 channel = __net_coverage_channel; |
|
866 break; |
|
867 case "BatteryLevel": |
|
868 channel = __battery_level_channel; |
|
869 break; |
|
870 case "SignalStrength": |
|
871 channel = __signal_channel; |
|
872 break; |
|
873 case "BluetoothOn": |
|
874 channel = __bluetooth_on_channel; |
|
875 break; |
|
876 default: |
|
877 var error; |
|
878 if (channel_name == null) { |
|
879 throw new DeviceException(this.error.MISSING_ARG_ERR, "SysInfo:stopChannel:channel is missing" ); |
|
880 } |
|
881 else { |
|
882 if (typeof channel_name != "string") { |
|
883 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:stopChannel:channel is of invalid type" ); |
|
884 } |
|
885 else{ |
|
886 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:stopChannel:channel is invalid" ); |
|
887 } |
|
888 } |
|
889 } |
|
890 if (channel.cancel_id) { |
|
891 var cancelParams = {}; |
|
892 modifyObjectBaseProp(cancelParams); |
|
893 cancelParams.TransactionID = channel.cancel_id; |
|
894 var retval = this.so.ISysInfo.Cancel(cancelParams); |
|
895 delete cancelParams; |
|
896 if(retval.ErrorCode != 0) { |
|
897 if(retval.ErrorMessage) { |
|
898 var err_msg = splitErrorMessage(retval.ErrorMessage); |
|
899 throw new DeviceException(MapErrorCode[retval.ErrorCode], "SysInfo: stopChannel: "+err_msg ); |
|
900 } |
|
901 else { |
|
902 throw new DeviceException(MapErrorCode[retval.ErrorCode], "SysInfo:stopChannel:Operation Failed" ); |
|
903 } |
|
904 } |
|
905 channel.cancel_id = null; |
|
906 } |
|
907 else { |
|
908 throw new DeviceException(this.error.DATA_NOT_FOUND_ERR, "SysInfo:stopChannel:channel not started" ); |
|
909 } |
|
910 } |
|
911 catch (e) { |
|
912 __device_handle_exception(e, "__sp_sysinfo_stopChannel: " + e); |
|
913 } |
|
914 } |
|
915 |
|
916 function __sp_sysinfo_cancel(cancel_Id) { |
|
917 try { |
|
918 var cancelFlag = 0; |
|
919 |
|
920 if(cancel_Id == null) { |
|
921 throw new DeviceException(this.error.MISSING_ARG_ERR, "SysInfo:cancel:Id is missing" ); |
|
922 } |
|
923 |
|
924 if(typeof cancel_Id != "number") { |
|
925 throw new DeviceException(this.error.INVALID_ARG_ERR, "SysInfo:cancel:Id is of invalid type" ); |
|
926 } |
|
927 |
|
928 if (cancel_Id == __charging_status_channel.cancel_id || cancel_Id == __net_coverage_channel.cancel_id || cancel_Id == __battery_level_channel.cancel_id || cancel_Id == __bluetooth_on_channel.cancel_id || cancel_Id == __signal_channel.cancel_id){ |
|
929 cancelFlag = 1; |
|
930 } |
|
931 |
|
932 if (cancelFlag != 1) { |
|
933 var cancelParam = { |
|
934 TransactionID: cancel_Id |
|
935 }; |
|
936 var retval = this.so.ISysInfo.Cancel(cancelParam); |
|
937 if (retval.ErrorCode != 0) { |
|
938 if (retval.ErrorMessage) { |
|
939 var err_msg = splitErrorMessage(retval.ErrorMessage);//alert("err_msg_my"+err_msg); |
|
940 throw new DeviceException( this.error.INVALID_ARG_ERR, "SysInfo:cancel: " + err_msg); |
|
941 } |
|
942 else { |
|
943 throw new DeviceException(MapErrorCode[retval.ErrorCode],"SysInfo:cancel:Operation Failed" ); |
|
944 } |
|
945 } |
|
946 } |
|
947 |
|
948 else { |
|
949 cancelFlag = 0; |
|
950 throw new DeviceException(this.error.NOT_ALLOWED_ERR,"SysInfo:cancel:Cannot Cancel a channel started using startChannel "); |
|
951 } |
|
952 } |
|
953 catch (e) { |
|
954 __device_handle_exception(e, "__sp_sysinfo_cancel: " + e); |
|
955 } |
|
956 } |