|
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 function __device_commlog_descriptor(provider){ |
|
19 this.interfaceName = provider.interfaceName; |
|
20 this.version = provider.version; |
|
21 } |
|
22 |
|
23 function __device_commlog_getList(commlog_cb, match, ErrorCallback){ |
|
24 return this.provider.getList(commlog_cb, match, ErrorCallback); |
|
25 } |
|
26 |
|
27 function __device_commlog_setNotification(commlog_cb, ErrorCallback){ |
|
28 return this.provider.setNotification(commlog_cb, ErrorCallback); |
|
29 } |
|
30 |
|
31 function __device_commlog_cancelNotification( ){ |
|
32 return this.provider.cancelNotification( ); |
|
33 } |
|
34 |
|
35 function __device_commlog_cancel( transactionId ){ |
|
36 return this.provider.cancel( transactionId ); |
|
37 } |
|
38 |
|
39 function __device_commlog_deleteLogEntry( logId ){ |
|
40 return this.provider.deleteLogEntry( logId ); |
|
41 } |
|
42 |
|
43 // Private location prototype: called from service factory |
|
44 function __device_commlog(provider){ |
|
45 //alert("in providere") |
|
46 //Private properties |
|
47 this.provider = provider; |
|
48 //Read-only properties |
|
49 this.interfaceName = provider.descriptor.interfaceName; |
|
50 this.version = provider.descriptor.version; |
|
51 //Extended methods |
|
52 this.getList = __device_commlog_getList; |
|
53 this.setNotification = __device_commlog_setNotification; |
|
54 this.cancelNotification = __device_commlog_cancelNotification; |
|
55 this.cancel = __device_commlog_cancel; |
|
56 this.deleteLogEntry = __device_commlog_deleteLogEntry; |
|
57 } |
|
58 |
|
59 // commlog service interface |
|
60 |
|
61 var __device_commlog_service_entry = {"name": null, |
|
62 "version": null, |
|
63 "proto": __device_commlog, |
|
64 "descriptor": __device_commlog_descriptor, |
|
65 "providers": [{"descriptor": __sp_commlog_descriptor, "instance": __sp_commlog_instance}] |
|
66 }; |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 /* |
|
72 Copyright © 2009 Nokia. All rights reserved. |
|
73 Code licensed under the BSD License: |
|
74 Software License Agreement (BSD License) Copyright © 2009 Nokia. |
|
75 All rights reserved. |
|
76 Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
|
77 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
|
78 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
|
79 Neither the name of Nokia Corporation. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Nokia Corporation. |
|
80 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
81 version: 1.0 |
|
82 */ |
|
83 var invoker_notification; |
|
84 //var error = new DeviceException(0, 'dummy'); |
|
85 // S60 sp-based commlog provider |
|
86 |
|
87 |
|
88 |
|
89 function __sp_commlog_descriptor(){ |
|
90 //Read-only properties |
|
91 this.interfaceName = "commlog"; |
|
92 if (window.__Service_Interface_Ver) |
|
93 this.version = __Service_Interface_Ver; |
|
94 else |
|
95 this.version = 1.0; |
|
96 //Class-static properties |
|
97 } |
|
98 |
|
99 var __sp_commlog_type_constants = { |
|
100 "call": 0, |
|
101 "sms": 3 |
|
102 }; |
|
103 |
|
104 var __sp_commlog_constants = { |
|
105 "received": 0, // Incoming received |
|
106 "missed": 5, // Incoming missed |
|
107 "outgoing": 1 |
|
108 }; |
|
109 |
|
110 var __sp_commlog_constants_output = { |
|
111 "Received": 0, // Incoming received |
|
112 "Missed": 5, // Incoming missed |
|
113 "Outgoing": 1 |
|
114 }; |
|
115 |
|
116 /* |
|
117 * Array holding Connection objects for setNotification |
|
118 */ |
|
119 var __notifArr = new Array(); |
|
120 |
|
121 /* |
|
122 * Counter to hold number of setNotification calls |
|
123 */ |
|
124 var __notifCount = 0; |
|
125 |
|
126 /* |
|
127 * Object to hold connectionId and callback for setNotification |
|
128 */ |
|
129 __Notification.prototype = new Object(); |
|
130 __Notification.prototype.constructor = __Notification; |
|
131 |
|
132 /* |
|
133 * Constructor for Notification |
|
134 */ |
|
135 function __Notification(transactionId, callback){ |
|
136 this.connectionId = transactionId; |
|
137 this.callback = callback; |
|
138 |
|
139 } |
|
140 |
|
141 |
|
142 var __nofLogs; |
|
143 |
|
144 function __get_const_string(def, val){ |
|
145 var i; |
|
146 for (i in def) { |
|
147 if (def[i] == val) { |
|
148 return i; |
|
149 } |
|
150 } |
|
151 return null; |
|
152 } |
|
153 |
|
154 |
|
155 function __get_const_val(def, str){//alert(def+" "+str); |
|
156 if (def[str] != undefined) { |
|
157 return def[str]; |
|
158 } |
|
159 return null; //TBD: trow an exception on bad input |
|
160 } |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 // All of the event fields should normally be filled in, so don't make the returned event sparse |
|
167 |
|
168 function __device_commlog_item(sp_commlog){ |
|
169 if (!sp_commlog) { |
|
170 return null; |
|
171 } |
|
172 var evt = {}; |
|
173 evt.type = __get_const_string(__sp_commlog_type_constants, sp_commlog.EventType); |
|
174 if (evt.type == null || evt.type == undefined) |
|
175 return null; |
|
176 evt.phoneNumber = sp_commlog.PhoneNumber; |
|
177 if (evt.phoneNumber == null || evt.phoneNumber == undefined || evt.phoneNumber.length == 0) |
|
178 evt.phoneNumber = "private number"; |
|
179 evt.time = sp_commlog.EventTime; |
|
180 evt.flag = (sp_commlog.Direction == undefined) ? null : __get_const_string(__sp_commlog_constants_output, sp_commlog.Direction); |
|
181 evt.summary = sp_commlog.Description; |
|
182 evt.logId = Number(sp_commlog.id); |
|
183 evt.contactName = sp_commlog.RemoteParty; |
|
184 if (!evt.contactName) |
|
185 evt.contactName = evt.phoneNumber; |
|
186 return evt; |
|
187 } |
|
188 |
|
189 /* ------ Wrap sp iterator ------- */ |
|
190 function __sp_commlog_iterator_get_next(){ |
|
191 //__device_debug("sp_commlog_iterator_get_next"); |
|
192 //alert(__nofLogs); |
|
193 if (typeof __nofLogs == "number") { |
|
194 if (__nofLogs <= 0) { |
|
195 return null; |
|
196 } |
|
197 __nofLogs = __nofLogs - 1; |
|
198 } |
|
199 |
|
200 |
|
201 if ((typeof this.buffer == "object") && (this.buffer != null)) { |
|
202 var b1 = this.buffer; |
|
203 this.buffer = null; |
|
204 var rval1 = new __device_commlog_item(b1); |
|
205 return rval1; |
|
206 } |
|
207 else { |
|
208 var sp_commlog; |
|
209 if (this.iter != undefined && this.iter != null) { |
|
210 while (sp_commlog = this.iter.getNext()) { |
|
211 if (sp_commlog.EventType == 0 || sp_commlog.EventType == 3) |
|
212 break; |
|
213 } |
|
214 } |
|
215 |
|
216 if (typeof sp_commlog == "undefined") { |
|
217 return null; |
|
218 } |
|
219 var rval = new __device_commlog_item(sp_commlog); |
|
220 sp_commlog.close(); |
|
221 return rval; |
|
222 } |
|
223 |
|
224 |
|
225 // return sp_commlog; |
|
226 } |
|
227 |
|
228 function __sp_commlog_iterator_has_next(){ |
|
229 if (__nofLogs <= 0) |
|
230 return false; |
|
231 |
|
232 if (this.iter != undefined && this.iter != null) { |
|
233 while (this.buffer = this.iter.getNext()) { |
|
234 if (this.buffer.EventType == 0 || this.buffer.EventType == 3) |
|
235 break; |
|
236 } |
|
237 |
|
238 } |
|
239 |
|
240 |
|
241 if ((typeof this.buffer == "object") && (this.buffer != null)) { |
|
242 return true; |
|
243 } |
|
244 else { |
|
245 return false; |
|
246 } |
|
247 } |
|
248 |
|
249 function __sp_commlog_iterator_close(){ |
|
250 |
|
251 this.iter.close(); |
|
252 |
|
253 |
|
254 } |
|
255 |
|
256 function __sp_commlog_iterator(js_iterator){ |
|
257 this.iter = js_iterator; |
|
258 this.buffer = null; |
|
259 this.next = __sp_commlog_iterator_get_next; |
|
260 this.hasNext = __sp_commlog_iterator_has_next; |
|
261 this.close = __sp_commlog_iterator_close; |
|
262 this.nofLogs = __nofLogs; |
|
263 |
|
264 } |
|
265 |
|
266 function __sp_commlog_getList_cb(arg1, arg2, arg3){ |
|
267 var success_cb; |
|
268 var error_cb; |
|
269 var iter = null; |
|
270 var err_msg = null; |
|
271 |
|
272 var CbObj; |
|
273 |
|
274 |
|
275 CbObj = glob_obj.getFromArray(arg1); |
|
276 |
|
277 if (CbObj) { |
|
278 success_cb = CbObj.success_cb; |
|
279 error_cb = CbObj.error_cb; |
|
280 } |
|
281 |
|
282 else { |
|
283 alert("Commlog: __sp_commlog_getList_cb : Callback not found "); |
|
284 return; |
|
285 } |
|
286 |
|
287 |
|
288 if (arg3.ErrorCode != 0) { |
|
289 |
|
290 if (arg3.ErrorMessage) { |
|
291 err_msg = splitErrorMessage(arg3.ErrorMessage); |
|
292 } |
|
293 else { |
|
294 err_msg = "operation failed"; |
|
295 } |
|
296 |
|
297 if (error_cb) { |
|
298 setTimeout(function(){ |
|
299 error_cb(new DeviceException(MapErrorCode[arg3.ErrorCode], "Commlog: getList: " + err_msg)); |
|
300 }, 1000); |
|
301 return; |
|
302 } |
|
303 } |
|
304 else |
|
305 if (arg3.ReturnValue) { |
|
306 iter = new __sp_commlog_iterator(arg3.ReturnValue); |
|
307 } |
|
308 |
|
309 if (arg2 != event_cancelled) // 3 signifies eventcancelled |
|
310 { |
|
311 success_cb(iter); |
|
312 } |
|
313 glob_obj.removeFromArray(arg1); |
|
314 } |
|
315 |
|
316 function __sp_commlog_getList(commlog_success_cb, match, ErrorCallback){ |
|
317 //alert("in getlist"); |
|
318 |
|
319 if (commlog_success_cb == null || commlog_success_cb == undefined) { |
|
320 throw new DeviceException(this.error.MISSING_ARG_ERR, "CommLog:getList:callback is Required"); |
|
321 } |
|
322 |
|
323 else |
|
324 if (typeof commlog_success_cb != "function") { //here we check if the type of callback is function. This case is useful when arbitrary values are passed to callback |
|
325 throw new DeviceException(this.error.INVALID_ARG_ERR, "CommLog:getList:Invalid Callback"); |
|
326 } |
|
327 if (ErrorCallback) { |
|
328 if (typeof(ErrorCallback) != 'function') { |
|
329 throw new DeviceException(this.error.INVALID_ARG_ERR, "CommLog: getList: ErrorCallback is invalid"); |
|
330 } |
|
331 } |
|
332 |
|
333 if (match != null && match != undefined) { |
|
334 if (typeof match != "object" || __device_typeof(match) == "Array") { |
|
335 throw new DeviceException(this.error.INVALID_ARG_ERR, "CommLog: getList: Match is not an object"); |
|
336 } |
|
337 |
|
338 if (match.type != null && match.type != undefined) { |
|
339 if (typeof match.type != "string") { |
|
340 throw new DeviceException(this.error.INVALID_ARG_ERR, "CommLog: getList: Type is not a string"); |
|
341 } |
|
342 } |
|
343 |
|
344 if (match.flag != null && match.flag != undefined) { |
|
345 if (typeof match.flag != "string") { |
|
346 throw new DeviceException(this.error.INVALID_ARG_ERR, "CommLog: getList: Flag is not a string"); |
|
347 } |
|
348 |
|
349 if (match.type) { |
|
350 if (match.type.toLowerCase() == "sms" && match.flag.toLowerCase() == "missed") { |
|
351 if (ErrorCallback) { |
|
352 //alert("1111"); |
|
353 ErrorCallback(new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "commlogs: getList: Missed is not supported for sms")); |
|
354 //setTimeout(function(){ErrorCallback(new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "commlogs: getList: Missed is not supported for sms")); }, 1000); |
|
355 return; |
|
356 } |
|
357 else { |
|
358 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "commlogs: getList: Missed is not supported for sms"); |
|
359 |
|
360 } |
|
361 } |
|
362 } |
|
363 } |
|
364 |
|
365 if (match.nofLogs != null && match.nofLogs != undefined) { |
|
366 if (typeof match.nofLogs != "number") { |
|
367 throw new DeviceException(this.error.INVALID_ARG_ERR, "CommLog: getList: nofLogs is invalid"); |
|
368 } |
|
369 } |
|
370 } |
|
371 //alert("after input validation"); |
|
372 try { |
|
373 var criteria = {}; |
|
374 modifyObjectBaseProp(criteria); |
|
375 criteria.Type = 'Log'; |
|
376 criteria.Filter = {}; |
|
377 modifyObjectBaseProp(criteria.Filter); |
|
378 |
|
379 if (match) { |
|
380 //alert(match.type.toLowerCase()); |
|
381 if (match.type) { //Check it type is populated |
|
382 var typevalue; |
|
383 typevalue = __get_const_val(__sp_commlog_type_constants, match.type.toLowerCase()); |
|
384 //alert(typevalue); |
|
385 if (typevalue != undefined) { |
|
386 criteria.Filter.EventType = typevalue; |
|
387 } |
|
388 else { |
|
389 if (ErrorCallback) { |
|
390 //alert("22222222222" +this.error.DATA_OUT_OF_RANGE_ERR); |
|
391 ErrorCallback(new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "CommLog: getList: Type is out of range")); |
|
392 //setTimeout(function(){ ErrorCallback(new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "CommLog: getList: Type is out of range")); }, 1000); |
|
393 return; |
|
394 } |
|
395 else { |
|
396 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "CommLog: getList: Type is out of range"); |
|
397 } |
|
398 } |
|
399 } |
|
400 |
|
401 if (match.nofLogs != null && match.nofLogs != undefined) { |
|
402 if ((match.nofLogs < 0) || (match.nofLogs != (match.nofLogs | 0))) { |
|
403 if (ErrorCallback) { |
|
404 //alert("33333333333"); |
|
405 ErrorCallback(new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "CommLog: getList: nofLogs is out of range")); |
|
406 // setTimeout(function(){ ErrorCallback(new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "CommLog: getList: nofLogs is out of range")); }, 1000); |
|
407 return; |
|
408 } |
|
409 else { |
|
410 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "CommLog: getList: nofLogs is out of range"); |
|
411 } |
|
412 } |
|
413 __nofLogs = match.nofLogs; |
|
414 } |
|
415 if (match.flag) { //Check if flag is populated |
|
416 var directionvalue; |
|
417 directionvalue = __get_const_val(__sp_commlog_constants, match.flag.toLowerCase()); |
|
418 |
|
419 if (directionvalue != undefined) { |
|
420 criteria.Filter.Direction = directionvalue; |
|
421 } |
|
422 else { |
|
423 if (ErrorCallback) { |
|
424 /*setTimeout(function(){ |
|
425 //alert("444444444444"); |
|
426 ErrorCallback(new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "CommLog: getList: Flag is out of range")); |
|
427 }, 1000);*/ |
|
428 ErrorCallback(new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "CommLog: getList: Flag is out of range")); |
|
429 } |
|
430 else { |
|
431 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "CommLog: getList: Flag is out of range"); |
|
432 } |
|
433 } |
|
434 } |
|
435 |
|
436 if (match.phoneNumber != null && match.phoneNumber != undefined) { |
|
437 if (match.phoneNumber != "") //Check if phone is populated |
|
438 criteria.Filter.PhoneNumber = match.phoneNumber; |
|
439 } |
|
440 |
|
441 if (match.contactName != null && match.contactName != undefined) { |
|
442 if (match.contactName != "") |
|
443 criteria.Filter.RemoteParty = match.contactName; |
|
444 } |
|
445 |
|
446 if (match.startTime != null && match.startTime != undefined) { |
|
447 criteria.Filter.StartTime = match.startTime; |
|
448 } |
|
449 |
|
450 if (match.endTime != null && match.endTime != undefined) { |
|
451 criteria.Filter.EndTime = match.endTime; |
|
452 } |
|
453 } |
|
454 |
|
455 |
|
456 temp_scb = commlog_success_cb; |
|
457 temp_ecb = ErrorCallback; |
|
458 var result = this.so.IDataSource.GetList(criteria, this.getListCb); |
|
459 |
|
460 if (result.TransactionID) { |
|
461 glob_obj.addToGlobalArray(result.TransactionID, commlog_success_cb, ErrorCallback); |
|
462 } |
|
463 |
|
464 if (criteria.Filter) { |
|
465 delete criteria.Filter.Direction; |
|
466 delete criteria.Filter.EventType; |
|
467 delete criteria.Filter.PhoneNumber; |
|
468 } |
|
469 if (criteria) { |
|
470 delete criteria.Filter; |
|
471 delete criteria.Type; |
|
472 } |
|
473 |
|
474 if (result.ErrorCode != 0) { |
|
475 var err_msg = "operation failed"; |
|
476 if (result.ErrorMessage) { |
|
477 err_msg = splitErrorMessage(result.ErrorMessage); |
|
478 } |
|
479 switch (MapErrorCode[result.ErrorCode]) { |
|
480 case this.error.INVALID_ARG_ERR: |
|
481 case this.error.MISSING_ARG_ERR: |
|
482 case this.error.NOT_SUPPORTED_ERR: |
|
483 throw new DeviceException(MapErrorCode[result.ErrorCode], "CommLog:getList:" + err_msg); |
|
484 break; |
|
485 |
|
486 default: |
|
487 if (ErrorCallback) { |
|
488 |
|
489 ErrorCallback(new DeviceException(MapErrorCode[result.ErrorCode], "CommLog:getList:" + err_msg)); |
|
490 |
|
491 return; |
|
492 } |
|
493 else { |
|
494 throw new DeviceException(MapErrorCode[result.ErrorCode], "CommLog:getList:" + err_msg); |
|
495 } |
|
496 |
|
497 } |
|
498 } |
|
499 // //alert(result.TransactionID); |
|
500 return result.TransactionID; |
|
501 } |
|
502 catch (e) { |
|
503 __device_handle_exception(e, "__sp_commlog_Input_validation: " + e); |
|
504 } |
|
505 |
|
506 |
|
507 } |
|
508 |
|
509 function __sp_commlog_setNotification_cb(arg1, arg2, arg3){ |
|
510 var success_cb; |
|
511 var error_cb; |
|
512 var result = null; |
|
513 //alert("arg3.ReturnValue is "+arg3.ReturnValue+" "+arg3.ErrorCode); |
|
514 var CbObj; |
|
515 |
|
516 |
|
517 CbObj = glob_obj.getFromArray(arg1); |
|
518 |
|
519 if (CbObj) { |
|
520 success_cb = CbObj.success_cb; |
|
521 error_cb = CbObj.error_cb; |
|
522 } |
|
523 |
|
524 else { |
|
525 alert("Commlog: __sp_commlog_setNotification_cb : Callback not found "); |
|
526 return; |
|
527 } |
|
528 |
|
529 if (arg3.ErrorCode != 0) { |
|
530 if (arg3.ErrorMessage) { |
|
531 err_msg = splitErrorMessage(arg3.ErrorMessage); |
|
532 } |
|
533 else { |
|
534 err_msg = "operation failed"; |
|
535 } |
|
536 |
|
537 if (error_cb) { |
|
538 error_cb(new DeviceException(MapErrorCode[arg3.ErrorCode], "CommLog: getList: " + err_msg)); |
|
539 return; |
|
540 } |
|
541 } |
|
542 else |
|
543 if (arg3.ReturnValue) {//alert("in return value"); |
|
544 result = new __device_commlog_item(arg3.ReturnValue); |
|
545 } |
|
546 |
|
547 if (arg2 != event_cancelled) // 3 signifies eventcancelled |
|
548 {//alert("in not event cancelled"+" "+arg1 +" "+ __notifArr[0].connectionId); |
|
549 for (i in __notifArr) { |
|
550 if (arg1 == __notifArr[i].connectionId) { |
|
551 var found = __notifArr[i]; |
|
552 break; |
|
553 } |
|
554 } |
|
555 //alert(found); |
|
556 if (found) |
|
557 found.callback(result); |
|
558 } |
|
559 glob_obj.removeFromArray(arg1); |
|
560 } |
|
561 |
|
562 //TBD: implement these? |
|
563 |
|
564 function __sp_commlog_setNotification(successCallback, ErrorCallback){ |
|
565 |
|
566 if (!successCallback) { |
|
567 throw new DeviceException(this.error.MISSING_ARG_ERR, "CommLog:setNotification:callback is missing"); |
|
568 } |
|
569 |
|
570 if (typeof successCallback != "function") { |
|
571 throw new DeviceException(this.error.INVALID_ARG_ERR, "CommLog:setNotification:callback is invalid"); |
|
572 } |
|
573 |
|
574 if (ErrorCallback) { |
|
575 if (typeof(ErrorCallback) != 'function') { |
|
576 throw new DeviceException(this.error.INVALID_ARG_ERR, "CommLog: setNotification: ErrorCallback is invalid"); |
|
577 } |
|
578 } |
|
579 |
|
580 |
|
581 |
|
582 for (i in __notifArr) { |
|
583 var spliced = __notifArr[i]; |
|
584 __notifArr.splice(i, 1); |
|
585 __notifCount = __notifArr.length; |
|
586 |
|
587 this.so.IDataSource.Cancel({ |
|
588 TransactionID: spliced.connectionId |
|
589 }); |
|
590 break; |
|
591 } |
|
592 |
|
593 |
|
594 |
|
595 var criteria = {}; |
|
596 modifyObjectBaseProp(criteria); |
|
597 criteria.Type = "Log"; |
|
598 criteria.Filter = { |
|
599 DelayTime: 0 |
|
600 }; |
|
601 |
|
602 temp_scb = successCallback; |
|
603 temp_ecb = ErrorCallback; |
|
604 var result = this.so.IDataSource.RequestNotification(criteria, this.setNotificationCb); |
|
605 if (result.TransactionID) { |
|
606 glob_obj.addToGlobalArray(result.TransactionID, successCallback, ErrorCallback); |
|
607 } |
|
608 //alert("after call"); |
|
609 __notifArr[__notifCount++] = new __Notification(result.TransactionID, successCallback); |
|
610 //alert("after count"); |
|
611 if (criteria) { |
|
612 delete criteria.Type; |
|
613 } |
|
614 |
|
615 if (result.ErrorCode != 0) { |
|
616 var err_msg = "operation failed"; |
|
617 if (result.ErrorMessage) { |
|
618 err_msg = splitErrorMessage(result.ErrorMessage); |
|
619 } |
|
620 //alert(MapErrorCode[ result.ErrorCode ] ); |
|
621 switch (MapErrorCode[result.ErrorCode]) { |
|
622 case this.error.INVALID_ARG_ERR: |
|
623 case this.error.MISSING_ARG_ERR: |
|
624 case this.error.NOT_SUPPORTED_ERR: |
|
625 throw new DeviceException(MapErrorCode[result.ErrorCode], "CommLog:setNotification:" + err_msg); |
|
626 break; |
|
627 |
|
628 default: |
|
629 if (ErrorCallback) { |
|
630 setTimeout(function(){ |
|
631 ErrorCallback(new DeviceException(MapErrorCode[result.ErrorCode], "CommLog:setNotification:" + err_msg)); |
|
632 }, 1000); |
|
633 } |
|
634 else { |
|
635 throw new DeviceException(MapErrorCode[result.ErrorCode], "CommLog:setNotification:" + err_msg); |
|
636 } |
|
637 |
|
638 } |
|
639 } |
|
640 } |
|
641 |
|
642 function __sp_commlog_cancelNotification(){ |
|
643 //alert("in cancel notification"); |
|
644 |
|
645 for (i in __notifArr) {//alert("in array"); |
|
646 if (__notifArr[i].connectionId) { |
|
647 var spliced = __notifArr[i]; |
|
648 __notifArr.splice(i, 1); |
|
649 __notifCount = __notifArr.length; |
|
650 break; |
|
651 } |
|
652 } |
|
653 if (spliced) { |
|
654 var result = this.so.IDataSource.Cancel({ |
|
655 TransactionID: spliced.connectionId |
|
656 }); |
|
657 |
|
658 if (result.ErrorCode != 0) { |
|
659 var err_msg = "operation failed"; |
|
660 if (result.ErrorMessage) { |
|
661 err_msg = splitErrorMessage(result.ErrorMessage); |
|
662 } |
|
663 |
|
664 //throw new DeviceException (MapErrorCode[ result.ErrorCode ],"CommLog:cancelNotification:" + err_msg ); |
|
665 } |
|
666 } |
|
667 } |
|
668 |
|
669 function __sp_commlog_cancel(transactionId){//alert("in cancel"); |
|
670 if (!transactionId) { |
|
671 throw new DeviceException(this.error.MISSING_ARG_ERR, "CommLog:cancel:transactionId is missing"); |
|
672 } |
|
673 |
|
674 if (typeof transactionId != "number") { |
|
675 throw new DeviceException(this.error.INVALID_ARG_ERR, "CommLog:cancel:transactionId is invalid"); |
|
676 } |
|
677 |
|
678 var result = this.so.IDataSource.Cancel({ |
|
679 TransactionID: transactionId |
|
680 }); |
|
681 |
|
682 if (result.ErrorCode != 0) { |
|
683 var err_msg = "operation failed"; |
|
684 if (result.ErrorMessage) { |
|
685 err_msg = splitErrorMessage(result.ErrorMessage); |
|
686 } |
|
687 |
|
688 throw new DeviceException(MapErrorCode[result.ErrorCode], "CommLog:cancel:" + err_msg); |
|
689 } |
|
690 } |
|
691 |
|
692 function __sp_commlog_deleteLogEntry(logId){ |
|
693 |
|
694 if (logId == null || logId == undefined) { |
|
695 throw new DeviceException(this.error.MISSING_ARG_ERR, "CommLog:deleteLogEntry:logId is missing"); |
|
696 } |
|
697 |
|
698 if (typeof logId != "number") { |
|
699 throw new DeviceException(this.error.INVALID_ARG_ERR, "CommLog:deleteLogEntry:logId is invalid"); |
|
700 } |
|
701 |
|
702 var criteria = {}; |
|
703 modifyObjectBaseProp(criteria); |
|
704 criteria.Type = 'Log'; |
|
705 criteria.Data = { |
|
706 id: logId.toString() |
|
707 }; |
|
708 modifyObjectBaseProp(criteria.Data); |
|
709 |
|
710 var result = this.so.IDataSource.Delete(criteria); |
|
711 |
|
712 if (result.ErrorCode != 0) { |
|
713 var err_msg = "operation failed"; |
|
714 if (result.ErrorMessage) { |
|
715 err_msg = splitErrorMessage(result.ErrorMessage); |
|
716 } |
|
717 |
|
718 throw new DeviceException(MapErrorCode[result.ErrorCode], "CommLog:deleteLogEntry:" + err_msg); |
|
719 } |
|
720 } |
|
721 |
|
722 |
|
723 function __sp_commlog_instance(){ |
|
724 //alert("in instance"); |
|
725 |
|
726 //Descriptor |
|
727 this.descriptor = new __sp_commlog_descriptor(); |
|
728 |
|
729 //Extended methods |
|
730 this.getList = __sp_commlog_getList; |
|
731 this.getListCb = __sp_commlog_getList_cb; |
|
732 |
|
733 this.setNotification = __sp_commlog_setNotification; |
|
734 this.setNotificationCb = __sp_commlog_setNotification_cb; |
|
735 |
|
736 this.cancelNotification = __sp_commlog_cancelNotification; |
|
737 |
|
738 this.cancel = __sp_commlog_cancel; |
|
739 |
|
740 this.deleteLogEntry = __sp_commlog_deleteLogEntry; |
|
741 this.error = new DeviceException(0, "Dummy"); |
|
742 //Private data |
|
743 |
|
744 try { |
|
745 //__device_debug("Trying commlog service"); |
|
746 |
|
747 this.so = device.getServiceObject('Service.Logging', 'IDataSource'); |
|
748 //__device_debug("Got commlog service object: "); |
|
749 } |
|
750 catch (e) { |
|
751 this.so = null; |
|
752 __device_handle_exception(e, "commlog service not available"); |
|
753 } |
|
754 } |