serviceproviders/sapi_location/src/locationinterface.cpp
changeset 10 fc9cf246af83
parent 5 989d2f495d90
child 16 44bb89c96acb
equal deleted inserted replaced
5:989d2f495d90 10:fc9cf246af83
    26 #include "locationcb.h"
    26 #include "locationcb.h"
    27 #include "locationservice.h"
    27 #include "locationservice.h"
    28 #include "locationerrormessage.hrh"
    28 #include "locationerrormessage.hrh"
    29 using namespace LIW;
    29 using namespace LIW;
    30 
    30 
    31 /**
       
    32  * KMAXACTIVEOBJ identifies maximum number of entries in callback registration table
       
    33  * presently it stores only two entries .
       
    34  */
       
    35 const TInt KMAXACTIVEOBJ = 2;
       
    36 
    31 
    37 
    32 
    38 //Error code for bad time
    33 //Error code for bad time
    39 const TInt KErrBadTime = -125;
    34 const TInt KErrBadTime = -125;
    40 
    35 
    48     {
    43     {
    49  	 
    44  	 
    50  	 delete iLocationService ;
    45  	 delete iLocationService ;
    51  	  	 
    46  	  	 
    52  	 
    47  	 
    53  	 iLocationService = NULL ;
       
    54  	 
    48  	 
    55  	 for(TInt iter = 0 ; iter < iHandleCB.Count() ; ++iter)
    49  	 for(TInt iter = 0 ; iter < iHandleCB.Count() ; ++iter)
    56  	 	{
    50  	 	{
    57  	 	 delete iHandleCB[iter] ;
    51  	 	 delete iHandleCB[iter] ;
    58  	 	}
    52  	 	}
    64 
    58 
    65 /**
    59 /**
    66  * Default constructor
    60  * Default constructor
    67  */
    61  */
    68  
    62  
    69  CLocationInterface :: CLocationInterface()
    63 CLocationInterface::CLocationInterface()
    70     {
    64     {
    71  	iGenericPosInfo = HPositionGenericInfo :: NewL() ; 
    65     //No Implementation Required Here
    72  	
    66     }
    73  	if(!iGenericPosInfo)
    67 void CLocationInterface::ConstructL()
    74  	    {
    68     {
    75  		User ::Leave(KErrNoMemory) ;
    69     iGenericPosInfo = HPositionGenericInfo::NewL() ;
    76  	    }
    70 
    77  	
    71     if ( !iGenericPosInfo )
    78  	
    72         {
    79  	for ( TInt count = 0;count < KMAXACTIVEOBJ ; count++)
    73         User::Leave( KErrNoMemory ) ;
    80     	{
    74         }
    81 		iHandleCB.Insert(NULL,count);
    75 
    82 	    }
    76     iLocationService = CLocationService::NewL() ;
    83 	
    77     User::LeaveIfError( iLocationService->GetModuleInfo( iModuleInfo ) );
    84  	
    78     User::LeaveIfError( this->SetSupportedFields() );
       
    79     }
       
    80 
       
    81 
       
    82 /**
       
    83  * This function is a static method to create iLocatinInterface object
       
    84  * return pointer to constructed object else paincs with symbian painc 
       
    85  * code
       
    86  */
       
    87 
       
    88 CLocationInterface* CLocationInterface::NewL()
       
    89     {
       
    90     CLocationInterface* self = new(ELeave)CLocationInterface();
       
    91 
       
    92     CleanupStack::PushL( self ) ;
       
    93 
       
    94     self->ConstructL();
       
    95 
       
    96     CleanupStack::Pop( self ) ;
       
    97     return self;
       
    98 
    85     }
    99     }
    86  TInt  CLocationInterface::ConvertToSapiError(TInt aSymbianErr)
   100  TInt  CLocationInterface::ConvertToSapiError(TInt aSymbianErr)
    87 	 {
   101 	 {
    88 	 TInt sapiErr(SErrGeneralError);
   102 	 TInt sapiErr(SErrGeneralError);
    89 	 switch (aSymbianErr)
   103 	 switch (aSymbianErr)
   132 		case SErrMissingArgument:
   146 		case SErrMissingArgument:
   133 			{
   147 			{
   134 				sapiErr = SErrMissingArgument;
   148 				sapiErr = SErrMissingArgument;
   135 				break;
   149 				break;
   136 			}
   150 			}
   137     	}
   151 		default:
       
   152 			{
       
   153 				sapiErr = SErrGeneralError;
       
   154 			}
       
   155     }
   138     return sapiErr;
   156     return sapiErr;
   139 
   157 
   140 	 
   158 	 
   141 	 }
   159 	 }
   142  /**
   160  /**
   154     {
   172     {
   155 
   173 
   156 
   174 
   157     aOutParamList.Reset() ;
   175     aOutParamList.Reset() ;
   158     
   176     
   159     
   177     /*
   160     
   178      * To indicate position based parsing for all the parameters
       
   179      */
       
   180     TBool posBasedFlag = EFalse;
   161     if( aCmdOptions & KLiwOptCancel ) // for cancel asynchronous request
   181     if( aCmdOptions & KLiwOptCancel ) // for cancel asynchronous request
   162         {
   182         {
   163           
   183           
   164           TInt ret = 0 ;
   184           TInt ret = 0 ;
   165           
   185           
   182 		       }
   202 		       }
   183                 
   203                 
   184             }
   204             }
   185             
   205             
   186           TInt32 transid = (transidparam->Value()).AsTInt32() ;
   206           TInt32 transid = (transidparam->Value()).AsTInt32() ;
   187           MLiwNotifyCallback* callBack = RequestCancel(transid) ;
   207         //Get Callback object curresponding to this transaction Id 
   188           
   208         MLiwNotifyCallback* callBack = NULL;
       
   209         TInt ncalls = iHandleCB.Count() ;
       
   210 
       
   211         for (TInt iter = 0; iter < ncalls; ++iter)
       
   212             {
       
   213 
       
   214             if (iHandleCB[iter])
       
   215                 {
       
   216                 if (iHandleCB[iter]->GetTransactionId() == transid)
       
   217                     {
       
   218                     //Get the callback object associated with this Transaction Id
       
   219                     callBack = iHandleCB[iter]->GetCallBackobj();
       
   220 
       
   221                     }
       
   222                 }
       
   223 
       
   224             }
   189           if (!callBack)
   225           if (!callBack)
   190 	          {
   226 	          {
   191 	          aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
   227 	          aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
   192                                       TLiwVariant(KCancelInvalidTransactionId)));
   228                                       TLiwVariant(KCancelInvalidTransactionId)));
   193               User::Leave(KErrNotFound);	
   229               User::Leave(KErrNotFound);	
   194 	          }
   230 	          }
   195           
   231           
   196           
   232         //Cancel the exisiting request
       
   233         User::LeaveIfError(iLocationService->CancelService(transid));
   197           
   234           
   198           //Send notification about the cancelled state to consumer
   235           //Send notification about the cancelled state to consumer
   199           callBack->HandleNotifyL(transid  , KLiwEventCanceled , 
   236           callBack->HandleNotifyL(transid  , KLiwEventCanceled , 
   200                                     aOutParamList,   aInParamList) ;
   237                                     aOutParamList,   aInParamList) ;
   201             
   238             
       
   239         }
   202           
   240           
       
   241     //LastKnownLocation Request is made by consumer
       
   242     else if (aCmdName == KCmdLastLocation)
       
   243         {
       
   244         //Extract Update options from input List
       
   245         User::LeaveIfError(iLocationService->GetLastKnownLoc(iPosition)) ;            
       
   246         TUint category1 = EBasicInfo;
       
   247 
       
   248         iGenericPosInfo->SetPosition(iPosition);
       
   249         GetLocationInfo(aOutParamList, category1) ;
   203 
   250 
   204         }
   251         }
   205 
   252 
   206     
   253     
   207     //GetLocation request is made by consumer
   254     //GetLocation request is made by consumer
   208     else if(aCmdName == KCmdGetLocation)                         
   255     else if( !( aCmdName.CompareF( KCmdGetLocation ) ) )                         
   209         {
   256         {
   210         TInt ret  =KErrNone ;
   257         TInt ret  =KErrNone ;
   211         //Extract category of Location Information user is interested in
   258         //Extract category of Location Information user is interested in
   212         TInt index = 0;
   259         TInt index = 0;
   213         TPtrC posInfoCategory(KLocationBasicinfo);
   260         TPtrC posInfoCategory(KLocationBasicinfo);
   237 				        aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   284 				        aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   238                                                TLiwVariant( KGetLocationWrongInfoType ) ) );
   285                                                TLiwVariant( KGetLocationWrongInfoType ) ) );
   239                         User::Leave( KErrArgument );
   286                         User::Leave( KErrArgument );
   240 				        //Leave with error code	
   287 				        //Leave with error code	
   241 				        }
   288 				        }
       
   289                     //indicates that position based parsing has been done 
       
   290                     posBasedFlag = ETrue;
   242 	                posInfoCategory.Set( variant.AsDes() );
   291 	                posInfoCategory.Set( variant.AsDes() );
   243 	                
   292 	                
   244 	                //Set infoFlag to indicate user has supplied category of location information
   293 	                //Set infoFlag to indicate user has supplied category of location information
   245 	                infoFlag = TRUE;
   294 	                infoFlag = TRUE;
   246 			        
   295 			        
   265             }
   314             }
   266 
   315 
   267         //if callback is given for this command then it will be a async request
   316         //if callback is given for this command then it will be a async request
   268         if( aCallback && ( KLiwOptASyncronous & aCmdOptions ) ) 
   317         if( aCallback && ( KLiwOptASyncronous & aCmdOptions ) ) 
   269             {
   318             {
   270             LocationInterfaceCB  *callback = LocationInterfaceCB :: NewL (aCallback ,  &aInParamList , 
       
   271             														      &iModuleInfo , transid) ;
       
   272             CleanupStack :: PushL(callback) ;														      
       
   273             
       
   274             callback->SetRequestType(KGetLocationCB) ;
       
   275 
   319 
   276            //Extract Update options from input List
   320            //Extract Update options from input List
   277         	
   321         	
   278         	index = 0;
   322         	index = 0;
   279         	const TLiwGenericParam *smapparam = aInParamList.FindFirst(index , KUpdateOptionMap) ;
   323         	const TLiwGenericParam *smapparam = aInParamList.FindFirst(index , KUpdateOptionMap) ;
   282         	TUint category = EBasicInfo ;
   326         	TUint category = EBasicInfo ;
   283         	//Check for possibility of position based parsing
   327         	//Check for possibility of position based parsing
   284         	if ( !smapparam )
   328         	if ( !smapparam )
   285 	        {
   329 	        {
   286 	        TInt count = aInParamList.Count();
   330 	        TInt count = aInParamList.Count();
   287 	        if (count == 2)	
   331                 if ( count >= 2 && posBasedFlag )	
   288 		        {
   332 		        {
   289 		        smapparam = &aInParamList[Index1];
   333 		        smapparam = &aInParamList[Index1];
   290 		        if (smapparam)
   334 		        if (smapparam)
   291 			        {
   335 			        {
   292 			        const CLiwMap  *updateOptionMap = (smapparam->Value() ).AsMap() ;
   336 			        const CLiwMap  *updateOptionMap = (smapparam->Value() ).AsMap() ;
   293 			        if( !updateOptionMap )
   337 			        if( !updateOptionMap )
   294 				        {
   338 				        {
   295 				        aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   339 				        aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   296                                                TLiwVariant( KGetLocationWrongupdateMap ) ) );
   340                                                TLiwVariant( KGetLocationWrongupdateMap ) ) );
   297                         CleanupStack :: Pop( callback ) ;
       
   298                         delete callback;
       
   299                         User::Leave( KErrArgument );
   341                         User::Leave( KErrArgument );
   300 				        }
   342 				        }
   301                 	TInt error = SetUpdateOption(updateOptionVal,updateOptionMap);
   343                 	TInt error = SetUpdateOption(updateOptionVal,updateOptionMap);
   302                 	if( KErrBadTime == error )
   344                 	if( KErrBadTime == error )
   303 	                	{
   345 	                	{
   304 	                	aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   346 	                	aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   305                                                TLiwVariant( KGetLocationNegativeTime ) ) );
   347                                                TLiwVariant( KGetLocationNegativeTime ) ) );
   306                         CleanupStack :: Pop( callback ) ;
       
   307                         delete callback;
       
   308                         User::Leave( KErrArgument );
   348                         User::Leave( KErrArgument );
   309 	                	
   349 	                	
   310 	                	}
   350 	                	}
   311                 	updateoptions = &updateOptionVal ;
   351                 	updateoptions = &updateOptionVal ;
   312 			        
   352 			        
   321     	        const CLiwMap  *updateOptionMap = (smapparam->Value() ).AsMap() ;
   361     	        const CLiwMap  *updateOptionMap = (smapparam->Value() ).AsMap() ;
   322     	        if( !updateOptionMap )
   362     	        if( !updateOptionMap )
   323 			        {
   363 			        {
   324 			        aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   364 			        aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   325                                            TLiwVariant( KGetLocationWrongupdateMap ) ) );
   365                                            TLiwVariant( KGetLocationWrongupdateMap ) ) );
   326                     CleanupStack :: Pop( callback ) ;
       
   327                     delete callback;
       
   328                     User::Leave( KErrArgument );
   366                     User::Leave( KErrArgument );
   329 			        }
   367 			        }
   330     	        
   368     	        
   331                 TInt error = SetUpdateOption(updateOptionVal,updateOptionMap);
   369                 TInt error = SetUpdateOption(updateOptionVal,updateOptionMap);
   332             	if( KErrBadTime == error )
   370             	if( KErrBadTime == error )
   333                 	{
   371                 	{
   334                 	aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   372                 	aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   335                                            TLiwVariant( KGetLocationNegativeTime ) ) );
   373                                            TLiwVariant( KGetLocationNegativeTime ) ) );
   336                     CleanupStack :: Pop( callback ) ;
       
   337                     delete callback;
       
   338                     
   374                     
   339                     User::Leave( KErrArgument );
   375                     User::Leave( KErrArgument );
   340                 	
   376                 	
   341                 	}
   377                 	}
   342                 
   378                 
   343                 else if( KErrArgument == error )
   379                 else if( KErrArgument == error )
   344 	                {
   380 	                {
   345 	                aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   381 	                aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   346                                            TLiwVariant( KGetLocationBadUpdateOptions ) ) );
   382                                            TLiwVariant( KGetLocationBadUpdateOptions ) ) );
   347                     
   383                     
   348                     CleanupStack :: Pop( callback ) ;
       
   349                     delete callback;
       
   350                     
   384                     
   351                     User::Leave( KErrArgument );
   385                     User::Leave( KErrArgument );
   352 	                	
   386 	                	
   353 	                }
   387 	                }
   354 
   388 
   364             else if ( ( posInfoCategory != KLocationBasicinfo ) && ( infoFlag ) )
   398             else if ( ( posInfoCategory != KLocationBasicinfo ) && ( infoFlag ) )
   365 	            {
   399 	            {
   366 	            //this indicates a wrong supplied location info category by the user
   400 	            //this indicates a wrong supplied location info category by the user
   367 	            aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
   401 	            aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
   368                                       TLiwVariant(KGetLocationCategoryInfo)));
   402                                       TLiwVariant(KGetLocationCategoryInfo)));
   369                 CleanupStack :: Pop( callback ) ;
       
   370                 delete callback;
       
   371                 User::Leave(KErrArgument);	
   403                 User::Leave(KErrArgument);	
   372 	            }
   404 	            }
   373             
   405             
   374             //Extraction of update options and information complete so now send the request 
   406             //Extract EnableHighAccuracy param 
   375             //To core dll    
   407             index = 0;
   376 
   408             const TLiwGenericParam* highaccparam = 
   377             ret = iLocationService->GetLocationL(callback ,category,iFieldList,updateoptions) ;	
   409             aInParamList.FindFirst(index , KEnableHighAccuracy) ;
   378          
   410             TBool enableHighAcc = false;
   379             //aOutParamList.AppendL(TLiwGenericParam(KErrorCode , TLiwVariant((TInt32)ret))) ;
   411             if ( KErrNotFound == index )
   380             
       
   381             if(KErrNone != ret)
       
   382                 {
   412                 {
   383                     CleanupStack :: Pop(callback) ;
   413                 highaccparam = 0;
   384                     delete callback ;
   414                 TInt count = aInParamList.Count();
   385                     User::Leave(ret);
   415                 if ( count >= 3 && posBasedFlag ) 
   386                     
   416                     {
       
   417                     //Possiblity of Position based parsing
       
   418                     highaccparam = &aInParamList[Index2];
       
   419                     }
   387                 }
   420                 }
   388                 
   421 
       
   422             if( highaccparam )
       
   423                 {
       
   424                 if((highaccparam->Value().TypeId()) == EVariantTypeTBool)
       
   425                     enableHighAcc = highaccparam->Value().AsTBool();
       
   426 
       
   427                 else
       
   428                     {
       
   429                     aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   430                             TLiwVariant(KGetLocationBadEnableHighAcc) ) );
       
   431 
       
   432                     User::Leave(KErrArgument);
       
   433                     }
       
   434                 }
       
   435             LocationInterfaceCB* callback =
       
   436             LocationInterfaceCB::NewL(aCallback,
       
   437                     &aInParamList, &iModuleInfo, transid) ;
       
   438 
       
   439             CleanupStack :: PushL(callback) ;                   
       
   440             callback->SetRequestType(KGetLocationCB) ;
       
   441             
       
   442             iLocationService->GetLocationL(callback ,category,
       
   443                     iFieldList,updateoptions,enableHighAcc) ;	                    
   389             //Store the allocatioed address 
   444             //Store the allocatioed address 
   390             iHandleCB[KGetLocationCB] = callback ; 
   445             iHandleCB.Append(callback);
   391             //Append Transcationid to out list
   446             //Append Transcationid to out list
   392             aOutParamList.AppendL(TLiwGenericParam(KTransactionId, TLiwVariant(transid)));
   447             aOutParamList.AppendL(TLiwGenericParam(KTransactionId, TLiwVariant(transid)));
   393             CleanupStack :: Pop(callback) ;
   448             CleanupStack :: Pop(callback) ;
   394 
   449 
   395             }
   450             }
   408             const TPositionUpdateOptions* updateOptions = NULL ;
   463             const TPositionUpdateOptions* updateOptions = NULL ;
   409             //if a smapparam is NULL there exist possibility of position based parsing
   464             //if a smapparam is NULL there exist possibility of position based parsing
   410             if ( !smapparam )
   465             if ( !smapparam )
   411 	        {
   466 	        {
   412 	        TInt count = aInParamList.Count();
   467 	        TInt count = aInParamList.Count();
   413 	        if (count == 2)	
   468                 if (count >= 2 && posBasedFlag)	
   414 		        {
   469 		        {
   415 		        smapparam = &aInParamList[Index1];
   470 		        smapparam = &aInParamList[Index1];
   416 		        if (smapparam)
   471 		        if (smapparam)
   417 			        {
   472 			        {
   418 			        const CLiwMap  *updateOptionMap = (smapparam->Value() ).AsMap() ;
   473 			        const CLiwMap  *updateOptionMap = (smapparam->Value() ).AsMap() ;
   493 	            //this indicates a wrong supplied location info category by the user
   548 	            //this indicates a wrong supplied location info category by the user
   494 	            aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
   549 	            aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
   495                                       TLiwVariant(KGetLocationCategoryInfo)));
   550                                       TLiwVariant(KGetLocationCategoryInfo)));
   496                 User::Leave(KErrArgument);	
   551                 User::Leave(KErrArgument);	
   497 	            } 
   552 	            } 
   498 
   553             //Extract Enable High accuracy param 
   499             ret = iLocationService->GetLocationL(iGenericPosInfo,updateOptions) ; 
   554             index = 0;
   500             //aOutParamList.AppendL(TLiwGenericParam (KErrorCode , TLiwVariant((TInt32)ret))) ;
   555             const TLiwGenericParam* highaccparam = 
   501             
   556             aInParamList.FindFirst(index ,
   502             if(KErrNone != ret)
   557                     KEnableHighAccuracy) ;
       
   558             TBool enableHighAcc = false;
       
   559 
       
   560             if ( KErrNotFound == index )
   503                 {
   561                 {
   504                 User::Leave(ret);
   562                 highaccparam = 0;
   505                  
   563                 TInt count = aInParamList.Count();
       
   564                 if (count >= 3 && posBasedFlag) 
       
   565                     {
       
   566                     //Position based parsing to be done
       
   567                     highaccparam = &aInParamList[Index2];
       
   568                     }
   506                 }
   569                 }
       
   570 
       
   571             if( highaccparam )
       
   572                 {
       
   573                 if((highaccparam->Value().TypeId()) == EVariantTypeTBool)
       
   574                     enableHighAcc = highaccparam->Value().AsTBool();
       
   575 
       
   576                 else
       
   577                     {
       
   578                     aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   579                             TLiwVariant(KGetLocationBadEnableHighAcc) ) );                                       
       
   580                     User::Leave(KErrArgument);
       
   581                     }
       
   582                 }
       
   583 
       
   584             iLocationService->GetLocationL(iGenericPosInfo,
       
   585                     updateOptions,enableHighAcc) ;
   507             GetLocationInfo(aOutParamList,category) ; 
   586             GetLocationInfo(aOutParamList,category) ; 
   508             
   587             
   509             								                        
   588             								                        
   510 
   589 
   511             } //End of Synchronous getlocationcall
   590             } //End of Synchronous getlocationcall
   512         	
   591         	
   513             
   592             
   514        	    
   593        	    
   515         } //End of KCmdGetLocation
   594         } //End of KCmdGetLocation
   516 
   595 
   517     else if(  ( aCmdName == KCmdTraceLocation ) && ( aCallback ) && ( KLiwOptASyncronous & aCmdOptions ) )	//Trace request is made by consumer
   596     else if(  ( !(aCmdName.CompareF( KCmdTraceLocation )) ) && ( aCallback ) && ( KLiwOptASyncronous & aCmdOptions ) )	//Trace request is made by consumer
   518         {
   597         {
   519 
   598 
   520         TInt ret = KErrNone ;
   599         TInt ret = KErrNone ;
   521         TInt32 transid  = aCallback->GetTransactionID() ;
   600         TInt32 transid  = aCallback->GetTransactionID() ;
   522         TInt index = 0;
   601         TInt index = 0;
   544 				        //Leave with error code	
   623 				        //Leave with error code	
   545 				        }
   624 				        }
   546 	                posInfoCategory.Set( variant.AsDes() );
   625 	                posInfoCategory.Set( variant.AsDes() );
   547 			        
   626 			        
   548 			        	
   627 			        	
       
   628                     posBasedFlag = ETrue;
   549 			        }
   629 			        }
   550 		        	
   630 		        	
   551 		        }
   631 		        }
   552 	        }
   632 	        }
   553         
   633         
   566 			        
   646 			        
   567             
   647             
   568             }
   648             }
   569         
   649         
   570 
   650 
   571         LocationInterfaceCB  *callback = LocationInterfaceCB :: NewL (aCallback,
       
   572         															  &aOutParamList,
       
   573         															  &iModuleInfo,
       
   574         															  transid ) ;
       
   575         CleanupStack :: PushL(callback) ;
       
   576         callback->SetRequestType(KTraceCB) ;
       
   577         
   651         
   578 
   652 
   579         
   653         
   580         	//Default posinfo Category is basic info
   654         	//Default posinfo Category is basic info
   581         	TUint catergory = EBasicInfo ;
   655         	TUint catergory = EBasicInfo ;
   586         	smapparam = aInParamList.FindFirst(index , KUpdateOptionMap) ;
   660         	smapparam = aInParamList.FindFirst(index , KUpdateOptionMap) ;
   587         	//if a smapparam is NULL there exist possibility of position based parsing
   661         	//if a smapparam is NULL there exist possibility of position based parsing
   588             if ( !smapparam )
   662             if ( !smapparam )
   589 	        {
   663 	        {
   590 	        TInt count = aInParamList.Count();
   664 	        TInt count = aInParamList.Count();
   591 	        if (count == 2)	
   665             if (count >= 2 && posBasedFlag)	
   592 		        {
   666 		        {
   593 		        smapparam = &aInParamList[Index1];
   667 		        smapparam = &aInParamList[Index1];
   594 		        if (smapparam)
   668 		        if (smapparam)
   595 			        {
   669 			        {
   596 			        const CLiwMap  *updateOptionMap = (smapparam->Value() ).AsMap() ;
   670 			        const CLiwMap  *updateOptionMap = (smapparam->Value() ).AsMap() ;
   597 		        if( !updateOptionMap )
   671 		        if( !updateOptionMap )
   598 			        {
   672 			        {
   599 			        aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   673 			        aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   600                                            TLiwVariant( KTraceWrongupdateMap ) ) );
   674                                            TLiwVariant( KTraceWrongupdateMap ) ) );
   601                     CleanupStack :: Pop( callback ) ;
       
   602                     delete callback;
       
   603                     
   675                     
   604                     User::Leave( KErrArgument );
   676                     User::Leave( KErrArgument );
   605 			        }
   677 			        }
   606 
   678 
   607             	TInt error = SetUpdateOption(updateOptionVal,updateOptionMap);
   679             	TInt error = SetUpdateOption(updateOptionVal,updateOptionMap);
   608             	if( KErrBadTime == error )
   680             	if( KErrBadTime == error )
   609                 	{
   681                 	{
   610                 	aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   682                 	aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   611                                            TLiwVariant( KTraceNegativeTime ) ) );
   683                                            TLiwVariant( KTraceNegativeTime ) ) );
   612                     CleanupStack :: Pop( callback ) ;
       
   613                     delete callback;
       
   614                     User::Leave( KErrArgument );
   684                     User::Leave( KErrArgument );
   615                 	
   685                 	
   616                 	}
   686                 	}
   617                 else if( KErrArgument == error )
   687                 else if( KErrArgument == error )
   618 	                {
   688 	                {
   619 	                aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   689 	                aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   620                                            TLiwVariant( KTraceBadUpdateOptions ) ) );
   690                                            TLiwVariant( KTraceBadUpdateOptions ) ) );
   621                     
   691                     
   622                     CleanupStack :: Pop( callback ) ;
       
   623                     delete callback;
       
   624                     
   692                     
   625                     
   693                     
   626                     User::Leave( KErrArgument );
   694                     User::Leave( KErrArgument );
   627 	                	
   695 	                	
   628 	                }
   696 	                }
   641         	    const CLiwMap  *updateOptionMap = (smapparam->Value()).AsMap() ; 
   709         	    const CLiwMap  *updateOptionMap = (smapparam->Value()).AsMap() ; 
   642 	    	    if( !updateOptionMap )
   710 	    	    if( !updateOptionMap )
   643 			        {
   711 			        {
   644 			        aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   712 			        aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   645 	                                       TLiwVariant( KGetLocationWrongupdateMap ) ) );
   713 	                                       TLiwVariant( KGetLocationWrongupdateMap ) ) );
   646 	                CleanupStack :: Pop( callback ) ;
       
   647 	                delete callback;
       
   648 	                
   714 	                
   649 	                User::Leave( KErrArgument );
   715 	                User::Leave( KErrArgument );
   650 			        }
   716 			        }
   651 
   717 
   652 	    	    TInt error = SetUpdateOption(updateOptionVal,updateOptionMap);
   718 	    	    TInt error = SetUpdateOption(updateOptionVal,updateOptionMap);
   653 	        	if( KErrBadTime == error )
   719 	        	if( KErrBadTime == error )
   654 	            	{
   720 	            	{
   655 	            	aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   721 	            	aOutParamList.AppendL( TLiwGenericParam( KErrorMessage,
   656 	                                       TLiwVariant( KTraceNegativeTime ) ) );
   722 	                                       TLiwVariant( KTraceNegativeTime ) ) );
   657 	                CleanupStack :: Pop( callback ) ;
       
   658 	                delete callback;
       
   659 	                User::Leave( KErrArgument );
   723 	                User::Leave( KErrArgument );
   660 	            	
   724 	            	
   661 	            	}
   725 	            	}
   662 	             else if( KErrArgument == error )
   726 	             else if( KErrArgument == error )
   663 	                {
   727 	                {
   682 	            {
   746 	            {
   683 	            //this indicates a wrong supplied location info category by the user
   747 	            //this indicates a wrong supplied location info category by the user
   684 	            aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
   748 	            aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
   685                                       TLiwVariant(KTraceCategoryInfo)));
   749                                       TLiwVariant(KTraceCategoryInfo)));
   686 				
   750 				
   687 				CleanupStack::Pop(callback);
       
   688 				delete callback;
       
   689 	            User::Leave(KErrArgument);	
   751 	            User::Leave(KErrArgument);	
   690 	            }
   752 	            }
   691 	        	
   753         //Extract Enable High accuracy param 
   692 		ret = iLocationService->TraceL(callback , catergory , iFieldList , updateOption ) ;
   754         index = 0;
   693         //TLiwGenericParam errorParm(KErrorCode , TLiwVariant((TInt32)ret)) ;
   755         const TLiwGenericParam* highaccparam = aInParamList.FindFirst(index ,
   694         //aOutParamList.AppendL(errorParm) ; 
   756                 KEnableHighAccuracy) ;
   695 
   757         TBool enableHighAcc = false;
   696         if(KErrNone != ret)
   758         if ( KErrNotFound == index )
   697             {
   759             {
   698                 CleanupStack :: Pop(callback) ;
   760             highaccparam = 0;
   699                 delete callback ;
   761             TInt count = aInParamList.Count();
   700                 User::Leave(ret);
   762             if (count >= 3 && posBasedFlag) 
       
   763                 {
       
   764                 //Possibility of Position based parsing
       
   765                 highaccparam = &aInParamList[Index2];
       
   766                 }
   701             }
   767             }
   702 
   768 
   703         
   769         if( highaccparam )
   704         iHandleCB[KTraceCB] = callback ;
   770             {
   705         aOutParamList.AppendL(TLiwGenericParam (KTransactionId , TLiwVariant(transid))) ; //Append Transcationid to out list
   771             if((highaccparam->Value().TypeId()) == EVariantTypeTBool)
       
   772                 enableHighAcc = highaccparam->Value().AsTBool(); 
       
   773 
       
   774             else
       
   775                 {
       
   776                 aOutParamList.AppendL(TLiwGenericParam(KErrorMessage,
       
   777                         TLiwVariant(KGetLocationBadEnableHighAcc) ) );
       
   778 
       
   779                 User::Leave(KErrArgument);
       
   780                 }
       
   781             }       
       
   782 
       
   783         LocationInterfaceCB* callback =
       
   784         LocationInterfaceCB::NewL(aCallback,
       
   785                 &aOutParamList, &iModuleInfo, transid) ;
       
   786         CleanupStack :: PushL(callback) ;
       
   787         callback->SetRequestType(KTraceCB) ;
       
   788 
       
   789 
       
   790         iLocationService->TraceL( callback, catergory,iFieldList, 
       
   791                 updateOption,enableHighAcc );
       
   792         iHandleCB.Append(callback);
       
   793         aOutParamList.AppendL(TLiwGenericParam(KTransactionId,
       
   794                 TLiwVariant(transid))) ; //Append Transcationid to out list
   706 
   795 
   707         CleanupStack :: Pop(callback) ;
   796         CleanupStack :: Pop(callback) ;
   708         
   797         
   709         } //End of KCmdTraceLocation
   798         } //End of KCmdTraceLocation
   710 
   799 
   711     else if(aCmdName == KCmdCancelRequest)	  //Cancel request is made by consumer 
   800     else if(!( aCmdName.CompareF( KCmdCancelRequest ) ) )	  //Cancel request is made by consumer 
   712         {
   801         {
   713 
   802 
   714          TInt index = 0 ;
   803          TInt index = 0 ;
   715          TInt count = aInParamList.Count();
   804          TInt count = aInParamList.Count();
   716          
   805          
   751         if(requesttype == KRequestTrace )
   840         if(requesttype == KRequestTrace )
   752             {
   841             {
   753             	
   842             	
   754             ret = iLocationService->CancelOnGoingService(ECancelTrace) ;
   843             ret = iLocationService->CancelOnGoingService(ECancelTrace) ;
   755             
   844             
   756             if(KErrNone == ret) ;
   845             if (KErrNone == ret)
   757                 {
   846                 {
   758                 delete iHandleCB[KTraceCB] ;
   847                 TInt ncal = iHandleCB.Count() ;
   759                 iHandleCB[KTraceCB] = NULL ;    //Mark the slot as free 	
   848 
       
   849                 for (TInt iter = 0; iter < ncal; ++iter)
       
   850                     {
       
   851                     if (iHandleCB[iter])
       
   852                         {                           
       
   853                         if(iHandleCB[iter]->GetRequestType() == KTraceCB)
       
   854                             {
       
   855                             delete iHandleCB[iter];
       
   856                             iHandleCB[iter] = NULL;
       
   857                             break;
       
   858                             }
       
   859                         }
       
   860                     }
       
   861 
   760                 }
   862                 }
   761             
       
   762 
       
   763             }
   863             }
   764 
       
   765         else if(requesttype == KRequestGetLoc )
   864         else if(requesttype == KRequestGetLoc )
   766             {
   865             {
   767             		
   866             		
   768             ret = iLocationService->CancelOnGoingService(ECancelGetLocation) ;
   867             ret = iLocationService->CancelOnGoingService(ECancelGetLocation) ;
   769             
   868             
   770             if(!ret) 
   869             if(!ret) 
   771                 {
   870                 {
   772                 delete iHandleCB[KGetLocationCB] ;
   871                 TInt ncal1 = iHandleCB.Count() ;
   773                 iHandleCB[KGetLocationCB] = NULL ;    //Mark the slot as free 
   872 
       
   873                 for (TInt iter = 0; iter < ncal1; ++iter)
       
   874                     {
       
   875 
       
   876                     if (iHandleCB[iter])
       
   877                         {
       
   878 
       
   879                         if(iHandleCB[iter]->GetRequestType() == KGetLocationCB)
       
   880                             {
       
   881                             delete iHandleCB[iter];
       
   882                             iHandleCB[iter] = NULL;
       
   883                             break;
       
   884                             }
       
   885                         }
       
   886                     }
   774                 }
   887                 }
   775             
   888             
   776             }
   889             }
   777 
   890 
   778         else        //Invalid command 
   891         else        //Invalid command 
   786     
   899     
   787         User::LeaveIfError(ret);
   900         User::LeaveIfError(ret);
   788 
   901 
   789         } //End of KCmdCancelRequest 
   902         } //End of KCmdCancelRequest 
   790 
   903 
   791     else if(aCmdName == KRequestCalculate)
   904     else if(( !aCmdName.CompareF(KRequestCalculate) ) )
   792         {
   905         {
   793         TInt index = 0 ;
   906         TInt index = 0 ;
   794         //Flag set to 0 indicate no position based parsing need to be done
   907         //Flag set to 0 indicate no position based parsing need to be done
   795         // for subsequent parameters
   908         // for subsequent parameters
   796         TInt paramparsingFlag = 0;
   909         TInt paramparsingFlag = 0;
  1247     Val = pos.Latitude() ;
  1360     Val = pos.Latitude() ;
  1248     Result->InsertL(KLatitudeKey , TLiwVariant((TReal)Val)) ; 
  1361     Result->InsertL(KLatitudeKey , TLiwVariant((TReal)Val)) ; 
  1249             
  1362             
  1250     TReal32 altitude = pos.Altitude() ;
  1363     TReal32 altitude = pos.Altitude() ;
  1251             
  1364             
  1252 
  1365     if (!(Math::IsNaN(altitude)))
       
  1366         {
  1253     Result->InsertL(KAltitudeKey , TLiwVariant((TReal)altitude)) ; 
  1367     Result->InsertL(KAltitudeKey , TLiwVariant((TReal)altitude)) ; 
  1254 
  1368         }
  1255     
  1369 
       
  1370     TReal32 Val1;
       
  1371     Val1 = pos.HorizontalAccuracy();
       
  1372     if (!(Math::IsNaN(Val1)))
       
  1373         {
       
  1374         Result->InsertL(KHorAccuracy, TLiwVariant((TReal)Val1)) ;
       
  1375         }
       
  1376 
       
  1377     Val1 = pos.VerticalAccuracy();
       
  1378     if (!(Math::IsNaN(Val1)))
       
  1379         {
       
  1380         Result->InsertL(KVerAccuracy, TLiwVariant((TReal)Val1)) ;
       
  1381         }
  1256     TLiwVariant MapVariant(Result) ;
  1382     TLiwVariant MapVariant(Result) ;
  1257      
  1383      
  1258    
  1384    
  1259      TPositionModuleInfo :: TCapabilities  currCapability  = iModuleInfo.Capabilities() ;
  1385      TPositionModuleInfo :: TCapabilities  currCapability  = iModuleInfo.Capabilities() ;
  1260 
  1386 
  1391     CleanupStack :: Pop(Result) ;
  1517     CleanupStack :: Pop(Result) ;
  1392     		
  1518     		
  1393     }
  1519     }
  1394 
  1520 
  1395 
  1521 
  1396 /**
       
  1397  * Function CLocationInterface :: RequestCancel is used to cancel the pending async request if 
       
  1398  * returns the cancell status success if transaction id is valid else KErrGeneral error.
       
  1399  */
       
  1400  
  1522  
  1401 MLiwNotifyCallback* CLocationInterface :: RequestCancel(TInt32 aTranactionId/*,MLiwNotifyCallback** aCallBack*/)
       
  1402     {
       
  1403         TInt ncalls = iHandleCB.Count() ;
       
  1404         
       
  1405         for(TInt iter = 0 ; iter < ncalls ;  ++iter )
       
  1406             {
       
  1407                 
       
  1408                 if( iHandleCB[iter] )
       
  1409 	                {
       
  1410 	                if(iHandleCB[iter]->GetTransactionId() == aTranactionId)
       
  1411                     	{
       
  1412                         TInt requestType = iHandleCB[iter]->GetRequestType() ;
       
  1413                         TInt cancelType = ECancelGetLocation ;
       
  1414                         
       
  1415                         
       
  1416                         if(requestType == KTraceCB)
       
  1417                             {
       
  1418                                 cancelType = ECancelTrace ;
       
  1419                             }
       
  1420                         iLocationService->CancelOnGoingService(cancelType ) ;
       
  1421                         
       
  1422                         MLiwNotifyCallback* callobj = iHandleCB[iter]->GetCallBackobj();
       
  1423                         
       
  1424                         return( callobj ) ;
       
  1425                     	}	
       
  1426 	                }
       
  1427                 
       
  1428             }
       
  1429         
       
  1430         //No TransactionId Match found, return Error 
       
  1431         return NULL ;    
       
  1432     }
       
  1433  
       
  1434  /**
       
  1435   * This function is a static method to create iLocatinInterface object
       
  1436   * return pointer to constructed object else paincs with symbian painc 
       
  1437   * code
       
  1438   */
       
  1439   
       
  1440  CLocationInterface * CLocationInterface :: NewL()
       
  1441     {
       
  1442     CLocationInterface *self =  new(ELeave)CLocationInterface() ;
       
  1443 
       
  1444 
       
  1445 
       
  1446      
       
  1447     CleanupStack :: PushL(self) ;
       
  1448     self->iLocationService =  CLocationService :: NewL() ;
       
  1449     TInt error = (self->iLocationService)->GetModuleInfo(self->iModuleInfo) ;
       
  1450     	
       
  1451 
       
  1452     User :: LeaveIfError(error) ;
       
  1453 
       
  1454     error = (self->SetSupportedFields()) ;
       
  1455 
       
  1456     User :: LeaveIfError(error) ;
       
  1457     CleanupStack :: Pop(self) ;
       
  1458     return self ;
       
  1459     	
       
  1460     }
       
  1461 
  1523 
  1462 /**
  1524 /**
  1463  * Function : ExecuteCmdL , called directly by consumer, parses the input parameters and 
  1525  * Function : ExecuteCmdL , called directly by consumer, parses the input parameters and 
  1464  * then calls appropriate method on iLocationService object
  1526  * then calls appropriate method on iLocationService object
  1465  */
  1527  */
  1482 
  1544 
  1483     }
  1545     }
  1484 
  1546 
  1485 
  1547 
  1486  
  1548  
  1487  /**
       
  1488    * Function: ConvertPosToGenricList puts the latitude, longitude and altitude information 
       
  1489    *  into generic parmater list
       
  1490    *  This is an internal utility function
       
  1491   */
       
  1492   
       
  1493  void CLocationInterface :: ConvertPosToGenricListL( TPosition& aPos , CLiwGenericParamList& aOutList )
       
  1494     {
       
  1495     CLiwDefaultMap *Result = CLiwDefaultMap::NewL() ; 
       
  1496     TReal64 Val = aPos.Longitude() ;
       
  1497 
       
  1498     Result->InsertL(KLongitudeKey , TLiwVariant((TReal)Val)) ; //Inserting latitude
       
  1499 
       
  1500     Val = aPos.Latitude() ;
       
  1501     Result->InsertL(KLatitudeKey , TLiwVariant((TReal)Val)) ; //Inserting latitude
       
  1502             
       
  1503     TReal32 altitude = aPos.Altitude() ;
       
  1504             
       
  1505 
       
  1506     Result->InsertL(KAltitudeKey , TLiwVariant((TReal)altitude)) ; //Inserting altitude
       
  1507 
       
  1508     //Now Push this map into outparm list 
       
  1509      TLiwVariant MapVariant(Result) ;
       
  1510      
       
  1511      TLiwGenericParam outParm(KLocationMap , TLiwVariant(MapVariant)) ;
       
  1512     // outParm.SetSemanticId(EGenericParamLocation) ;
       
  1513      aOutList.AppendL(outParm) ;
       
  1514      Result->DecRef();
       
  1515      
       
  1516     }
       
  1517 
  1549 
  1518 /**
  1550 /**
  1519  * Internal function which is used to extract the coordinates from CLiwMap passed by consumer
  1551  * Internal function which is used to extract the coordinates from CLiwMap passed by consumer
  1520  */ 
  1552  */ 
  1521 
  1553