serviceproviders/jsapi/platformservices/src/landmarks.js
changeset 27 02682e02e51f
child 34 5dae2c62e9b6
equal deleted inserted replaced
26:5d0ec8b709be 27:02682e02e51f
       
     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 // Namepace: com.nokia.device.service
       
    19 
       
    20 var __device_landmarks_service_entry = {
       
    21     "name": null,
       
    22     "version": null,
       
    23     "proto": __device_landmarks,
       
    24     "descriptor": __device_landmarks_descriptor,
       
    25     "providers": [{
       
    26         "descriptor": __sp_landmarks_descriptor,
       
    27         "instance": __sp_landmarks_instance
       
    28     }]
       
    29 };
       
    30 
       
    31 // Private location prototype: called from service factory
       
    32 function __device_landmarks(provider){
       
    33     //Private properties
       
    34     this.provider = provider;
       
    35     //Read-only properties
       
    36     this.interfaceName = provider.descriptor.interfaceName;
       
    37     this.version = provider.descriptor.version;
       
    38     //Core methods
       
    39     this.startEditor = __device_landmarks_startEditor;
       
    40     //Extended methods
       
    41     this.getCategories = __device_landmarks_getCategories;
       
    42     this.getLandmarks = __device_landmarks_getLandmarks;
       
    43     this.addCategory = __device_landmarks_add_category;
       
    44     this.updateCategory = __device_landmarks_update_category;
       
    45     this.updateLandmark = __device_landmarks_update_landmark;
       
    46     this.addLandmark = __device_landmarks_add_landmark;
       
    47     this.deleteCategory = __device_landmarks_delete_category;
       
    48     this.deleteLandmark = __device_landmarks_delete_landmark;
       
    49     this.importLandmarks = __device_landmarks_import_landmarks;
       
    50     this.exportLandmarks = __device_landmarks_export_landmarks;
       
    51     this.organizeLandmarks = __device_landmarks_organize_landmarks;
       
    52     ;
       
    53     this.cancel = __device_landmarks_cancel;
       
    54 }
       
    55 
       
    56 function __device_landmarks_descriptor(provider){
       
    57     this.interfaceName = provider.interfaceName;
       
    58     this.version = provider.version;
       
    59 }
       
    60 
       
    61 function __device_landmarks_startEditor(callback, entry){
       
    62     this.provider.startEditor(callback, entry);
       
    63 }
       
    64 
       
    65 function __device_landmarks_getCategories(callback, name, errorcb){
       
    66     return this.provider.getCategories(callback, name, errorcb);
       
    67 }
       
    68 
       
    69 
       
    70 function __device_landmarks_getLandmarks(callback, match, errcb){
       
    71     return this.provider.getLandmarks(callback, match, errcb);
       
    72 }
       
    73 
       
    74 function __device_landmarks_add_category(callback, categoryItem, ErrorCallback){
       
    75     return this.provider.addCategory(callback, categoryItem, ErrorCallback);
       
    76 }
       
    77 
       
    78 
       
    79 function __device_landmarks_add_landmark(callback, landmarkItem, ErrorCallback){
       
    80     return this.provider.addLandmark(callback, landmarkItem, ErrorCallback);
       
    81 }
       
    82 
       
    83 function __device_landmarks_delete_category(callback, categoryId, ErrorCallback){
       
    84     return this.provider.deleteCategory(callback, categoryId, ErrorCallback);
       
    85 }
       
    86 
       
    87 function __device_landmarks_delete_landmark(callback, landmarkId, ErrorCallback){
       
    88     return this.provider.deleteLandmark(callback, landmarkId, ErrorCallback);
       
    89 }
       
    90 
       
    91 function __device_landmarks_update_landmark(callback, landmarkItem, ErrorCallback){
       
    92     return this.provider.updateLandmark(callback, landmarkItem, ErrorCallback);
       
    93 }
       
    94 
       
    95 function __device_landmarks_update_category(callback, categoryItem, ErrorCallback){
       
    96     return this.provider.updateCategory(callback, categoryItem, ErrorCallback);
       
    97 }
       
    98 
       
    99 function __device_landmarks_import_landmarks(callback, sourceFileUri, mimetype, ErrorCallback){
       
   100     return this.provider.importLandmarks(callback, sourceFileUri, mimetype, ErrorCallback);
       
   101 }
       
   102 
       
   103 function __device_landmarks_export_landmarks(callback, landmarkIdList, destFileUri, mimetype, ErrorCallback){
       
   104     return this.provider.exportLandmarks(callback, landmarkIdList, destFileUri, mimetype, ErrorCallback);
       
   105 }
       
   106 
       
   107 function __device_landmarks_organize_landmarks(callback, landmarkIdList, categoryId, associate, ErrorCallback){
       
   108     return this.provider.organizeLandmarks(callback, landmarkIdList, categoryId, associate, ErrorCallback);
       
   109 }
       
   110 
       
   111 function __device_landmarks_cancel(transactionId){
       
   112     return this.provider.cancel(transactionId);
       
   113 }
       
   114 
       
   115 
       
   116 
       
   117 
       
   118 /*
       
   119  Copyright � 2009 Nokia. All rights reserved.
       
   120  Code licensed under the BSD License:
       
   121  Software License Agreement (BSD License) Copyright � 2009 Nokia.
       
   122  All rights reserved.
       
   123  Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
       
   124  Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
       
   125  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.
       
   126  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.
       
   127  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.
       
   128  version: 1.0
       
   129  */
       
   130 //utillity function for converting error code from PS to CJSE codes
       
   131 //this gets used in communicating errors via error callback
       
   132 var err_missing_argument = 1003;
       
   133 var err_bad_argument = 1002;
       
   134 var err_ServiceNotSupported = 1004;
       
   135 var err_InvalidService_Argument = 1000;
       
   136 function convertFromPS2JS(PSCode){
       
   137     var JSCodeValue = new DeviceAPIError(0, "dummy");
       
   138     var JsErrCode;
       
   139     switch (PSCode) {
       
   140         case 1016:
       
   141             JsErrCode = JSCodeValue.TIMEOUT_ERR;
       
   142             break;
       
   143         case 1012:
       
   144             JsErrCode = JSCodeValue.DATA_NOT_FOUND_ERR;
       
   145             break;
       
   146         case 1010:
       
   147             JsErrCode = JSCodeValue.DATA_ALREADY_EXISTS_ERR;
       
   148             break;
       
   149         case 1009:
       
   150             JsErrCode = JSCodeValue.SERVICE_BUSY_ERR;
       
   151             break;
       
   152         case 1005:
       
   153             JsErrCode = JSCodeValue.SERVICE_IN_USE_ERR;
       
   154             break;
       
   155         default:
       
   156             JsErrCode = 1001;
       
   157     }
       
   158     return JsErrCode;
       
   159 }
       
   160 
       
   161 // S60 sp-based landmarks provider
       
   162 
       
   163 function __sp_landmarks_descriptor(){
       
   164     //Read-only properties
       
   165     this.interfaceName = "landmarks";
       
   166     if (window.__Service_Interface_Ver) 
       
   167         this.version = __Service_Interface_Ver;
       
   168     else 
       
   169         this.version = 1.0;
       
   170     //Class-static properties 
       
   171 }
       
   172 
       
   173 function __sp_landmarks_instance(){
       
   174     //Descriptor
       
   175     this.descriptor = new __sp_landmarks_descriptor();
       
   176     //Core methods
       
   177     this.startEditor = __sp_landmarks_startEditor;
       
   178     //Extended methods
       
   179     this.getCategories = __sp_landmarks_category_getList;
       
   180     this.getCategoriesCb = __sp_landmarks_category_getList_cb;
       
   181     
       
   182     this.addCategory = __sp_landmarks_category_add;
       
   183     this.addCategoryCb = __sp_landmarks_category_add_cb;
       
   184     
       
   185     this.updateCategory = __sp_landmarks_category_update;
       
   186     this.updateCategoryCb = __sp_landmarks_category_update_cb;
       
   187     
       
   188     this.deleteCategory = __sp_landmarks_category_delete;
       
   189     this.deleteCategoryCb = __sp_landmarks_category_delete_cb;
       
   190     
       
   191     this.getLandmarks = __sp_landmarks_getList;
       
   192     this.getLandmarksCb = __sp_landmarks_getList_cb;
       
   193     
       
   194     this.addLandmark = __sp_landmarks_add;
       
   195     this.addLandmarkCb = __sp_landmarks_add_cb;
       
   196     
       
   197     this.updateLandmark = __sp_landmarks_update;
       
   198     this.updateLandmarkCb = __sp_landmarks_update_cb;
       
   199     
       
   200     this.deleteLandmark = __sp_landmarks_delete;
       
   201     this.deleteLandmarkCb = __sp_landmarks_delete_cb;
       
   202     
       
   203     this.importLandmarks = __sp_landmarks_import;
       
   204     this.importLandmarksCb = __sp_landmarks_import_cb;
       
   205     
       
   206     this.exportLandmarks = __sp_landmarks_export;
       
   207     this.exportLandmarksCb = __sp_landmarks_export_cb;
       
   208     
       
   209     this.organizeLandmarks = __sp_landmarks_organize;
       
   210     this.organizeLandmarksCb = __sp_landmarks_organize_cb;
       
   211     
       
   212     this.temporarySCb = null;
       
   213     this.temporaryECb = null;
       
   214     
       
   215     this.cancel = __sp_landmarks_cancel;
       
   216     //Private data 
       
   217     try {
       
   218         this.so = device.getServiceObject("Service.Landmarks", "IDataSource");
       
   219     } 
       
   220     catch (e) {
       
   221         __device_handle_exception(e, "Landmarks service not available");
       
   222     }
       
   223 }
       
   224 
       
   225 // TBD: We MUST get rid of this when underlying sp supports category names directly
       
   226 // For one thing this is not localized!
       
   227 
       
   228 var __SP_CATEGORY_MIN_LOCAL_ID = 16;
       
   229 
       
   230 var __sp_category_list = [{
       
   231     id: 1,
       
   232     globalId: 3000,
       
   233     name: "Accommodation"
       
   234 }, {
       
   235     id: 2,
       
   236     globalId: 6000,
       
   237     name: "Businesses"
       
   238 }, {
       
   239     id: 3,
       
   240     globalId: 9000,
       
   241     name: "Telecommunications"
       
   242 }, {
       
   243     id: 4,
       
   244     globalId: 12000,
       
   245     name: "Education"
       
   246 }, {
       
   247     id: 5,
       
   248     globalId: 15000,
       
   249     name: "Entertainment"
       
   250 }, {
       
   251     id: 6,
       
   252     globalId: 18000,
       
   253     name: "Food and drink"
       
   254 }, {
       
   255     id: 7,
       
   256     globalId: 21000,
       
   257     name: "Geographical locations"
       
   258 }, {
       
   259     id: 8,
       
   260     globalId: 24000,
       
   261     name: "Outdoor activities"
       
   262 }, {
       
   263     id: 9,
       
   264     globalId: 27000,
       
   265     name: "People"
       
   266 }, {
       
   267     id: 10,
       
   268     globalId: 30000,
       
   269     name: "Public services"
       
   270 }, {
       
   271     id: 11,
       
   272     globalId: 33000,
       
   273     name: "Places of worship"
       
   274 }, {
       
   275     id: 12,
       
   276     globalId: 36000,
       
   277     name: "Shopping"
       
   278 }, {
       
   279     id: 13,
       
   280     globalId: 39000,
       
   281     name: "Sightseeing"
       
   282 }, {
       
   283     id: 14,
       
   284     globalId: 42000,
       
   285     name: "Sports"
       
   286 }, {
       
   287     id: 15,
       
   288     globalId: 45000,
       
   289     name: "Transport"
       
   290 }];
       
   291 
       
   292 /* ------ Wrap sp iterators ------- */
       
   293 
       
   294 function __sp_landmarks_category_iterator(js_iterator){
       
   295     this.iter = js_iterator;
       
   296     this.next = __sp_landmarks_category_iterator_get_next;
       
   297     this.hasNext = __sp_landmarks_category_iterator_has_next;
       
   298     
       
   299     //indicate whether iterator has been populated atleast once
       
   300     this.hasElement = false;
       
   301     //refers to the current category item
       
   302     this.catItem = null;
       
   303     this.close = __sp_landmarks_category_close;
       
   304 }
       
   305 
       
   306 function __sp_landmarks_category_close(){
       
   307     this.iter.close();
       
   308 }
       
   309 
       
   310 function __sp_landmarks_category_iterator_has_next(){
       
   311     if (this.hasElement) {
       
   312         if (this.catItem !== null) {
       
   313             return true;
       
   314         }
       
   315         else {
       
   316             return false;
       
   317         }
       
   318         
       
   319     }
       
   320     else {
       
   321         this.catItem = this.iter.getNext();
       
   322         this.hasElement = true;
       
   323         if (typeof this.catItem == "undefined") {
       
   324             this.catItem = null;
       
   325             return false;
       
   326         }
       
   327         else {
       
   328             return true;
       
   329         }
       
   330     }
       
   331 }
       
   332 
       
   333 function __sp_landmarks_category_iterator_get_next(){
       
   334     if (this.hasElement) {
       
   335         var tempitem = new Object();
       
   336         tempitem = this.catItem;
       
   337         //update
       
   338         this.catItem = this.iter.getNext();
       
   339         if (typeof(this.catItem) == "undefined") {
       
   340             this.catItem = null;
       
   341         }
       
   342         return new __sp_device_category_obj(tempitem);
       
   343     }
       
   344     else {
       
   345         this.catItem = this.iter.getNext();
       
   346         if (typeof this.catItem == "undefined") {
       
   347             this.hasElement = true;
       
   348             this.catItem = null;
       
   349             return null;
       
   350             
       
   351         }
       
   352         else {
       
   353             this.hasElement = true;
       
   354             var tempObject = new Object();
       
   355             tempObject = this.lmItem;
       
   356             //update 
       
   357             
       
   358             this.catItem = this.iter.getNext();
       
   359             if (typeof(this.catItem) == "undefined") {
       
   360                 this.catItem = null;
       
   361             }
       
   362             return new __sp_device_category_obj(tempObject);
       
   363         }
       
   364     }
       
   365 }
       
   366 
       
   367 //landmark iterator
       
   368 function __sp_landmarks_iterator(js_iterator){
       
   369     this.iter = js_iterator;
       
   370     this.next = __sp_landmarks_iterator_get_next;
       
   371     this.hasNext = __sp_landmarks_iterator_has_next;
       
   372     
       
   373     //indicate whether iterator has been populated atleast once
       
   374     this.hasElement = false;
       
   375     //refers to the current landmark item
       
   376     this.lmItem = null;
       
   377     this.close = __sp_landmarks_landmarkitem_close;
       
   378 }
       
   379 
       
   380 function __sp_landmarks_landmarkitem_close(){
       
   381     this.iter.close();
       
   382 }
       
   383 
       
   384 // Parameter objects
       
   385 //converts from LIW position to JS wrapper positionfield object
       
   386 function __sp_device_landmark_location_obj(sp_location){
       
   387     this.longitude = (sp_location.Longitude == undefined) ? null : sp_location.Longitude;
       
   388     this.latitude = (sp_location.Latitude == undefined) ? null : sp_location.Latitude;
       
   389     if (sp_location.Altitude) 
       
   390         this.altitude = sp_location.Altitude;
       
   391     if (sp_location.HAccuracy) 
       
   392         this.hAccuracy = sp_location.HAccuracy;
       
   393     if (sp_location.VAccuracy) 
       
   394         this.vAccuracy = sp_location.VAccuracy;
       
   395 }
       
   396 
       
   397 //this is being used for converting position field in criteria for getLandmarks.
       
   398 function __sp_landmark_position_obj(location){
       
   399     if ((location.longitude !== undefined) &&
       
   400     (location.longitude !== null) &&
       
   401     (location.longitude !== "")) {
       
   402         this.Longitude = location.longitude;
       
   403     }
       
   404     if ((location.latitude !== undefined) &&
       
   405     (location.latitude !== null) &&
       
   406     (location.latitude !== "")) {
       
   407         this.Latitude = location.latitude;
       
   408     }
       
   409     
       
   410     
       
   411     /*if(location.altitude) 
       
   412     
       
   413      this.Altitude = location.altitude;
       
   414     
       
   415      if(location.hAccuracy)
       
   416     
       
   417      this.HAccuracy = location.hAccuracy;
       
   418     
       
   419      if(location.vAccuracy)
       
   420     
       
   421      this.VAccuracy = location.vAccuracy;*/
       
   422     
       
   423 }
       
   424 
       
   425 //use this to convert from positon filed of landmarkitem to convert it to position field 
       
   426 //in LIW of landmark item
       
   427 function __sp_landmark_position_obj_fromJS_2LIW(location){
       
   428 	var error = new DeviceAPIError(0, "dummy");
       
   429 	if (typeof(location) != "object"){
       
   430 		throw new DeviceAPIError(error.INVALID_ARG_ERR, 'position must be of type object');	
       
   431 	}
       
   432 	var loFound = false;
       
   433 	var laFound = false;
       
   434 	if ((location.longitude !== undefined)
       
   435 	     && (location.longitude !== null)
       
   436 		 && (location.longitude !== "")){
       
   437 		this.Longitude = location.longitude;
       
   438 		loFound = true;	 
       
   439 	}
       
   440 	if ((location.latitude !== undefined)
       
   441 	     && (location.latitude !== null)
       
   442 		 && (location.latitude !== "")){
       
   443 		this.Latitude = location.latitude;
       
   444 		laFound = true;	 
       
   445 	}
       
   446     if (!(loFound && laFound)) {
       
   447 		throw new DeviceAPIError(error.MISSING_ARG_ERR, 'missing position field');
       
   448 	}
       
   449     if (location.altitude) 
       
   450         this.Altitude = location.altitude;
       
   451     if (location.hAccuracy) 
       
   452         this.HAccuracy = location.hAccuracy;
       
   453     if (location.vAccuracy) 
       
   454         this.VAccuracy = location.vAccuracy;
       
   455 }
       
   456 
       
   457 function __sp_landmark_bounded_area_obj(area){
       
   458 
       
   459     var error = new DeviceAPIError(0, "dummy");
       
   460     var c1Found = false;
       
   461     var c2Found = false;
       
   462     if ((area.coordinate1 !== undefined) &&
       
   463     (area.coordinate1 !== null) &&
       
   464     (area.coordinate1 !== "")) {
       
   465         if (typeof(area.coordinate1) != "object") {
       
   466             throw new DeviceAPIError(error.INVALID_ARG_ERR, 'coordinate1 must be an object');
       
   467         }
       
   468         else {
       
   469             var latFound = false;
       
   470             var longFound = false;
       
   471             if ((area.coordinate1.latitude !== undefined) &&
       
   472             (area.coordinate1.latitude !== null) &&
       
   473             (area.coordinate1.latitude !== "")) {
       
   474                 this.NorthLatitude = area.coordinate1.latitude;
       
   475                 latFound = true;
       
   476             }
       
   477             
       
   478             
       
   479             if ((area.coordinate1.longitude !== undefined) &&
       
   480             (area.coordinate1.longitude !== null) &&
       
   481             (area.coordinate1.longitude !== "")) {
       
   482                 this.EastLongitude = area.coordinate1.longitude;
       
   483                 longFound = true;
       
   484             }
       
   485             if (!(latFound && longFound)) {
       
   486                 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'missing position field');
       
   487             }
       
   488             c1Found = true;
       
   489             
       
   490         }
       
   491         
       
   492         
       
   493     }
       
   494     if ((area.coordinate2 !== undefined) &&
       
   495     (area.coordinate2 !== null) &&
       
   496     (area.coordinate2 !== "")) {
       
   497         if (typeof(area.coordinate2) != "object") {
       
   498             throw new DeviceAPIError(error.INVALID_ARG_ERR, 'coordinate2 must be an object');
       
   499         }
       
   500         else {
       
   501             var latFound = false;
       
   502             var longFound = false;
       
   503             if ((area.coordinate2.latitude !== undefined) &&
       
   504             (area.coordinate2.latitude !== null) &&
       
   505             (area.coordinate2.latitude !== "")) {
       
   506                 this.SouthLatitude = area.coordinate2.latitude;
       
   507                 latFound = true;
       
   508             }
       
   509             
       
   510             
       
   511             if ((area.coordinate2.longitude !== undefined) &&
       
   512             (area.coordinate2.longitude !== null) &&
       
   513             (area.coordinate2.longitude !== "")) {
       
   514                 this.WestLongitude = area.coordinate2.longitude;
       
   515                 longFound = true;
       
   516             }
       
   517             if (!(latFound && longFound)) {
       
   518                 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'missing position field');
       
   519             }
       
   520             c2Found = true;
       
   521             
       
   522         }
       
   523         
       
   524         
       
   525     }
       
   526     if (!(c1Found && c2Found)) {
       
   527         throw new DeviceAPIError(error.MISSING_ARG_ERR, 'missing position field');
       
   528     }
       
   529     
       
   530 }
       
   531 
       
   532 
       
   533 //converts from LIW address to JS wrapper AddressDetails
       
   534 
       
   535 function __sp_device_landmark_address_obj(sp_address){
       
   536     if (sp_address.Street) 
       
   537         this.street = sp_address.Street;
       
   538     if (sp_address.City) 
       
   539         this.city = sp_address.City;
       
   540     if (sp_address.state) 
       
   541         this.state = sp_address.state;
       
   542     if (sp_address.AreaCode) 
       
   543         this.postalCode = sp_address.AreaCode;
       
   544     if (sp_address.Country) 
       
   545         this.country = sp_address.Country;
       
   546     if (sp_address.BuildingName) 
       
   547         this.building = sp_address.BuildingName;
       
   548     if (sp_address.Telephone) 
       
   549         this.phone = sp_address.Telephone;
       
   550 }
       
   551 
       
   552 // sp problem: no way to specify state/province?
       
   553 
       
   554 function __sp_landmark_address_obj(address){
       
   555 	var error = new DeviceAPIError(0, "dummy");
       
   556 	if (typeof(address) != "object"){
       
   557 		throw new DeviceAPIError(error.MISSING_ARG_ERR, 'address must be of type object');	
       
   558 	}
       
   559 	
       
   560     if (address.street !== undefined){
       
   561 		if (address.street === null){
       
   562 			this.Street = "";	
       
   563 		}
       
   564 		else {
       
   565 			this.Street = address.street;	
       
   566 		}
       
   567 			
       
   568 	} 
       
   569 	if (address.city !== undefined){
       
   570 		if (address.city === null){
       
   571 			this.City = "";	
       
   572 		}
       
   573 		else {
       
   574 			this.City = address.city;	
       
   575 		}
       
   576 			
       
   577 	} 
       
   578 	if (address.state !== undefined){
       
   579 		if (address.state === null){
       
   580 			this.state = "";	
       
   581 		}
       
   582 		else {
       
   583 			this.state = address.state;	
       
   584 		}
       
   585 			
       
   586 	} 
       
   587 	if (address.postalCode !== undefined){
       
   588 		if (address.postalCode === null){
       
   589 			this.AreaCode = "";	
       
   590 		}
       
   591 		else {
       
   592 			this.AreaCode = address.postalCode;	
       
   593 		}
       
   594 			
       
   595 	} 
       
   596 	if (address.country !== undefined){
       
   597 		if (address.country === null){
       
   598 			this.Country = "";	
       
   599 		}
       
   600 		else {
       
   601 			this.Country = address.country;	
       
   602 		}
       
   603 			
       
   604 	} 
       
   605 	if (address.building !== undefined){
       
   606 		if (address.building === null){
       
   607 			this.BuildingName = "";	
       
   608 		}
       
   609 		else {
       
   610 			this.BuildingName = address.building;	
       
   611 		}
       
   612 			
       
   613 	} 
       
   614 	if (address.phone !== undefined){
       
   615 		if (address.phone === null){
       
   616 			this.Telephone = "";	
       
   617 		}
       
   618 		else {
       
   619 			this.Telephone = address.phone;	
       
   620 		}
       
   621 			
       
   622 	} 
       
   623     
       
   624 }
       
   625 
       
   626 function __sp_add_category_ids_for_names(names){
       
   627     var errObj = new DeviceAPIError(0, "dummy");
       
   628     var retval = new Array();
       
   629     
       
   630     for (var i in names) {
       
   631         if ((names[i] !== undefined) &&
       
   632         (names[i] !== "") &&
       
   633         (names[i] !== null)) {
       
   634             if (typeof(names[i]) != "string") {
       
   635                 throw new DeviceAPIError(errObj.INVALID_ARG_ERR, 'category should be of type string');
       
   636             }
       
   637             else {
       
   638                 retval.push(names[i].toString());
       
   639             }
       
   640             
       
   641             
       
   642         }
       
   643         
       
   644     }
       
   645     return retval;
       
   646 }
       
   647 
       
   648 function __sp_get_category_ids_for_names(names){
       
   649     var errObj = new DeviceAPIError(0, "dummy");
       
   650     var retval = new Array();
       
   651     var isCatGlobal = 0;// to check if the category passed is a global category
       
   652     for (var i in names) {
       
   653         if (typeof(names[i]) != "string") {
       
   654             throw new DeviceAPIError(errObj.INVALID_ARG_ERR, 'category should be of type string');
       
   655         }
       
   656         for (var ii in __sp_category_list) {
       
   657             //__device_debug(names[i] + " ==? " + __sp_category_list[ii].name);
       
   658             
       
   659             if (__sp_category_list[ii].name.toLowerCase() == names[i].toLowerCase()) {
       
   660                 retval.push(__sp_category_list[ii].id.toString());
       
   661                 isCatGlobal = 1;
       
   662             }
       
   663         }
       
   664         if (isCatGlobal == 0) {
       
   665             return null;
       
   666         }
       
   667         isCatGlobal = 0;// set the flag to 0
       
   668     }
       
   669     return retval;
       
   670 }
       
   671 
       
   672 //converts from LIW to JS wrapper paramater
       
   673 function __sp_device_landmark_obj(sp_landmark){
       
   674     this.landmarkId = sp_landmark.id;
       
   675     if (sp_landmark.LandmarkName) {
       
   676         this.name = sp_landmark.LandmarkName;
       
   677     }
       
   678     if (sp_landmark.LandmarkDesc) {
       
   679         this.description = sp_landmark.LandmarkDesc;
       
   680     }
       
   681     if (sp_landmark.CoverageRadius) {
       
   682         this.coverageRadius = sp_landmark.CoverageRadius;
       
   683     }
       
   684     if (sp_landmark.LandmarkPosition) {
       
   685         this.position = new __sp_device_landmark_location_obj(sp_landmark.LandmarkPosition);
       
   686     }
       
   687     if (sp_landmark.CategoryInfo) {
       
   688         this.categoryIds = sp_landmark.CategoryInfo;
       
   689     }
       
   690     
       
   691     if (sp_landmark.LandmarkFields) {
       
   692         this.address = new __sp_device_landmark_address_obj(sp_landmark.LandmarkFields);
       
   693     }
       
   694 }
       
   695 
       
   696 function __sp_landmarks_addLocality(add){
       
   697     var errLoc = new DeviceAPIError(0, "dummy");
       
   698     if (typeof(add) != "object") {
       
   699         throw new DeviceAPIError(errLoc.INVALID_ARG_ERR, 'address should be of type object');
       
   700     }
       
   701     if ((add.street !== undefined) &&
       
   702     (add.street !== null) &&
       
   703     (add.street !== "")) {
       
   704     
       
   705         this.Street = add.street;
       
   706         
       
   707     }
       
   708     if ((add.city !== undefined) &&
       
   709     (add.city !== null) &&
       
   710     (add.city !== "")) {
       
   711     
       
   712         this.City = add.city;
       
   713         
       
   714     }
       
   715     if ((add.state !== undefined) &&
       
   716     (add.state !== null) &&
       
   717     (add.state !== "")) {
       
   718     
       
   719         this.state = add.state;
       
   720         
       
   721     }
       
   722     if ((add.postalCode !== undefined) &&
       
   723     (add.postalCode !== null) &&
       
   724     (add.postalCode !== "")) {
       
   725     
       
   726         this.AreaCode = add.postalCode;
       
   727         
       
   728     }
       
   729     if ((add.country !== undefined) &&
       
   730     (add.country !== null) &&
       
   731     (add.country !== "")) {
       
   732     
       
   733         this.Country = add.country;
       
   734         
       
   735     }
       
   736     if ((add.building !== undefined) &&
       
   737     (add.building !== null) &&
       
   738     (add.building !== "")) {
       
   739     
       
   740         this.BuildingName = add.building;
       
   741         
       
   742     }
       
   743     if ((add.phone !== undefined) &&
       
   744     (add.phone !== null) &&
       
   745     (add.phone !== "")) {
       
   746     
       
   747         this.Telephone = add.phone;
       
   748         
       
   749     }
       
   750 }
       
   751 
       
   752 function __sp_landmarks_addPosition(pos){
       
   753     var errPos = new DeviceAPIError(0, "dummy");
       
   754     if (typeof(pos) != "object") {
       
   755         throw new DeviceAPIError(errPos.INVALID_ARG_ERR, 'position should be of type object');
       
   756     }
       
   757     
       
   758     if ((pos.longitude !== undefined) &&
       
   759     (pos.longitude !== null) &&
       
   760     (pos.longitude !== "")) {
       
   761     
       
   762         this.Longitude = pos.longitude;
       
   763         //alert("longitude found");
       
   764     
       
   765     }
       
   766     if ((pos.latitude !== undefined) &&
       
   767     (pos.latitude !== null) &&
       
   768     (pos.latitude !== "")) {
       
   769     
       
   770         this.Latitude = pos.latitude;
       
   771         //alert("latitude found");
       
   772     
       
   773     }
       
   774     if ((pos.altitude !== undefined) &&
       
   775     (pos.altitude !== null) &&
       
   776     (pos.altitude !== "")) {
       
   777     
       
   778         this.Altitude = pos.altitude;
       
   779         
       
   780     }
       
   781     if ((pos.hAccuracy !== undefined) &&
       
   782     (pos.hAccuracy !== null) &&
       
   783     (pos.hAccuracy !== "")) {
       
   784     
       
   785         this.HAccuracy = pos.hAccuracy;
       
   786         
       
   787     }
       
   788     if ((pos.vAccuracy !== undefined) &&
       
   789     (pos.vAccuracy !== null) &&
       
   790     (pos.vAccuracy !== "")) {
       
   791     
       
   792         this.VAccuracy = pos.vAccuracy;
       
   793         
       
   794     }
       
   795 }
       
   796 
       
   797 function __sp_landmarks_addLmObject(lm){
       
   798     var posSet = false;
       
   799     var errObj = new DeviceAPIError(0, "dummy");
       
   800     if ((lm.name !== undefined) &&
       
   801     (lm.name !== null) &&
       
   802     (lm.name !== "")) {
       
   803     
       
   804         this.LandmarkName = lm.name;
       
   805         
       
   806     }
       
   807     if ((lm.description !== undefined) &&
       
   808     (lm.description !== null) &&
       
   809     (lm.description !== "")) {
       
   810     
       
   811         this.LandmarkDesc = lm.description;
       
   812         
       
   813     }
       
   814     if ((lm.position !== undefined) &&
       
   815     (lm.position !== null) &&
       
   816     (lm.position !== "")) {
       
   817         //alert("adding position");
       
   818         this.LandmarkPosition = new __sp_landmarks_addPosition(lm.position);
       
   819         posSet = true;
       
   820         //alert("pos="+this.position); 
       
   821     
       
   822     }
       
   823     if ((lm.coverageRadius !== undefined) &&
       
   824     (lm.coverageRadius !== null) &&
       
   825     (lm.coverageRadius !== "")) {
       
   826     
       
   827         if (posSet) {
       
   828             this.CoverageRadius = lm.coverageRadius;
       
   829         }
       
   830         else {
       
   831             throw new DeviceAPIError(errObj.MISSING_ARG_ERR, 'missing position');
       
   832         }
       
   833         
       
   834         
       
   835     }
       
   836     
       
   837     if ((lm.categoryIds !== undefined) &&
       
   838     (lm.categoryIds !== null) &&
       
   839     (lm.categoryIds !== "")) {
       
   840         if (typeof(lm.categoryIds) != 'object') {
       
   841             throw new DeviceAPIError(errObj.INVALID_ARG_ERR, 'categoryids should be of type object');
       
   842         }
       
   843         
       
   844         this.CategoryInfo = __sp_add_category_ids_for_names(lm.categoryIds);
       
   845         if (!this.CategoryInfo) {
       
   846             throw new DeviceAPIError(errObj.MISSING_ARG_ERR, 'invalid category');
       
   847             
       
   848         }
       
   849         
       
   850     }
       
   851     if ((lm.address !== undefined) &&
       
   852     (lm.address !== null) &&
       
   853     (lm.address !== "")) {
       
   854     
       
   855         this.LandmarkFields = new __sp_landmarks_addLocality(lm.address);
       
   856         
       
   857     }
       
   858     //dummy object
       
   859     this.dummyField = "dummyfield";
       
   860     
       
   861 }
       
   862 
       
   863 //this converts from JS landmarkitem to LIW landmark item
       
   864 //being used by updateLandmark API
       
   865 function __sp_landmark_obj(landmark, str){
       
   866 	var error = new DeviceAPIError(0, "dummy");
       
   867     if (landmark.name !== undefined){
       
   868 		if (landmark.name === null){
       
   869 			this.LandmarkName = "";	
       
   870 		}
       
   871 		else {
       
   872 			this.LandmarkName = landmark.name;	
       
   873 		}
       
   874 		
       
   875 	} 
       
   876         
       
   877     if ((landmark.landmarkId === undefined)
       
   878 	     || (landmark.landmarkId === null)
       
   879 		 || (landmark.landmarkId === "")) 
       
   880 		 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'for updating; id must be supplied');
       
   881 	else 
       
   882         this.id = landmark.landmarkId;
       
   883     if (landmark.description !== undefined){
       
   884 		if (landmark.description === null){
       
   885 			this.LandmarkDesc = "";	
       
   886 		}
       
   887 		else {
       
   888 			this.LandmarkDesc = landmark.description;	
       
   889 		}
       
   890 		
       
   891 	} 
       
   892         
       
   893     if (landmark.position) 
       
   894         this.LandmarkPosition = new __sp_landmark_position_obj_fromJS_2LIW(landmark.position);
       
   895     if (landmark.coverageRadius) 
       
   896         this.CoverageRadius = landmark.coverageRadius;
       
   897     if (landmark.categories) {
       
   898         this.CategoryInfo = __sp_get_category_ids_for_names(landmark.categories);
       
   899         if (!this.CategoryInfo) {
       
   900             throw new DeviceError("Landmarks: " + str + "Category is invalid", err_bad_argument);
       
   901         }
       
   902     }
       
   903     if (landmark.address) 
       
   904         this.LandmarkFields = new __sp_landmark_address_obj(landmark.address);
       
   905     
       
   906 	this.temp = "dummy";
       
   907 }
       
   908 
       
   909 function __sp_landmarks_iterator_has_next(){
       
   910     if (this.hasElement) {
       
   911         if (this.lmItem !== null) {
       
   912             return true;
       
   913         }
       
   914         else {
       
   915             return false;
       
   916         }
       
   917         
       
   918     }
       
   919     else {
       
   920         this.lmItem = this.iter.getNext();
       
   921         this.hasElement = true;
       
   922         if (typeof this.lmItem == "undefined") {
       
   923             this.lmItem = null;
       
   924             return false;
       
   925         }
       
   926         else {
       
   927             return true;
       
   928         }
       
   929     }
       
   930 }
       
   931 
       
   932 function __sp_landmarks_iterator_get_next(){
       
   933     if (this.hasElement) {
       
   934         var tempitem = new Object();
       
   935         tempitem = this.lmItem;
       
   936         //update
       
   937         this.lmItem = this.iter.getNext();
       
   938         if (typeof(this.lmItem) == "undefined") {
       
   939             this.lmItem = null;
       
   940         }
       
   941         return new __sp_device_landmark_obj(tempitem);
       
   942     }
       
   943     else {
       
   944         this.lmItem = this.iter.getNext();
       
   945         if (typeof this.lmItem == "undefined") {
       
   946             this.hasElement = true;
       
   947             this.lmItem = null;
       
   948             return null;
       
   949             
       
   950         }
       
   951         else {
       
   952             this.hasElement = true;
       
   953             var tempObject = new Object();
       
   954             tempObject = this.lmItem;
       
   955             //update 
       
   956             
       
   957             this.lmItem = this.iter.getNext();
       
   958             if (typeof(this.lmItem) == "undefined") {
       
   959                 this.lmItem = null;
       
   960             }
       
   961             return new __sp_device_landmark_obj(tempObject);
       
   962         }
       
   963     }
       
   964     
       
   965 }
       
   966 
       
   967 function __sp_category_obj(category){
       
   968     if (category.name) 
       
   969         this.CategoryName = category.name;
       
   970     if (category.categoryId) 
       
   971         this.id = category.categoryId;
       
   972 }
       
   973 
       
   974 function __sp_device_category_obj(sp_category){
       
   975     this.categoryId = sp_category.id;
       
   976     this.name = sp_category.CategoryName;
       
   977 }
       
   978 
       
   979 /* --------- Public methods ---------- */
       
   980 
       
   981 
       
   982 var LANDMARKS_APP_ID = 0x101F85A2;
       
   983 
       
   984 // Apps should take care that this is not reinvoked
       
   985 // while the editor is already running. 
       
   986 
       
   987 function __sp_landmarks_startEditor(__success_cb, landmark_item, _error_cb){
       
   988     // internal variable used in this library implementation
       
   989     // This will made local variable when seperate module js files gets integrated in this file.
       
   990     error = new DeviceAPIError(0, "dummy");
       
   991     if ((__success_cb === undefined) ||
       
   992     (__success_cb === null) ||
       
   993     (__success_cb === "")) 
       
   994         throw new DeviceAPIError(error.MISSING_ARG_ERR, 'StartEditor:Missing Success Callback');
       
   995     
       
   996     if ((typeof __success_cb) != "function") 
       
   997         throw new DeviceAPIError(error.INVALID_ARG_ERR, 'StartEditor:Success Callback must be of type function');
       
   998     
       
   999     if (landmark_item !== undefined) {
       
  1000         if ((landmark_item !== null) &&
       
  1001         (landmark_item !== "")) {
       
  1002         
       
  1003             throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, 'startEditor:landmark item is not supported');
       
  1004             
       
  1005         }
       
  1006     }
       
  1007     
       
  1008     if ((_error_cb !== undefined) &&
       
  1009     (_error_cb !== null) &&
       
  1010     (_error_cb !== "")) {
       
  1011         if ((typeof _error_cb) != "function") 
       
  1012             throw new DeviceAPIError(error.INVALID_ARG_ERR, 'StartEditor:error callback must be of type function');
       
  1013     }
       
  1014     
       
  1015     var LANDMARKS_APP_ID = 0x101F85A2;
       
  1016     
       
  1017     
       
  1018     var __s60_start_and_wait_cb;
       
  1019     
       
  1020     function __s60_on_app_exit(){
       
  1021         window.xwidget.onshow = null;
       
  1022         if (__s60_start_and_wait_cb) {
       
  1023             __s60_start_and_wait_cb();
       
  1024         }
       
  1025     }
       
  1026     
       
  1027     var finished = function(arg1, arg2, arg3){
       
  1028         __success_cb(arg1, arg2, arg3);
       
  1029     };
       
  1030     __s60_start_and_wait(LANDMARKS_APP_ID, '', finished);
       
  1031     
       
  1032 }
       
  1033 
       
  1034 //oriiginal signature category_cb, name
       
  1035 
       
  1036 function __sp_landmarks_category_getList_cb(arg1, arg2, arg3){
       
  1037     var CbObj;
       
  1038     var category_cb;
       
  1039     var ErrorCallback;
       
  1040     if (this.temporarySCb) {
       
  1041         category_cb = this.temporarySCb;
       
  1042         ErrorCallback = this.temporaryECb;
       
  1043         this.temporarySCb = null;
       
  1044         this.temporaryECb = null;
       
  1045     }
       
  1046     else {
       
  1047         CbObj = glob_obj.getFromArray(arg1);
       
  1048         if (CbObj) {
       
  1049             category_cb = CbObj.success_cb;
       
  1050             ErrorCallback = CbObj.error_cb;
       
  1051         }
       
  1052         
       
  1053         else {
       
  1054             alert("Landmarks: __sp_landmarks_category_getList_cb: Callback not found ");
       
  1055             return;
       
  1056         }
       
  1057     }
       
  1058     
       
  1059     
       
  1060     var iter = null;
       
  1061     //if there is an error invoke user supplied error callback
       
  1062     if (arg3.ErrorCode || (arg2 == 4)) { //indicates an error
       
  1063         var scbErrCode = convertFromPS2JS(arg3.ErrorCode);
       
  1064         var erroObject = new DeviceAPIError(scbErrCode, arg3.ErrorMessage);
       
  1065         if (ErrorCallback) {
       
  1066             ErrorCallback(erroObject);
       
  1067         }
       
  1068     }
       
  1069     else {
       
  1070         if (arg3.ReturnValue) {
       
  1071             iter = new __sp_landmarks_category_iterator(arg3.ReturnValue);
       
  1072             category_cb(iter);
       
  1073         }
       
  1074     }
       
  1075     glob_obj.removeFromArray(arg1);
       
  1076 }
       
  1077 
       
  1078 function __sp_landmarks_category_getList(category_cb, name, ErrorCallback){
       
  1079     try {
       
  1080         //alert("calling getlist");
       
  1081         var error = new DeviceAPIError(0, "dummy");
       
  1082         //succes callback must be defined and should be of the type function
       
  1083         if ((category_cb === undefined) ||
       
  1084         (category_cb === "") ||
       
  1085         (category_cb === null)) {
       
  1086             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'callback is missing');
       
  1087         }
       
  1088         if (typeof(category_cb) != "function") {
       
  1089             throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid callback argument');
       
  1090         }
       
  1091         //check if errorcallback has been supplied and valid
       
  1092         var errcbFound = false;
       
  1093         if ((ErrorCallback !== undefined) &&
       
  1094         (ErrorCallback !== null) &&
       
  1095         (ErrorCallback !== "")) {
       
  1096             if (typeof(ErrorCallback) != "function") {
       
  1097                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid error callback argument');
       
  1098             }
       
  1099             else {
       
  1100                 errcbFound = true;
       
  1101             }
       
  1102         }
       
  1103         //to check from here
       
  1104         var criteria = new Object();
       
  1105         modifyObjectBaseProp(criteria);
       
  1106         criteria.Type = "Category";
       
  1107         //if name has been supplied it must be of type string
       
  1108         if ((name !== undefined) &&
       
  1109         (name !== null) &&
       
  1110         (name !== "")) {
       
  1111         
       
  1112             if (typeof(name) != "string") {
       
  1113                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'name must be a string');
       
  1114             }
       
  1115             
       
  1116         }
       
  1117         
       
  1118         if (name) {
       
  1119             criteria.Filter = new Object();
       
  1120             modifyObjectBaseProp(criteria.Filter);
       
  1121             criteria.Filter.CategoryName = name;
       
  1122             criteria.Filter.PreviousMatchesOnly = false;
       
  1123         }
       
  1124         
       
  1125         this.temporarySCb = category_cb;
       
  1126         this.temporaryECb = ErrorCallback;
       
  1127         
       
  1128         var rval = this.so.IDataSource.GetList(criteria, this.getCategoriesCb);
       
  1129         
       
  1130         if (rval.TransactionID) {
       
  1131             glob_obj.addToGlobalArray(rval.TransactionID, category_cb, ErrorCallback);
       
  1132         }
       
  1133         
       
  1134         if (rval.ErrorCode != 0) {
       
  1135             switch (rval.ErrorCode) {
       
  1136                 case 1003:
       
  1137                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  1138                     break;
       
  1139                 case 1002:
       
  1140                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1141                     break;
       
  1142                 case 1004:
       
  1143                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  1144                     break;
       
  1145                 case 1000:
       
  1146                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1147                     break;
       
  1148                 default:
       
  1149                     throw new DeviceAPIError(-101, "unknown error message");
       
  1150                     
       
  1151             }
       
  1152             
       
  1153         }
       
  1154         return rval.TransactionID;
       
  1155         
       
  1156         
       
  1157     } 
       
  1158     catch (e) {
       
  1159         //alert("exception from here");
       
  1160         throw e;
       
  1161     }
       
  1162 }
       
  1163 
       
  1164 function __sp_landmarks_category_add_cb(arg1, arg2, arg3){
       
  1165     var CbObj;
       
  1166     var callback;
       
  1167     var ErrorCallback;
       
  1168     if (this.temporarySCb) {
       
  1169         category_cb = this.temporarySCb;
       
  1170         ErrorCallback = this.temporaryECb;
       
  1171         this.temporarySCb = null;
       
  1172         this.temporaryECb = null;
       
  1173     }
       
  1174     else {
       
  1175         CbObj = glob_obj.getFromArray(arg1);
       
  1176         if (CbObj) {
       
  1177             callback = CbObj.success_cb;
       
  1178             ErrorCallback = CbObj.error_cb;
       
  1179         }
       
  1180         
       
  1181         else {
       
  1182             alert("Landmarks: __sp_landmarks_category_add_cb: Callback not found ");
       
  1183             return;
       
  1184         }
       
  1185     }
       
  1186     
       
  1187     
       
  1188     var id = null;
       
  1189     //if there is an error invoke user supplied error callback
       
  1190     if (arg2 == 4 || arg3.ErrorCode) { //indicates an error
       
  1191         var scbErrCode = convertFromPS2JS(arg3.ErrorCode);
       
  1192         var erroObject = new DeviceAPIError(scbErrCode, arg3.ErrorMessage);
       
  1193         if (ErrorCallback) {
       
  1194             ErrorCallback(erroObject);
       
  1195         }
       
  1196     }
       
  1197     else {
       
  1198         if (arg3.ReturnValue) {
       
  1199             id = arg3.ReturnValue;
       
  1200         }
       
  1201         //in case of success invoke user supplied scb
       
  1202         callback(id);
       
  1203     }
       
  1204     glob_obj.removeFromArray(arg1);
       
  1205 }
       
  1206 
       
  1207 //original signature : __sp_landmarks_category_add(cat)
       
  1208 function __sp_landmarks_category_add(callback, categoryItem, ErrorCallback){
       
  1209     try {
       
  1210         var error = new DeviceAPIError(0, "dummy");
       
  1211         var isErrCB = true;//indicates a valid errocalback has been supplied
       
  1212         if (callback === undefined) {
       
  1213             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'AddSucessCallback is missing');
       
  1214         }
       
  1215         else {
       
  1216             if (((callback === null) ||
       
  1217             (callback === "")) &&
       
  1218             (typeof(callback) != "number")) {
       
  1219                 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'AddSucessCallback is missing');
       
  1220             }
       
  1221             else 
       
  1222                 if (typeof(callback) != 'function') {
       
  1223                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid AddSucessCallback argument');
       
  1224                 }
       
  1225         }
       
  1226         if (categoryItem === undefined || categoryItem === null) {
       
  1227             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'CategoryItem is missing');
       
  1228         }
       
  1229         else 
       
  1230             if (typeof(categoryItem) !== "object") {
       
  1231                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid CategoryItem argument');
       
  1232             }
       
  1233         
       
  1234         if ((ErrorCallback != undefined)) {
       
  1235             if ((!ErrorCallback) &&
       
  1236             (typeof(ErrorCallback) != "number")) {
       
  1237                 isErrCB = false;
       
  1238             }
       
  1239             else 
       
  1240                 if ((typeof(ErrorCallback) != 'function')) {
       
  1241                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid ErrorCallback callback');
       
  1242                 }
       
  1243             
       
  1244         }
       
  1245         else {
       
  1246             isErrCB = false;
       
  1247         }
       
  1248         
       
  1249         var criteria = new Object();
       
  1250         modifyObjectBaseProp(criteria);
       
  1251         criteria.Type = "Category";
       
  1252         criteria.Data = new __sp_category_obj(categoryItem);
       
  1253 		
       
  1254 		this.temporarySCb = callback;
       
  1255         this.temporaryECb = ErrorCallback;
       
  1256 		
       
  1257         var rval = this.so.IDataSource.Add(criteria, this.addCategoryCb);
       
  1258         
       
  1259         if (rval.TransactionID) {
       
  1260             glob_obj.addToGlobalArray(rval.TransactionID, callback, ErrorCallback);
       
  1261         }
       
  1262         if (rval.ErrorCode != 0) {
       
  1263             switch (rval.ErrorCode) {
       
  1264                 case err_missing_argument:
       
  1265                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  1266                     break;
       
  1267                 case err_bad_argument:
       
  1268                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1269                     break;
       
  1270                 case err_ServiceNotSupported:
       
  1271                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  1272                     break;
       
  1273                 case err_InvalidService_Argument:
       
  1274                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1275                     break;
       
  1276                 default:
       
  1277                     throw new DeviceAPIError(-101, "unknown error message");
       
  1278             }
       
  1279         }
       
  1280         return rval.TransactionID;
       
  1281     } 
       
  1282     catch (e) {
       
  1283         throw e;
       
  1284     }
       
  1285 }
       
  1286 
       
  1287 function __sp_landmarks_add_cb(arg1, arg2, arg3){
       
  1288     var id = null;
       
  1289     var CbObj;
       
  1290     var callback;
       
  1291     var ErrorCallback;
       
  1292 	if (this.temporarySCb) {
       
  1293         category_cb = this.temporarySCb;
       
  1294         ErrorCallback = this.temporaryECb;
       
  1295         this.temporarySCb = null;
       
  1296         this.temporaryECb = null;
       
  1297     }
       
  1298     else {
       
  1299         CbObj = glob_obj.getFromArray(arg1);
       
  1300         if (CbObj) {
       
  1301             callback = CbObj.success_cb;
       
  1302             ErrorCallback = CbObj.error_cb;
       
  1303         }
       
  1304         
       
  1305         else {
       
  1306             alert("Landmarks: __sp_landmarks_add_cb: Callback not found ");
       
  1307             return;
       
  1308         }
       
  1309     }
       
  1310     
       
  1311     //if there is an error invoke user supplied error callback
       
  1312     if (arg2 == 4 || arg3.ErrorCode) { //indicates an error
       
  1313         var scbErrCode = convertFromPS2JS(arg3.ErrorCode);
       
  1314         var erroObject = new DeviceAPIError(scbErrCode, arg3.ErrorMessage);
       
  1315         if (ErrorCallback) {
       
  1316             ErrorCallback(erroObject);
       
  1317         }
       
  1318     }
       
  1319     else {
       
  1320         if (arg3.ReturnValue) {
       
  1321             id = arg3.ReturnValue;
       
  1322         }
       
  1323         //in case of success invoke user supplied scb
       
  1324         callback(id);
       
  1325     }
       
  1326     glob_obj.removeFromArray(arg1);
       
  1327 }
       
  1328 
       
  1329 //original signature : __sp_landmarks_add(landmark)
       
  1330 function __sp_landmarks_add(callback, landmarkItem, ErrorCallback){
       
  1331     try {
       
  1332         var error = new DeviceAPIError(0, "dummy");
       
  1333         var isErrCB = true;//indicates a valid errocalback has been supplied
       
  1334         if (callback === undefined) {
       
  1335             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'AddSucessCallback is missing');
       
  1336         }
       
  1337         else {
       
  1338             if (((callback === null) ||
       
  1339             (callback === "")) &&
       
  1340             (typeof(callback) != "number")) {
       
  1341                 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'AddSucessCallback is missing');
       
  1342             }
       
  1343             else 
       
  1344                 if (typeof(callback) != 'function') {
       
  1345                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid AddSucessCallback argument');
       
  1346                 }
       
  1347         }
       
  1348         if ((landmarkItem === undefined) ||
       
  1349         (landmarkItem === null) ||
       
  1350         (landmarkItem === "")) {
       
  1351             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'LandmarkItem is missing');
       
  1352         }
       
  1353         else 
       
  1354             if (typeof(landmarkItem) !== "object") {
       
  1355                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid LandmarkItem argument');
       
  1356             }
       
  1357         
       
  1358         if ((ErrorCallback != undefined)) {
       
  1359             if ((!ErrorCallback) &&
       
  1360             (typeof(ErrorCallback) != "number")) {
       
  1361                 isErrCB = false;
       
  1362             }
       
  1363             else 
       
  1364                 if ((typeof(ErrorCallback) != 'function')) {
       
  1365                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid ErrorCallback callback');
       
  1366                 }
       
  1367             
       
  1368         }
       
  1369         else {
       
  1370             isErrCB = false;
       
  1371         }
       
  1372         
       
  1373         
       
  1374         var str = "addLandmark: ";
       
  1375         var criteria = new Object();
       
  1376         modifyObjectBaseProp(criteria);
       
  1377         criteria.Type = "Landmark";
       
  1378         //criteria.Data = new __sp_landmark_obj(landmarkItem, str);
       
  1379         criteria.Data = new __sp_landmarks_addLmObject(landmarkItem);
       
  1380         //alert("calling PS add");
       
  1381 		this.temporarySCb = callback;
       
  1382         this.temporaryECb = ErrorCallback;
       
  1383         var rval = this.so.IDataSource.Add(criteria, this.addLandmarkCb);
       
  1384         //alert("rval.tid="+rval.TransactionID);
       
  1385         //alert("rval.error="+rval.ErrorCode);
       
  1386         if (rval.TransactionID) {
       
  1387             glob_obj.addToGlobalArray(rval.TransactionID, callback, ErrorCallback);
       
  1388         }
       
  1389         
       
  1390         if (rval.ErrorCode != 0) {
       
  1391             switch (rval.ErrorCode) {
       
  1392                 case err_missing_argument:
       
  1393                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  1394                     break;
       
  1395                 case err_bad_argument:
       
  1396                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1397                     break;
       
  1398                 case err_ServiceNotSupported:
       
  1399                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  1400                     break;
       
  1401                 case err_InvalidService_Argument:
       
  1402                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1403                     break;
       
  1404                 default:
       
  1405                     throw new DeviceAPIError(-101, "unknown error message");
       
  1406             }
       
  1407         }
       
  1408         return rval.TransactionID;
       
  1409     } 
       
  1410     catch (e) {
       
  1411         throw e;
       
  1412     }
       
  1413 }
       
  1414 
       
  1415 function __sp_landmarks_delete_cb(arg1, arg2, arg3){
       
  1416     var callback;
       
  1417     var ErrorCallback;
       
  1418     var CbObj;
       
  1419 	if (this.temporarySCb) {
       
  1420         category_cb = this.temporarySCb;
       
  1421         ErrorCallback = this.temporaryECb;
       
  1422         this.temporarySCb = null;
       
  1423         this.temporaryECb = null;
       
  1424     }
       
  1425     else {
       
  1426         CbObj = glob_obj.getFromArray(arg1);
       
  1427         if (CbObj) {
       
  1428             callback = CbObj.success_cb;
       
  1429             ErrorCallback = CbObj.error_cb;
       
  1430         }
       
  1431         
       
  1432         else {
       
  1433             alert("Landmarks: __sp_landmarks_delete_cb: Callback not found ");
       
  1434             return;
       
  1435         }
       
  1436     }
       
  1437     
       
  1438     //if there is an error invoke user supplied error callback
       
  1439     if (arg2 == 4 || arg3.ErrorCode) { //indicates an error
       
  1440         var scbErrCode = convertFromPS2JS(arg3.ErrorCode);
       
  1441         var erroObject = new DeviceAPIError(scbErrCode, arg3.ErrorMessage);
       
  1442         if (ErrorCallback) {
       
  1443             ErrorCallback(erroObject);
       
  1444         }
       
  1445     }
       
  1446     else {
       
  1447         //in case of success invoke user supplied scb
       
  1448         callback();
       
  1449     }
       
  1450     glob_obj.removeFromArray(arg1);
       
  1451 }
       
  1452 
       
  1453 //original signature : __sp_landmarks_delete(id)
       
  1454 function __sp_landmarks_delete(callback, landmarkId, ErrorCallback){
       
  1455     try {
       
  1456         var error = new DeviceAPIError(0, "dummy");
       
  1457         var isErrCB = true;//indicates a valid errocalback has been supplied
       
  1458         if (callback === undefined) {
       
  1459             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SucessCallback is missing');
       
  1460         }
       
  1461         else {
       
  1462             if (((callback === null) ||
       
  1463             (callback === "")) &&
       
  1464             (typeof(callback) != "number")) {
       
  1465                 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SucessCallback is missing');
       
  1466             }
       
  1467             else 
       
  1468                 if (typeof(callback) != 'function') {
       
  1469                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid SucessCallback argument');
       
  1470                 }
       
  1471         }
       
  1472         if (landmarkId === undefined || landmarkId === null) {
       
  1473             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'landmarkId is missing');
       
  1474         }
       
  1475         else 
       
  1476             if (typeof(landmarkId) !== "string") {
       
  1477                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid landmarkId argument');
       
  1478             }
       
  1479         
       
  1480         if ((ErrorCallback != undefined)) {
       
  1481             if ((!ErrorCallback) &&
       
  1482             (typeof(ErrorCallback) != "number")) {
       
  1483                 isErrCB = false;
       
  1484             }
       
  1485             else 
       
  1486                 if ((typeof(ErrorCallback) != 'function')) {
       
  1487                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid ErrorCallback callback');
       
  1488                 }
       
  1489             
       
  1490         }
       
  1491         else {
       
  1492             isErrCB = false;
       
  1493         }
       
  1494         
       
  1495         
       
  1496         var criteria = new Object();
       
  1497         modifyObjectBaseProp(criteria);
       
  1498         criteria.Type = "Landmark";
       
  1499         criteria.Data = new Object();
       
  1500         modifyObjectBaseProp(criteria.Data);
       
  1501         criteria.Data.id = landmarkId;
       
  1502 		
       
  1503 		this.temporarySCb = callback;
       
  1504         this.temporaryECb = ErrorCallback;
       
  1505 		
       
  1506         var rval = this.so.IDataSource.Delete(criteria, this.deleteLandmarkCb);
       
  1507         if (rval.TransactionID) {
       
  1508             glob_obj.addToGlobalArray(rval.TransactionID, callback, ErrorCallback);
       
  1509         }
       
  1510         if (rval.ErrorCode != 0) {
       
  1511             switch (rval.ErrorCode) {
       
  1512                 case err_missing_argument:
       
  1513                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  1514                     break;
       
  1515                 case err_bad_argument:
       
  1516                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1517                     break;
       
  1518                 case err_ServiceNotSupported:
       
  1519                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  1520                     break;
       
  1521                 case err_InvalidService_Argument:
       
  1522                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1523                     break;
       
  1524                 default:
       
  1525                     throw new DeviceAPIError(-101, "unknown error message");
       
  1526             }
       
  1527         }
       
  1528         return rval.TransactionID;
       
  1529     } 
       
  1530     catch (e) {
       
  1531         throw e;
       
  1532     }
       
  1533 }
       
  1534 
       
  1535 function __sp_landmarks_update_cb(arg1, arg2, arg3){
       
  1536 
       
  1537     var callback;
       
  1538     var ErrorCallback;
       
  1539     var CbObj;
       
  1540 		if (this.temporarySCb) {
       
  1541         category_cb = this.temporarySCb;
       
  1542         ErrorCallback = this.temporaryECb;
       
  1543         this.temporarySCb = null;
       
  1544         this.temporaryECb = null;
       
  1545     }
       
  1546     else {
       
  1547         CbObj = glob_obj.getFromArray(arg1);
       
  1548         if (CbObj) {
       
  1549             callback = CbObj.success_cb;
       
  1550             ErrorCallback = CbObj.error_cb;
       
  1551         }
       
  1552         
       
  1553         else {
       
  1554             alert("Landmarks: __sp_landmarks_update_cb: Callback not found ");
       
  1555             return;
       
  1556         }
       
  1557     }
       
  1558     
       
  1559     //if there is an error invoke user supplied error callback
       
  1560     if (arg2 == 4 || arg3.ErrorCode) { //indicates an error
       
  1561         var scbErrCode = convertFromPS2JS(arg3.ErrorCode);
       
  1562         var erroObject = new DeviceAPIError(scbErrCode, arg3.ErrorMessage);
       
  1563         if (ErrorCallback) {
       
  1564             ErrorCallback(erroObject);
       
  1565         }
       
  1566     }
       
  1567     else {
       
  1568         //in case of success invoke user supplied scb
       
  1569         callback();
       
  1570     }
       
  1571     glob_obj.removeFromArray(arg1);
       
  1572 }
       
  1573 
       
  1574 //original signature : __sp_landmarks_update(landmark)
       
  1575 function __sp_landmarks_update(callback, landmarkItem, ErrorCallback){
       
  1576     try {
       
  1577         var error = new DeviceAPIError(0, "dummy");
       
  1578         var isErrCB = true;//indicates a valid errocalback has been supplied
       
  1579         if (callback === undefined) {
       
  1580             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SuccessCallback is missing');
       
  1581         }
       
  1582         else {
       
  1583             if (((callback === null) ||
       
  1584             (callback === "")) &&
       
  1585             (typeof(callback) != "number")) {
       
  1586                 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SuccessCallback is missing');
       
  1587             }
       
  1588             else 
       
  1589                 if (typeof(callback) != 'function') {
       
  1590                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid SuccessCallback argument');
       
  1591                 }
       
  1592         }
       
  1593         if (landmarkItem === undefined || landmarkItem === null || landmarkItem === "") {
       
  1594             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'LandmarkItem is missing');
       
  1595         }
       
  1596         else 
       
  1597             if (typeof(landmarkItem) !== "object") {
       
  1598                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid LandmarkItem argument');
       
  1599             }
       
  1600         
       
  1601         if ((ErrorCallback != undefined)) {
       
  1602             if ((!ErrorCallback) &&
       
  1603             (typeof(ErrorCallback) != "number")) {
       
  1604                 isErrCB = false;
       
  1605             }
       
  1606             else 
       
  1607                 if ((typeof(ErrorCallback) != 'function')) {
       
  1608                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid ErrorCallback callback');
       
  1609                 }
       
  1610             
       
  1611         }
       
  1612         else {
       
  1613             isErrCB = false;
       
  1614         }
       
  1615         
       
  1616         
       
  1617         var str = "updateLandmark: ";
       
  1618         var criteria = new Object();
       
  1619         modifyObjectBaseProp(criteria);
       
  1620         criteria.Type = "Landmark";
       
  1621         criteria.Data = new __sp_landmark_obj(landmarkItem, str);
       
  1622 		
       
  1623 		this.temporarySCb = callback;
       
  1624         this.temporaryECb = ErrorCallback;
       
  1625         var rval = this.so.IDataSource.Add(criteria, this.updateLandmarkCb);
       
  1626         if (rval.TransactionID) {
       
  1627             glob_obj.addToGlobalArray(rval.TransactionID, callback, ErrorCallback);
       
  1628         }
       
  1629         
       
  1630         if (rval.ErrorCode != 0) {
       
  1631             switch (rval.ErrorCode) {
       
  1632                 case err_missing_argument:
       
  1633                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  1634                     break;
       
  1635                 case err_bad_argument:
       
  1636                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1637                     break;
       
  1638                 case err_ServiceNotSupported:
       
  1639                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  1640                     break;
       
  1641                 case err_InvalidService_Argument:
       
  1642                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1643                     break;
       
  1644                 default:
       
  1645                     throw new DeviceAPIError(-101, "unknown error message");
       
  1646             }
       
  1647         }
       
  1648         return rval.TransactionID;
       
  1649     } 
       
  1650     catch (e) {
       
  1651         throw e;
       
  1652     }
       
  1653 }
       
  1654 
       
  1655 function __sp_landmarks_category_update_cb(arg1, arg2, arg3){
       
  1656     var callback;
       
  1657     var ErrorCallback;
       
  1658     var CbObj;
       
  1659 	if (this.temporarySCb) {
       
  1660         category_cb = this.temporarySCb;
       
  1661         ErrorCallback = this.temporaryECb;
       
  1662         this.temporarySCb = null;
       
  1663         this.temporaryECb = null;
       
  1664     }
       
  1665     else {
       
  1666         CbObj = glob_obj.getFromArray(arg1);
       
  1667         if (CbObj) {
       
  1668             callback = CbObj.success_cb;
       
  1669             ErrorCallback = CbObj.error_cb;
       
  1670         }
       
  1671         
       
  1672         else {
       
  1673             alert("Landmarks: __sp_landmarks_category_update_cb: Callback not found ");
       
  1674             return;
       
  1675         }
       
  1676     }
       
  1677     
       
  1678     //if there is an error invoke user supplied error callback
       
  1679     if (arg2 == 4 || arg3.ErrorCode) { //indicates an error
       
  1680         var scbErrCode = convertFromPS2JS(arg3.ErrorCode);
       
  1681         var erroObject = new DeviceAPIError(scbErrCode, arg3.ErrorMessage);
       
  1682         if (ErrorCallback) {
       
  1683             ErrorCallback(erroObject);
       
  1684         }
       
  1685     }
       
  1686     else {
       
  1687         //in case of success invoke user supplied scb
       
  1688         callback();
       
  1689     }
       
  1690     glob_obj.removeFromArray(arg1);
       
  1691 }
       
  1692 
       
  1693 function __sp_landmarks_category_update(callback, categoryItem, ErrorCallback){
       
  1694     try {
       
  1695         var error = new DeviceAPIError(0, "dummy");
       
  1696         var isErrCB = true;//indicates a valid errocalback has been supplied
       
  1697         if (callback === undefined) {
       
  1698             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SucessCallback is missing');
       
  1699         }
       
  1700         else {
       
  1701             if (((callback === null) ||
       
  1702             (callback === "")) &&
       
  1703             (typeof(callback) != "number")) {
       
  1704                 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SucessCallback is missing');
       
  1705             }
       
  1706             else 
       
  1707                 if (typeof(callback) != 'function') {
       
  1708                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid SucessCallback argument');
       
  1709                 }
       
  1710         }
       
  1711         if (categoryItem === undefined || categoryItem === null || categoryItem === "") {
       
  1712             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'CategoryItem is missing');
       
  1713         }
       
  1714         else 
       
  1715             if (typeof(categoryItem) !== "object") {
       
  1716                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid CategoryItem argument');
       
  1717             }
       
  1718         if ((categoryItem.categoryId === undefined)
       
  1719 		     || (categoryItem.categoryId === null)
       
  1720 			 || (categoryItem.categoryId === "")){
       
  1721 			 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'categoryId is missing');	
       
  1722 		}
       
  1723 		if (typeof (categoryItem.categoryId) != "string") {
       
  1724 			throw new DeviceAPIError(error.INVALID_ARG_ERR, 'category Id must be a string');
       
  1725 		}
       
  1726         if ((ErrorCallback != undefined)) {
       
  1727             if ((!ErrorCallback) &&
       
  1728             (typeof(ErrorCallback) != "number")) {
       
  1729                 isErrCB = false;
       
  1730             }
       
  1731             else 
       
  1732                 if ((typeof(ErrorCallback) != 'function')) {
       
  1733                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid ErrorCallback callback');
       
  1734                 }
       
  1735         }
       
  1736         else {
       
  1737             isErrCB = false;
       
  1738         }
       
  1739         
       
  1740         
       
  1741         var criteria = new Object();
       
  1742         modifyObjectBaseProp(criteria);
       
  1743         criteria.Type = "Category";
       
  1744         criteria.Data = new __sp_category_obj(categoryItem);
       
  1745 		
       
  1746 		this.temporarySCb = callback;
       
  1747         this.temporaryECb = ErrorCallback;
       
  1748 		
       
  1749         var rval = this.so.IDataSource.Add(criteria, this.updateCategoryCb);
       
  1750         
       
  1751         if (rval.TransactionID) {
       
  1752             glob_obj.addToGlobalArray(rval.TransactionID, callback, ErrorCallback);
       
  1753         }
       
  1754         
       
  1755         if (rval.ErrorCode != 0) {
       
  1756             switch (rval.ErrorCode) {
       
  1757                 case err_missing_argument:
       
  1758                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  1759                     break;
       
  1760                 case err_bad_argument:
       
  1761                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1762                     break;
       
  1763                 case err_ServiceNotSupported:
       
  1764                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  1765                     break;
       
  1766                 case err_InvalidService_Argument:
       
  1767                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1768                     break;
       
  1769                 default:
       
  1770                     throw new DeviceAPIError(-101, "unknown error message");
       
  1771             }
       
  1772         }
       
  1773         return rval.TransactionID;
       
  1774     } 
       
  1775     catch (e) {
       
  1776         throw e;
       
  1777     }
       
  1778 }
       
  1779 
       
  1780 function __sp_landmarks_category_delete_cb(arg1, arg2, arg3){
       
  1781     var callback;
       
  1782     var ErrorCallback;
       
  1783     var CbObj;
       
  1784     if (this.temporarySCb) {
       
  1785         category_cb = this.temporarySCb;
       
  1786         ErrorCallback = this.temporaryECb;
       
  1787         this.temporarySCb = null;
       
  1788         this.temporaryECb = null;
       
  1789     }
       
  1790     else {
       
  1791         CbObj = glob_obj.getFromArray(arg1);
       
  1792         if (CbObj) {
       
  1793             callback = CbObj.success_cb;
       
  1794             ErrorCallback = CbObj.error_cb;
       
  1795         }
       
  1796         
       
  1797         else {
       
  1798             alert("Landmarks: __sp_landmarks_category_delete_cb: Callback not found ");
       
  1799             return;
       
  1800         }
       
  1801     }
       
  1802     
       
  1803     //if there is an error invoke user supplied error callback
       
  1804     if (arg2 == 4 || arg3.ErrorCode) { //indicates an error
       
  1805         var scbErrCode = convertFromPS2JS(arg3.ErrorCode);
       
  1806         var erroObject = new DeviceAPIError(scbErrCode, arg3.ErrorMessage);
       
  1807         if (ErrorCallback) {
       
  1808             ErrorCallback(erroObject);
       
  1809         }
       
  1810     }
       
  1811     else {
       
  1812         //in case of success invoke user supplied scb
       
  1813         callback();
       
  1814     }
       
  1815     glob_obj.removeFromArray(arg1);
       
  1816 }
       
  1817 
       
  1818 function __sp_landmarks_category_delete(callback, categoryId, ErrorCallback){
       
  1819     try {
       
  1820         var error = new DeviceAPIError(0, "dummy");
       
  1821         var isErrCB = true;//indicates a valid errocalback has been supplied
       
  1822         if (callback === undefined) {
       
  1823             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SucessCallback is missing');
       
  1824         }
       
  1825         else {
       
  1826             if (((callback === null) ||
       
  1827             (callback === "")) &&
       
  1828             (typeof(callback) != "number")) {
       
  1829                 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SucessCallback is missing');
       
  1830             }
       
  1831             else 
       
  1832                 if (typeof(callback) != 'function') {
       
  1833                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid SucessCallback argument');
       
  1834                 }
       
  1835         }
       
  1836         if (categoryId === undefined || categoryId === null) {
       
  1837             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'categoryId is missing');
       
  1838         }
       
  1839         else 
       
  1840             if (typeof(categoryId) !== "string") {
       
  1841                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid categoryId argument');
       
  1842             }
       
  1843         
       
  1844         if ((ErrorCallback != undefined)) {
       
  1845             if ((!ErrorCallback) &&
       
  1846             (typeof(ErrorCallback) != "number")) {
       
  1847                 isErrCB = false;
       
  1848             }
       
  1849             else 
       
  1850                 if ((typeof(ErrorCallback) != 'function')) {
       
  1851                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid ErrorCallback callback');
       
  1852                 }
       
  1853             
       
  1854         }
       
  1855         else {
       
  1856             isErrCB = false;
       
  1857         }
       
  1858         
       
  1859         
       
  1860         var criteria = new Object();
       
  1861         modifyObjectBaseProp(criteria);
       
  1862         criteria.Type = "Category";
       
  1863         criteria.Data = new Object();
       
  1864         modifyObjectBaseProp(criteria.Data);
       
  1865         criteria.Data.id = categoryId;
       
  1866 		
       
  1867 		this.temporarySCb = callback;
       
  1868         this.temporaryECb = ErrorCallback;
       
  1869 		
       
  1870         var rval = this.so.IDataSource.Delete(criteria, this.deleteCategoryCb);
       
  1871         if (rval.TransactionID) {
       
  1872             glob_obj.addToGlobalArray(rval.TransactionID, callback, ErrorCallback);
       
  1873         }
       
  1874         
       
  1875         if (rval.ErrorCode != 0) {
       
  1876             switch (rval.ErrorCode) {
       
  1877                 case err_missing_argument:
       
  1878                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  1879                     break;
       
  1880                 case err_bad_argument:
       
  1881                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1882                     break;
       
  1883                 case err_ServiceNotSupported:
       
  1884                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  1885                     break;
       
  1886                 case err_InvalidService_Argument:
       
  1887                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  1888                     break;
       
  1889                 default:
       
  1890                     throw new DeviceAPIError(-101, "unknown error message");
       
  1891             }
       
  1892         }
       
  1893         return rval.TransactionID;
       
  1894     } 
       
  1895     catch (e) {
       
  1896         throw e;
       
  1897     }
       
  1898 }
       
  1899 
       
  1900 function __sp_landmarks_getList_cb(arg1, arg2, arg3){
       
  1901     var iter = null;
       
  1902     var callback;
       
  1903     var ErrorCallback;
       
  1904     var CbObj;
       
  1905     if (this.temporarySCb) {
       
  1906         category_cb = this.temporarySCb;
       
  1907         ErrorCallback = this.temporaryECb;
       
  1908         this.temporarySCb = null;
       
  1909         this.temporaryECb = null;
       
  1910     }
       
  1911     else {
       
  1912         CbObj = glob_obj.getFromArray(arg1);
       
  1913         if (CbObj) {
       
  1914             callback = CbObj.success_cb;
       
  1915             ErrorCallback = CbObj.error_cb;
       
  1916         }
       
  1917         
       
  1918         else {
       
  1919             alert("Landmarks: __sp_landmarks_getList_cb: Callback not found ");
       
  1920             return;
       
  1921         }
       
  1922     }
       
  1923     
       
  1924     //if there is an error invoke user supplied error callback
       
  1925     if (arg3.ErrorCode || (arg2 == 4)) { //indicates an error
       
  1926         var scbErrCode = convertFromPS2JS(arg3.ErrorCode);
       
  1927         var erroObject = new DeviceAPIError(scbErrCode, arg3.ErrorMessage);
       
  1928         if (ErrorCallback) {
       
  1929             ErrorCallback(erroObject);
       
  1930         }
       
  1931     }
       
  1932     else {
       
  1933         if (arg3.ReturnValue) {
       
  1934             iter = new __sp_landmarks_iterator(arg3.ReturnValue);
       
  1935         }
       
  1936         //in case of success invoke user supplied scb
       
  1937         callback(iter);
       
  1938     }
       
  1939     glob_obj.removeFromArray(arg1);
       
  1940 }
       
  1941 
       
  1942 function __sp_landmarks_getList(callback, matchObject, ErrorCallback){
       
  1943     try {
       
  1944         var error = new DeviceAPIError(0, "dummy");
       
  1945         //test variable
       
  1946         var isErrCB = false;//indicates a valid errocalback has not been supplied
       
  1947         var isNameSearch = false;
       
  1948         var isDefaultvalue = false;
       
  1949         
       
  1950         if ((callback === undefined) ||
       
  1951         (callback === null) ||
       
  1952         (callback === "")) {
       
  1953         
       
  1954             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SucessCallback is missing');
       
  1955         }
       
  1956         if (typeof(callback) != 'function') {
       
  1957             throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid SucessCallback argument');
       
  1958         }
       
  1959         if ((ErrorCallback !== undefined) &&
       
  1960         (ErrorCallback !== "") &&
       
  1961         (ErrorCallback !== null)) {
       
  1962         
       
  1963             if ((typeof(ErrorCallback) != 'function')) {
       
  1964                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid error callback');
       
  1965             }
       
  1966             else {
       
  1967                 isErrCB = true;
       
  1968             }
       
  1969             
       
  1970         }
       
  1971         var criteria = new Object();
       
  1972         modifyObjectBaseProp(criteria);
       
  1973         criteria.Type = "Landmark";
       
  1974         criteria.Filter = new Object();
       
  1975         if ((matchObject === undefined) ||
       
  1976         (matchObject === null) ||
       
  1977         (matchObject === "")) {
       
  1978         
       
  1979             criteria.Filter.dummy = "dummy";
       
  1980         }
       
  1981         else 
       
  1982             if (typeof(matchObject) == "string") {
       
  1983             
       
  1984                 criteria.Filter.LandmarkName = matchObject;
       
  1985             }
       
  1986             else 
       
  1987                 if (typeof(matchObject) != "object") {
       
  1988                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid match criteria');
       
  1989                 }
       
  1990                 else {
       
  1991                     if ((matchObject.name !== undefined) &&
       
  1992                     (matchObject.name !== null) &&
       
  1993                     (matchObject.name !== "")) 
       
  1994                         criteria.Filter.LandmarkName = matchObject.name;
       
  1995                     if ((matchObject.description !== undefined) &&
       
  1996                     (matchObject.description !== null) &&
       
  1997                     (matchObject.description !== "")) 
       
  1998                         criteria.Filter.LandmarkDesc = matchObject.description;
       
  1999                     
       
  2000                     if ((matchObject.categoryId !== undefined) &&
       
  2001                     (matchObject.categoryId !== null) &&
       
  2002                     (matchObject.categoryId !== "")) 
       
  2003                         criteria.Filter.categoryId = matchObject.categoryId;
       
  2004                     
       
  2005                     if ((matchObject.position !== undefined) &&
       
  2006                     (matchObject.position !== null) &&
       
  2007                     (matchObject.position !== "")) {
       
  2008                         if (typeof(matchObject.position) != "object") 
       
  2009                             throw new DeviceAPIError(error.INVALID_ARG_ERR, 'position must be an object');
       
  2010                         else {
       
  2011                             criteria.Filter.LandmarkPosition = new __sp_landmark_position_obj(matchObject.position);
       
  2012                         }
       
  2013                     }
       
  2014                     if ((matchObject.coverageRadiusUsed !== undefined) &&
       
  2015                     (matchObject.coverageRadiusUsed !== null) &&
       
  2016                     (matchObject.coverageRadiusUsed !== "")) {
       
  2017                         if (typeof(matchObject.coverageRadiusUsed) != "number") 
       
  2018                             throw new DeviceAPIError(error.INVALID_ARG_ERR, "coverageRadiusUsed should be number");
       
  2019                         else 
       
  2020                             criteria.Filter.CoverageRadiusOption = matchObject.coverageRadiusUsed;
       
  2021                     }
       
  2022                     
       
  2023                     if ((matchObject.searchRadius !== undefined) &&
       
  2024                     (matchObject.searchRadius !== null) &&
       
  2025                     (matchObject.searchRadius !== "")) {
       
  2026                         if (typeof(matchObject.searchRadius) != "number") 
       
  2027                             throw new DeviceAPIError(error.INVALID_ARG_ERR, "searchRadius should be number");
       
  2028                         else 
       
  2029                             criteria.Filter.MaximumDistance = matchObject.searchRadius;
       
  2030                         
       
  2031                     }
       
  2032                     
       
  2033                     if ((matchObject.area !== undefined) &&
       
  2034                     (matchObject.area !== null) &&
       
  2035                     (matchObject.area !== "")) {
       
  2036                         if (typeof(matchObject.area) != 'object') 
       
  2037                             throw new DeviceAPIError(error.INVALID_ARG_ERR, 'area must be an object');
       
  2038                         else {
       
  2039                             criteria.Filter.BoundedArea = new __sp_landmark_bounded_area_obj(matchObject.area);
       
  2040                         }
       
  2041                     }
       
  2042                 }
       
  2043         //alert("calling getlist");        
       
  2044 		
       
  2045 		this.temporarySCb = callback;
       
  2046         this.temporaryECb = ErrorCallback;
       
  2047 		   
       
  2048         var rval = this.so.IDataSource.GetList(criteria, this.getLandmarksCb);
       
  2049         if (rval.TransactionID) {
       
  2050             glob_obj.addToGlobalArray(rval.TransactionID, callback, ErrorCallback);
       
  2051         }
       
  2052         
       
  2053         if (rval.ErrorCode != 0) {
       
  2054             switch (rval.ErrorCode) {
       
  2055                 case 1003:
       
  2056                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  2057                     break;
       
  2058                 case 1002:
       
  2059                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  2060                     break;
       
  2061                 case 1004:
       
  2062                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  2063                     break;
       
  2064                 case 1000:
       
  2065                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  2066                     break;
       
  2067                 default:
       
  2068                     throw new DeviceAPIError(-101, "unknown error message");
       
  2069                     
       
  2070             }
       
  2071             
       
  2072         }
       
  2073         return rval.TransactionID;
       
  2074         
       
  2075         
       
  2076     } 
       
  2077     catch (e) {
       
  2078         //alert("exception from here");
       
  2079         throw e;
       
  2080     }
       
  2081 }
       
  2082 
       
  2083 function __sp_landmarks_import_cb(arg1, arg2, arg3){
       
  2084     //if there is an error invoke user supplied error callback
       
  2085     var iter = null;
       
  2086     var callback;
       
  2087     var ErrorCallback;
       
  2088     var CbObj;
       
  2089     if (this.temporarySCb) {
       
  2090         category_cb = this.temporarySCb;
       
  2091         ErrorCallback = this.temporaryECb;
       
  2092         this.temporarySCb = null;
       
  2093         this.temporaryECb = null;
       
  2094     }
       
  2095     else {
       
  2096         CbObj = glob_obj.getFromArray(arg1);
       
  2097         if (CbObj) {
       
  2098             callback = CbObj.success_cb;
       
  2099             ErrorCallback = CbObj.error_cb;
       
  2100         }
       
  2101         
       
  2102         else {
       
  2103             alert("Landmarks: __sp_landmarks_import_cb: Callback not found ");
       
  2104             return;
       
  2105         }
       
  2106     }
       
  2107     
       
  2108     //if there is an error invoke user supplied error callback
       
  2109     if (arg2 == 4 || arg3.ErrorCode) { //indicates an error
       
  2110         var scbErrCode = convertFromPS2JS(arg3.ErrorCode);
       
  2111         var erroObject = new DeviceAPIError(scbErrCode, arg3.ErrorMessage);
       
  2112         if (ErrorCallback) {
       
  2113             ErrorCallback(erroObject);
       
  2114         }
       
  2115     }
       
  2116     else {
       
  2117         if (arg3.ReturnValue) {
       
  2118             iter = new __sp_landmarks_iterator(arg3.ReturnValue);
       
  2119         }
       
  2120         
       
  2121         //in case of success invoke user supplied scb
       
  2122         callback(iter);
       
  2123     }
       
  2124     glob_obj.removeFromArray(arg1);
       
  2125 }
       
  2126 
       
  2127 function __sp_landmarks_import(callback, sourceFileUri, mimetype, ErrorCallback){
       
  2128     try {
       
  2129         var error = new DeviceAPIError(0, "dummy");
       
  2130         var isErrCB = true;//indicates a valid errocalback has been supplied
       
  2131         if (callback === undefined) {
       
  2132             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'LandmarksItrCallback is missing');
       
  2133         }
       
  2134         else {
       
  2135             if (((callback === null) ||
       
  2136             (callback === "")) &&
       
  2137             (typeof(callback) != "number")) {
       
  2138                 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'LandmarksItrCallback is missing');
       
  2139             }
       
  2140             else 
       
  2141                 if (typeof(callback) != 'function') {
       
  2142                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid LandmarksItrCallback argument');
       
  2143                 }
       
  2144         }
       
  2145         
       
  2146         if (sourceFileUri === undefined || sourceFileUri === null) {
       
  2147             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'sourceFileUri is missing');
       
  2148         }
       
  2149         else 
       
  2150             if (typeof(sourceFileUri) !== "string") {
       
  2151                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid sourceFileUri argument');
       
  2152             }
       
  2153         
       
  2154         if (mimetype === undefined || mimetype === null) {
       
  2155             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'mimetype is missing');
       
  2156         }
       
  2157         else 
       
  2158             if (typeof(mimetype) !== "string") {
       
  2159                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid mimetype argument');
       
  2160             }
       
  2161         
       
  2162         if ((ErrorCallback != undefined)) {
       
  2163             if ((!ErrorCallback) &&
       
  2164             (typeof(ErrorCallback) != "number")) {
       
  2165                 isErrCB = false;
       
  2166             }
       
  2167             else 
       
  2168                 if ((typeof(ErrorCallback) != 'function')) {
       
  2169                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid ErrorCallback callback');
       
  2170                 }
       
  2171             
       
  2172         }
       
  2173         else {
       
  2174             isErrCB = false;
       
  2175         }
       
  2176         
       
  2177         
       
  2178         
       
  2179         var criteria = new Object();
       
  2180         modifyObjectBaseProp(criteria);
       
  2181         criteria.Type = "Landmark";
       
  2182         criteria.Data = new Object();
       
  2183         modifyObjectBaseProp(criteria.Data);
       
  2184         //replace all '/' to '\' and remove file:// or file:///
       
  2185         if (sourceFileUri.slice(0, 7) == "file://") {
       
  2186             sourceFileUri = sourceFileUri.slice(7);
       
  2187         }
       
  2188         else 
       
  2189             if (sourceFileUri.slice(0, 8) == "file:///") {
       
  2190                 sourceFileUri = sourceFileUri.slice(8);
       
  2191             }
       
  2192             else {
       
  2193                 throw new DeviceAPIError(error.INVALID_ARG_ERR, "sourceFileUri is not in URI format");
       
  2194             }
       
  2195         while (sourceFileUri.search("/") != -1) {
       
  2196             sourceFileUri = sourceFileUri.replace("/", "\\");
       
  2197         }
       
  2198         criteria.Data.SourceFile = sourceFileUri;
       
  2199         criteria.Data.MimeType = mimetype;
       
  2200 		
       
  2201 		this.temporarySCb = callback;
       
  2202         this.temporaryECb = ErrorCallback;
       
  2203 		
       
  2204         var rval = this.so.IDataSource.Import(criteria, this.importLandmarksCb);
       
  2205         if (rval.TransactionID) {
       
  2206             glob_obj.addToGlobalArray(rval.TransactionID, callback, ErrorCallback);
       
  2207         }
       
  2208         
       
  2209         if (rval.ErrorCode != 0) {
       
  2210             switch (rval.ErrorCode) {
       
  2211                 case err_missing_argument:
       
  2212                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  2213                     break;
       
  2214                 case err_bad_argument:
       
  2215                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  2216                     break;
       
  2217                 case err_ServiceNotSupported:
       
  2218                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  2219                     break;
       
  2220                 case err_InvalidService_Argument:
       
  2221                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  2222                     break;
       
  2223                 default:
       
  2224                     throw new DeviceAPIError(-101, "unknown error message");
       
  2225             }
       
  2226         }
       
  2227         return rval.TransactionID;
       
  2228     } 
       
  2229     catch (e) {
       
  2230         throw e;
       
  2231     }
       
  2232 }
       
  2233 
       
  2234 function __sp_landmarks_export_cb(arg1, arg2, arg3){
       
  2235     var callback;
       
  2236     var ErrorCallback;
       
  2237     var CbObj;
       
  2238     if (this.temporarySCb) {
       
  2239         category_cb = this.temporarySCb;
       
  2240         ErrorCallback = this.temporaryECb;
       
  2241         this.temporarySCb = null;
       
  2242         this.temporaryECb = null;
       
  2243     }
       
  2244     else {
       
  2245         CbObj = glob_obj.getFromArray(arg1);
       
  2246         if (CbObj) {
       
  2247             callback = CbObj.success_cb;
       
  2248             ErrorCallback = CbObj.error_cb;
       
  2249         }
       
  2250         
       
  2251         else {
       
  2252             alert("Landmarks: __sp_landmarks_export_cb: Callback not found ");
       
  2253             return;
       
  2254         }
       
  2255     }
       
  2256     
       
  2257     //if there is an error invoke user supplied error callback
       
  2258     //if there is an error invoke user supplied error callback
       
  2259     if (arg2 == 4 || arg3.ErrorCode) { //indicates an error
       
  2260         var scbErrCode = convertFromPS2JS(arg3.ErrorCode);
       
  2261         var erroObject = new DeviceAPIError(scbErrCode, arg3.ErrorMessage);
       
  2262         if (ErrorCallback) {
       
  2263             ErrorCallback(erroObject);
       
  2264         }
       
  2265     }
       
  2266     else {
       
  2267         //in case of success invoke user supplied scb
       
  2268         callback();
       
  2269     }
       
  2270     
       
  2271     glob_obj.removeFromArray(arg1);
       
  2272 }
       
  2273 
       
  2274 function __sp_landmarks_export(callback, landmarkIdList, destFileUri, mimetype, ErrorCallback){
       
  2275     try {
       
  2276         var error = new DeviceAPIError(0, "dummy");
       
  2277         var isErrCB = true;//indicates a valid errocalback has been supplied
       
  2278         if (callback === undefined) {
       
  2279             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SuccessCallback is missing');
       
  2280         }
       
  2281         else {
       
  2282             if (((callback === null) ||
       
  2283             (callback === "")) &&
       
  2284             (typeof(callback) != "number")) {
       
  2285                 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SuccessCallback is missing');
       
  2286             }
       
  2287             else 
       
  2288                 if (typeof(callback) != 'function') {
       
  2289                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid SuccessCallback argument');
       
  2290                 }
       
  2291         }
       
  2292         
       
  2293         if (landmarkIdList === undefined || landmarkIdList === null) {
       
  2294             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'landmarkIdList is missing');
       
  2295         }
       
  2296         else 
       
  2297             if (typeof(landmarkIdList) !== "object") {
       
  2298                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid landmarkIdList argument');
       
  2299             }
       
  2300         
       
  2301         if (destFileUri === undefined || destFileUri === null) {
       
  2302             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'destFileUri is missing');
       
  2303         }
       
  2304         else 
       
  2305             if (typeof(destFileUri) !== "string") {
       
  2306                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid destFileUri argument');
       
  2307             }
       
  2308         
       
  2309         if (mimetype === undefined || mimetype === null) {
       
  2310             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'mimetype is missing');
       
  2311         }
       
  2312         else 
       
  2313             if (typeof(mimetype) !== "string") {
       
  2314                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid mimetype argument');
       
  2315             }
       
  2316         
       
  2317         if ((ErrorCallback != undefined)) {
       
  2318             if ((!ErrorCallback) &&
       
  2319             (typeof(ErrorCallback) != "number")) {
       
  2320                 isErrCB = false;
       
  2321             }
       
  2322             else 
       
  2323                 if ((typeof(ErrorCallback) != 'function')) {
       
  2324                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid ErrorCallback callback');
       
  2325                 }
       
  2326             
       
  2327         }
       
  2328         else {
       
  2329             isErrCB = false;
       
  2330         }
       
  2331         
       
  2332         
       
  2333         var criteria = new Object();
       
  2334         modifyObjectBaseProp(criteria);
       
  2335         criteria.Type = "Landmark";
       
  2336         criteria.Data = new Object();
       
  2337         modifyObjectBaseProp(criteria.Data);
       
  2338         //replace all '/' to '\' and remove file:// or file:///
       
  2339         if (destFileUri.slice(0, 7) == "file://") {
       
  2340             destFileUri = destFileUri.slice(7);
       
  2341         }
       
  2342         else 
       
  2343             if (destFileUri.slice(0, 8) == "file:///") {
       
  2344                 destFileUri = destFileUri.slice(8);
       
  2345             }
       
  2346             else {
       
  2347                 throw new DeviceAPIError(error.INVALID_ARG_ERR, "destFileUri is not in URI format");
       
  2348             }
       
  2349         while (destFileUri.search("/") != -1) {
       
  2350             destFileUri = destFileUri.replace("/", "\\");
       
  2351         }
       
  2352         criteria.Data.DestinationFile = destFileUri;
       
  2353         criteria.Data.IdList = landmarkIdList;
       
  2354         criteria.Data.MimeType = mimetype;
       
  2355 		
       
  2356 		this.temporarySCb = callback;
       
  2357         this.temporaryECb = ErrorCallback;
       
  2358 		
       
  2359         var rval = this.so.IDataSource.Export(criteria, this.exportLandmarksCb);
       
  2360         if (rval.TransactionID) {
       
  2361             glob_obj.addToGlobalArray(rval.TransactionID, callback, ErrorCallback);
       
  2362         }
       
  2363         if (rval.ErrorCode != 0) {
       
  2364             switch (rval.ErrorCode) {
       
  2365                 case err_missing_argument:
       
  2366                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  2367                     break;
       
  2368                 case err_bad_argument:
       
  2369                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  2370                     break;
       
  2371                 case err_ServiceNotSupported:
       
  2372                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  2373                     break;
       
  2374                 case err_InvalidService_Argument:
       
  2375                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  2376                     break;
       
  2377                 default:
       
  2378                     throw new DeviceAPIError(-101, "unknown error message");
       
  2379             }
       
  2380         }
       
  2381         return rval.TransactionID;
       
  2382     } 
       
  2383     catch (e) {
       
  2384         throw e;
       
  2385     }
       
  2386 }
       
  2387 
       
  2388 function __sp_landmarks_organize_cb(arg1, arg2, arg3){
       
  2389     var callback;
       
  2390     var ErrorCallback;
       
  2391 	if (this.temporarySCb) {
       
  2392         category_cb = this.temporarySCb;
       
  2393         ErrorCallback = this.temporaryECb;
       
  2394         this.temporarySCb = null;
       
  2395         this.temporaryECb = null;
       
  2396     }
       
  2397     else {
       
  2398         CbObj = glob_obj.getFromArray(arg1);
       
  2399         if (CbObj) {
       
  2400             callback = CbObj.success_cb;
       
  2401             ErrorCallback = CbObj.error_cb;
       
  2402         }
       
  2403         
       
  2404         else {
       
  2405             alert("Landmarks: __sp_landmarks_organize_cb: Callback not found ");
       
  2406             return;
       
  2407         }
       
  2408     }
       
  2409     
       
  2410     //if there is an error invoke user supplied error callback
       
  2411     if (arg2 == 4 || arg3.ErrorCode) { //indicates an error
       
  2412         var scbErrCode = convertFromPS2JS(arg3.ErrorCode);
       
  2413         var erroObject = new DeviceAPIError(scbErrCode, arg3.ErrorMessage);
       
  2414         if (ErrorCallback) {
       
  2415             ErrorCallback(erroObject);
       
  2416         }
       
  2417     }
       
  2418     else {
       
  2419         //in case of success invoke user supplied scb
       
  2420         callback();
       
  2421     }
       
  2422     glob_obj.removeFromArray(arg1);
       
  2423 }
       
  2424 
       
  2425 function __sp_landmarks_organize(callback, landmarkIdList, categoryId, associate, ErrorCallback){
       
  2426     try {
       
  2427         var error = new DeviceAPIError(0, "dummy");
       
  2428         var isErrCB = true;//indicates a valid errocalback has been supplied
       
  2429         if (callback === undefined) {
       
  2430             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SuccessCallback is missing');
       
  2431         }
       
  2432         else {
       
  2433             if (((callback === null) ||
       
  2434             (callback === "")) &&
       
  2435             (typeof(callback) != "number")) {
       
  2436                 throw new DeviceAPIError(error.MISSING_ARG_ERR, 'SuccessCallback is missing');
       
  2437             }
       
  2438             else 
       
  2439                 if (typeof(callback) != 'function') {
       
  2440                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid SuccessCallback argument');
       
  2441                 }
       
  2442         }
       
  2443         
       
  2444         if (landmarkIdList === undefined || landmarkIdList === null) {
       
  2445             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'landmarkIdList is missing');
       
  2446         }
       
  2447         else 
       
  2448             if (typeof(landmarkIdList) !== "object") {
       
  2449                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid LandmarkItem argument');
       
  2450             }
       
  2451         
       
  2452         if (categoryId === undefined || categoryId === null) {
       
  2453             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'categoryId is missing');
       
  2454         }
       
  2455         else 
       
  2456             if (typeof(categoryId) !== "string") {
       
  2457                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid categoryId argument');
       
  2458             }
       
  2459         
       
  2460         if (associate === undefined || associate === null) {
       
  2461             associate = true;
       
  2462         }
       
  2463         else 
       
  2464             if (typeof(associate) !== "boolean") {
       
  2465                 throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid associate argument');
       
  2466             }
       
  2467         
       
  2468         if ((ErrorCallback != undefined)) {
       
  2469             if ((!ErrorCallback) &&
       
  2470             (typeof(ErrorCallback) != "number")) {
       
  2471                 isErrCB = false;
       
  2472             }
       
  2473             else 
       
  2474                 if ((typeof(ErrorCallback) != 'function')) {
       
  2475                     throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid ErrorCallback callback');
       
  2476                 }
       
  2477             
       
  2478         }
       
  2479         else {
       
  2480             isErrCB = false;
       
  2481         }
       
  2482         
       
  2483         
       
  2484         
       
  2485         var criteria = new Object();
       
  2486         modifyObjectBaseProp(criteria);
       
  2487         criteria.Type = "Landmark";
       
  2488         criteria.Data = new Object();
       
  2489         modifyObjectBaseProp(criteria.Data);
       
  2490         criteria.Data.id = categoryId;
       
  2491         criteria.Data.IdList = landmarkIdList;
       
  2492         if (associate) 
       
  2493             criteria.OperationType = "Associate";
       
  2494         else 
       
  2495             criteria.OperationType = "Disassociate";
       
  2496 		
       
  2497 		this.temporarySCb = callback;
       
  2498         this.temporaryECb = ErrorCallback;
       
  2499 		
       
  2500         var rval = this.so.IDataSource.Organise(criteria, this.organizeLandmarksCb);
       
  2501         if (rval.TransactionID) {
       
  2502             glob_obj.addToGlobalArray(rval.TransactionID, callback, ErrorCallback);
       
  2503         }
       
  2504         
       
  2505         if (rval.ErrorCode != 0) {
       
  2506             switch (rval.ErrorCode) {
       
  2507                 case err_missing_argument:
       
  2508                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  2509                     break;
       
  2510                 case err_bad_argument:
       
  2511                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  2512                     break;
       
  2513                 case err_ServiceNotSupported:
       
  2514                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  2515                     break;
       
  2516                 case err_InvalidService_Argument:
       
  2517                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  2518                     break;
       
  2519                 default:
       
  2520                     throw new DeviceAPIError(-101, "unknown error message");
       
  2521             }
       
  2522         }
       
  2523         return rval.TransactionID;
       
  2524     } 
       
  2525     catch (e) {
       
  2526         throw e;
       
  2527     }
       
  2528 }
       
  2529 
       
  2530 function __sp_landmarks_cancel(transactionId){
       
  2531     try {
       
  2532         var error = new DeviceAPIError(0, "dummy");
       
  2533         if ((transactionId === undefined) ||
       
  2534         (transactionId === null) ||
       
  2535         (transactionId === "")) {
       
  2536             throw new DeviceAPIError(error.MISSING_ARG_ERR, 'transactionId is missing');
       
  2537         }
       
  2538         
       
  2539         if (typeof(transactionId) != "number") {
       
  2540             throw new DeviceAPIError(error.INVALID_ARG_ERR, 'invalid transactionId argument');
       
  2541         }
       
  2542         if (transactionId < 0) {
       
  2543             throw new DeviceAPIError(error.DATA_NOT_FOUND_ERR, 'non-existent transactionId');
       
  2544         }
       
  2545         
       
  2546         var criteria = new Object();
       
  2547         modifyObjectBaseProp(criteria);
       
  2548         criteria.TransactionID = transactionId;
       
  2549         var rval = this.so.IDataSource.Cancel(criteria);
       
  2550         if (rval.ErrorCode != 0) {
       
  2551             switch (rval.ErrorCode) {
       
  2552                 case err_missing_argument:
       
  2553                     throw new DeviceAPIError(error.MISSING_ARG_ERR, rval.ErrorMessage);
       
  2554                     break;
       
  2555                 case err_bad_argument:
       
  2556                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  2557                     break;
       
  2558                 case err_ServiceNotSupported:
       
  2559                     throw new DeviceAPIError(error.NOT_SUPPORTED_ERR, rval.ErrorMessage);
       
  2560                     break;
       
  2561                 case err_InvalidService_Argument:
       
  2562                     throw new DeviceAPIError(error.INVALID_ARG_ERR, rval.ErrorMessage);
       
  2563                     break;
       
  2564                 default:
       
  2565                     throw new DeviceAPIError(-101, "unknown error message");
       
  2566             }
       
  2567         }
       
  2568     } 
       
  2569     catch (e) {
       
  2570         throw e;
       
  2571     }
       
  2572 }