serviceproviders/sapi_location/locationservice/src/locationservice.cpp
changeset 32 8d692d9f828f
parent 22 fc9cf246af83
child 50 5dae2c62e9b6
equal deleted inserted replaced
27:44bb89c96acb 32:8d692d9f828f
    29  * Default constructor
    29  * Default constructor
    30  */
    30  */
    31  
    31  
    32  
    32  
    33 EXPORT_C CLocationService :: CLocationService()
    33 EXPORT_C CLocationService :: CLocationService()
       
    34 						  :iGenericPosInfo(NULL)
    34     {
    35     {
    35 	//No Implementation Required Here
    36 	//No Implementation Required Here
    36     }
    37     }
    37 
    38 
    38 
    39 
    58 
    59 
    59                 }
    60                 }
    60         }
    61         }
    61     iPosServer.Close();
    62     iPosServer.Close();
    62     iRegTable.Close();
    63     iRegTable.Close();
       
    64     delete iGenericPosInfo;
    63 
    65 
    64     }
    66     }
    65  
    67  
    66 /**
    68 /**
    67  * CLocationService::NewL
    69  * CLocationService::NewL
    87  */
    89  */
    88 
    90 
    89 void CLocationService::ConstructL()
    91 void CLocationService::ConstructL()
    90     {
    92     {
    91     User :: LeaveIfError(iPosServer.Connect());
    93     User :: LeaveIfError(iPosServer.Connect());
    92     CleanupClosePushL(iPosServer);
    94     //CleanupClosePushL(iPosServer);
       
    95     iGenericPosInfo = HPositionGenericInfo::NewL() ;
       
    96 
       
    97     if ( !iGenericPosInfo )
       
    98         {
       
    99         User::Leave( KErrNoMemory ) ;
       
   100         }
    93     
   101     
    94     //Get the module id of the default module available
   102     //Get the module id of the default module available
    95     User :: LeaveIfError(iPosServer.GetDefaultModuleId(iModuleId));
   103     //User :: LeaveIfError(iPosServer.GetDefaultModuleId(iModuleId));
    96 
   104 
    97     CleanupStack::Pop(&iPosServer);
   105     //CleanupStack::Pop(&iPosServer);
    98     }
   106     }
    99 
   107 
   100 /**
   108 /**
   101  * CLocationService::GetHighAccuracyModule
   109  * CLocationService::GetHighAccuracyModule
   102  * This function returns the module id of highest accuracy 
   110  * This function returns the module id of highest accuracy 
   109     TUint numOfModules = 0;
   117     TUint numOfModules = 0;
   110 
   118 
   111     //Flags used for indicating if a particular module is found
   119     //Flags used for indicating if a particular module is found
   112     TInt termInternalFlag = 0;   
   120     TInt termInternalFlag = 0;   
   113     TInt termFlag = 0 ,assisFlag = 0 ,networkFlag = 0,unknownFlag = 0;
   121     TInt termFlag = 0 ,assisFlag = 0 ,networkFlag = 0,unknownFlag = 0;
   114     TInt err;
   122     //TInt err;
   115     
   123     
   116     User::LeaveIfError(iPosServer.GetNumModules(numOfModules));
   124     User::LeaveIfError(iPosServer.GetNumModules(numOfModules));
   117         
   125         
   118 
   126 
   119     for( TInt i=0;i< numOfModules;i++ )
   127     for( TInt i=0;i< numOfModules;i++ )
   169  * CLocationService :: GetLocationL with update options, this function gets users current location
   177  * CLocationService :: GetLocationL with update options, this function gets users current location
   170  * returns 0 on success and Symbian specific error codes on failure
   178  * returns 0 on success and Symbian specific error codes on failure
   171  */
   179  */
   172 
   180 
   173 EXPORT_C void  CLocationService :: GetLocationL( TPositionInfoBase* aInfoBase ,
   181 EXPORT_C void  CLocationService :: GetLocationL( TPositionInfoBase* aInfoBase ,
   174         const TPositionUpdateOptions* aUpdateOpts,TBool aEnableHighAcc )
   182                                                  const TPositionUpdateOptions* aUpdateOpts,
   175     {
   183                                                  TBool aEnableHighAcc )
       
   184     {
       
   185     //Check if atleast one of the module is enabled
       
   186     TInt modError = iPosServer.GetDefaultModuleId(iModuleId);
       
   187     if (modError)
       
   188         {
       
   189         User::Leave(errServiceNotReady);
       
   190         }
   176     // Open subsession to the position server
   191     // Open subsession to the position server
   177     TPositionModuleId ModuleId;
   192     TPositionModuleId ModuleId;
   178     TInt error;
   193     //TInt error;
   179     if(aEnableHighAcc)
   194     if(aEnableHighAcc)
   180         {
   195         {
   181         GetHighAccuracyModuleL(&ModuleId);
   196         GetHighAccuracyModuleL(&ModuleId);
   182        
   197        
   183         User::LeaveIfError(iPositioner.Open(iPosServer,ModuleId));
   198         User::LeaveIfError(iPositioner.Open(iPosServer,ModuleId));
   184         
   199         
       
   200         iModuleId = ModuleId;
   185         }
   201         }
   186     else
   202     else
   187         {
   203         {
   188         User::LeaveIfError(iPositioner.Open(iPosServer));
   204         User::LeaveIfError(iPositioner.Open(iPosServer));
   189         }
   205         User::LeaveIfError(iPosServer.GetDefaultModuleId(iModuleId));
   190 
   206         }
   191     
   207 
   192     CleanupClosePushL(iPositioner);
   208     
   193 
   209     //CleanupClosePushL(iPositioner);
       
   210     TInt errorInprocessing = KErrNone;
       
   211     errorInprocessing = SetRequestingField();
       
   212     if(errorInprocessing)
       
   213         {
       
   214         iPositioner.Close();
       
   215         User::Leave(errorInprocessing);
       
   216         }
       
   217    // (static_cast<HPositionGenericInfo*>(aInfoBase))->ClearRequestedFields() ;
       
   218     (static_cast<HPositionGenericInfo*>(aInfoBase))->SetRequestedFields(iFieldList) ;
   194     //setting identity for this requestor
   219     //setting identity for this requestor
   195     User::LeaveIfError( iPositioner.SetRequestor( CRequestor::ERequestorService,
   220     User::LeaveIfError( iPositioner.SetRequestor( CRequestor::ERequestorService,
   196             CRequestor::EFormatApplication,
   221             CRequestor::EFormatApplication,
   197             KIdentity ) );
   222             KIdentity ) );
   198 
   223 
   199     TRequestStatus status;
   224     TRequestStatus status;
   200 
   225 
   201     if(aUpdateOpts)
   226     if(aUpdateOpts)
   202         {
   227         {
   203         User::LeaveIfError(iPositioner.SetUpdateOptions(*aUpdateOpts));
   228         TInt errorInprocessing = iPositioner.SetUpdateOptions(*aUpdateOpts);
       
   229         
       
   230         if(errorInprocessing)
       
   231            {
       
   232            iPositioner.Close();
       
   233            User::Leave(errorInprocessing);
       
   234            }
       
   235         
   204         }
   236         }
   205 
   237 
   206     else
   238     else
   207         {
   239         {
   208         TPositionUpdateOptions updateopts ;
   240         TPositionUpdateOptions updateopts ;
   225         }
   257         }
   226 
   258 
   227 
   259 
   228     iPositioner.NotifyPositionUpdate( *aInfoBase, status );
   260     iPositioner.NotifyPositionUpdate( *aInfoBase, status );
   229     User :: WaitForRequest(status) ;
   261     User :: WaitForRequest(status) ;
   230     CleanupStack::PopAndDestroy(&iPositioner);
   262     //CleanupStack::PopAndDestroy(&iPositioner);
       
   263     iPositioner.Close();
   231     
   264     
   232     User::LeaveIfError(status.Int());
   265     User::LeaveIfError(status.Int());
   233     }
   266     }
   234 
   267 
   235 /**
   268 /**
   236  * CLocationService::ModuleInfo, gets information about the location moudleid of currently used
   269  * CLocationService::ModuleInfo, gets information about the location moudleid of currently used
   237  * positioning moulde, currently this methods only supports info of default module indentifier
   270  * positioning moulde, currently this methods only supports info of default module indentifier
   238  */
   271  */
   239 
   272 
   240  EXPORT_C TInt CLocationService :: GetModuleInfo( TPositionModuleInfoBase& aModuleInfo )   const
   273 EXPORT_C TInt CLocationService :: GetModuleInfo( 
       
   274         TPositionModuleInfoBase& aModuleInfo ) const
   241     {
   275     {
   242     return  iPosServer.GetModuleInfoById(iModuleId , aModuleInfo) ;
   276     return  iPosServer.GetModuleInfoById(iModuleId , aModuleInfo) ;
   243 
   277 
   244     }
   278     }
   245 
   279 
   250  * This function gets users current location
   284  * This function gets users current location
   251  * returns status of job submitted 
   285  * returns status of job submitted 
   252  */
   286  */
   253 EXPORT_C void CLocationService :: GetLocationL( MLocationCallBack* aCallBackObj ,
   287 EXPORT_C void CLocationService :: GetLocationL( MLocationCallBack* aCallBackObj ,
   254         TInt aLocationInfoCategory,
   288         TInt aLocationInfoCategory,
   255         TPositionFieldIdList aFieldList ,
   289         TPositionFieldIdList/* aFieldList*/ ,
   256         const TPositionUpdateOptions* aUpateOptions,
   290         const TPositionUpdateOptions* aUpateOptions,
   257         TBool aEnableHighAcc 
   291         TBool aEnableHighAcc 
   258 )
   292 )
   259     {  
   293     {  
       
   294     TInt modError = iPosServer.GetDefaultModuleId(iModuleId);
       
   295     if (modError)
       
   296         {
       
   297         User::Leave(errServiceNotReady);
       
   298         }
   260     TPositionModuleId ModuleId;
   299     TPositionModuleId ModuleId;
   261     if(aEnableHighAcc)
   300     if(aEnableHighAcc)
   262         {
   301         {
   263         GetHighAccuracyModuleL(&ModuleId);
   302         GetHighAccuracyModuleL(&ModuleId);
       
   303         iModuleId = ModuleId;
   264         
   304         
   265         }
   305         }
   266     else
   306     else
   267         {
   307         {
   268         //Indicates that when opening the subsession ,moudleId need not be specified
   308         //Indicates that when opening the subsession ,moudleId need not be specified
   269         ModuleId.iUid = 0;       
   309         ModuleId.iUid = 0;       
       
   310         User::LeaveIfError(iPosServer.GetDefaultModuleId(iModuleId));
   270         }
   311         }
   271 
   312 
   272     TInt err = KErrGeneral;
   313     TInt err = KErrGeneral;
       
   314     User::LeaveIfError(SetSupportedFields());
   273 
   315 
   274     CGetLoc* activeGetLoc = CGetLoc :: NewL(iPosServer ,
   316     CGetLoc* activeGetLoc = CGetLoc :: NewL(iPosServer ,
   275             aFieldList ,
   317             iFieldList ,
   276             KGetLocationRequest,
   318             KGetLocationRequest,
   277             aLocationInfoCategory,
   319             aLocationInfoCategory,
   278             ModuleId) ;
   320             ModuleId) ;
   279 
   321 
   280     err = activeGetLoc->GetLocationUpdates(this,aCallBackObj,aUpateOptions);
   322     err = activeGetLoc->GetLocationUpdates(this,aCallBackObj,aUpateOptions);
   298  * Returns 0 on success and symbian specific error codes on failures
   340  * Returns 0 on success and symbian specific error codes on failures
   299  */
   341  */
   300 
   342 
   301 EXPORT_C void CLocationService :: TraceL( MLocationCallBack* aCallBackObj ,
   343 EXPORT_C void CLocationService :: TraceL( MLocationCallBack* aCallBackObj ,
   302         TInt aLocationInfoCategory,
   344         TInt aLocationInfoCategory,
   303         TPositionFieldIdList aFiledList ,
   345         TPositionFieldIdList/* aFiledList*/ ,
   304         const TPositionUpdateOptions* aUpateOptions,
   346         const TPositionUpdateOptions* aUpateOptions,
   305         TBool aEnableHighAcc )
   347         TBool aEnableHighAcc )
   306     {
   348     {
       
   349     TInt modError = iPosServer.GetDefaultModuleId(iModuleId);
       
   350     if (modError)
       
   351         {
       
   352         User::Leave(errServiceNotReady);
       
   353         }
   307     TPositionModuleId ModuleId;
   354     TPositionModuleId ModuleId;
   308     if(aEnableHighAcc)
   355     if(aEnableHighAcc)
   309         {
   356         {
   310         GetHighAccuracyModuleL(&ModuleId);
   357         GetHighAccuracyModuleL(&ModuleId);
   311         if(ModuleId.iUid == NULL)
   358         if(ModuleId.iUid == NULL)
   312             {
   359             {
   313             User::Leave(KErrGeneral);
   360             User::Leave(KErrGeneral);
   314             }
   361             }
       
   362         iModuleId = ModuleId;
   315         }
   363         }
   316     else
   364     else
   317         {
   365         {
   318         //Indicates that when opening the subsession ,moudleId need not be specified
   366         //Indicates that when opening the subsession ,moudleId need not be specified
   319         ModuleId.iUid = 0;          
   367         ModuleId.iUid = 0;          
       
   368         User::LeaveIfError(iPosServer.GetDefaultModuleId(iModuleId));
   320         }
   369         }
   321     
   370     
   322     CGetLoc* activeTrace = CGetLoc :: NewL(iPosServer ,
   371     CGetLoc* activeTrace = CGetLoc :: NewL(iPosServer ,
   323             aFiledList ,
   372             iFieldList ,
   324             KTraceRequest,
   373             KTraceRequest,
   325             aLocationInfoCategory,
   374             aLocationInfoCategory,
   326             ModuleId) ;
   375             ModuleId) ;
   327 
   376 
   328     TInt ret = activeTrace->GetLocationUpdates(this,aCallBackObj , aUpateOptions);
   377     TInt ret = activeTrace->GetLocationUpdates(this,aCallBackObj , aUpateOptions);
   499             }
   548             }
   500         }
   549         }
   501 
   550 
   502     return KErrNotFound;
   551     return KErrNotFound;
   503     }
   552     }
       
   553 TInt CLocationService :: SetSupportedFields()
       
   554     {
       
   555     
       
   556     TUint fieldIter = 0 ;
       
   557     //get positioning module information
       
   558     TInt infoerr = GetModuleInfo(iModuleInfo);
       
   559     if (infoerr)
       
   560         {
       
   561         return infoerr;
       
   562         }
       
   563 
       
   564     TPositionModuleInfo :: TCapabilities  currCapability  = iModuleInfo.Capabilities() ;
       
   565 
       
   566     if(currCapability & TPositionModuleInfo :: ECapabilitySpeed) //set horizontal,vertical speeds along with errros 
       
   567         {   
       
   568         iFieldList[fieldIter++] = EPositionFieldHorizontalSpeed ;
       
   569         
       
   570         iFieldList[fieldIter++] = EPositionFieldHorizontalSpeedError ;
       
   571         iFieldList[fieldIter++] = EPositionFieldVerticalSpeed ;
       
   572         iFieldList[fieldIter++] = EPositionFieldVerticalSpeedError ;
       
   573         }
       
   574 
       
   575     if(currCapability & TPositionModuleInfo :: ECapabilitySatellite) //Set satellite info fields if positioning module supports
       
   576         {                                                               //
       
   577         
       
   578         iFieldList[fieldIter++] = EPositionFieldSatelliteNumInView ;
       
   579         iFieldList[fieldIter++] = EPositionFieldSatelliteNumUsed ;
       
   580         iFieldList[fieldIter++] = EPositionFieldSatelliteTime ;
       
   581         iFieldList[fieldIter++] = EPositionFieldSatelliteHorizontalDoP ;
       
   582         iFieldList[fieldIter++] = EPositionFieldSatelliteVerticalDoP ;
       
   583         
       
   584         }
       
   585 
       
   586     if(currCapability & TPositionModuleInfo :: ECapabilityDirection) //Set Direction info fields if positioning module supports
       
   587         {
       
   588         
       
   589         iFieldList[fieldIter++] = EPositionFieldTrueCourse ;
       
   590         iFieldList[fieldIter++] = EPositionFieldTrueCourseError ;
       
   591         iFieldList[fieldIter++] = EPositionFieldMagneticCourse ;
       
   592         iFieldList[fieldIter++] = EPositionFieldMagneticCourseError ;
       
   593         
       
   594         }
       
   595     
       
   596 
       
   597     if(currCapability & TPositionModuleInfo :: ECapabilityCompass) //Set NMEA fields if positioning module supports 
       
   598         {
       
   599             
       
   600         iFieldList[fieldIter++] = EPositionFieldHeading ;
       
   601         iFieldList[fieldIter++] = EPositionFieldHeadingError ;
       
   602         iFieldList[fieldIter++] = EPositionFieldMagneticHeading ;
       
   603         iFieldList[fieldIter++] = EPositionFieldMagneticHeadingError ;
       
   604         
       
   605         }
       
   606     
       
   607     
       
   608    iFieldList[fieldIter] = EPositionFieldNone  ;   //Field Termination 
       
   609    iGenericPosInfo->ClearRequestedFields() ;
       
   610    iGenericPosInfo->SetRequestedFields(iFieldList) ;
       
   611   
       
   612   
       
   613    return KErrNone ;
       
   614    }
       
   615 TInt CLocationService :: SetRequestingField()
       
   616     {
       
   617     
       
   618     TUint fieldIter = 0 ;
       
   619     //get positioning module information
       
   620     TInt infoerr = GetModuleInfo(iModuleInfo);
       
   621     if (infoerr)
       
   622         {
       
   623         return infoerr;
       
   624         }
       
   625 
       
   626     TPositionModuleInfo :: TCapabilities  currCapability  = iModuleInfo.Capabilities() ;
       
   627 
       
   628     if(currCapability & TPositionModuleInfo :: ECapabilitySpeed) //set horizontal,vertical speeds along with errros 
       
   629         {   
       
   630         iFieldList[fieldIter++] = EPositionFieldHorizontalSpeed ;
       
   631         
       
   632         iFieldList[fieldIter++] = EPositionFieldHorizontalSpeedError ;
       
   633         iFieldList[fieldIter++] = EPositionFieldVerticalSpeed ;
       
   634         iFieldList[fieldIter++] = EPositionFieldVerticalSpeedError ;
       
   635         }
       
   636 
       
   637     if(currCapability & TPositionModuleInfo :: ECapabilitySatellite) //Set satellite info fields if positioning module supports
       
   638         {                                                               //
       
   639         
       
   640         iFieldList[fieldIter++] = EPositionFieldSatelliteNumInView ;
       
   641         iFieldList[fieldIter++] = EPositionFieldSatelliteNumUsed ;
       
   642         iFieldList[fieldIter++] = EPositionFieldSatelliteTime ;
       
   643         iFieldList[fieldIter++] = EPositionFieldSatelliteHorizontalDoP ;
       
   644         iFieldList[fieldIter++] = EPositionFieldSatelliteVerticalDoP ;
       
   645         
       
   646         }
       
   647 
       
   648     if(currCapability & TPositionModuleInfo :: ECapabilityDirection) //Set Direction info fields if positioning module supports
       
   649         {
       
   650         
       
   651         iFieldList[fieldIter++] = EPositionFieldTrueCourse ;
       
   652         iFieldList[fieldIter++] = EPositionFieldTrueCourseError ;
       
   653         iFieldList[fieldIter++] = EPositionFieldMagneticCourse ;
       
   654         iFieldList[fieldIter++] = EPositionFieldMagneticCourseError ;
       
   655         
       
   656         }
       
   657     
       
   658 
       
   659     if(currCapability & TPositionModuleInfo :: ECapabilityCompass) //Set NMEA fields if positioning module supports 
       
   660         {
       
   661             
       
   662         iFieldList[fieldIter++] = EPositionFieldHeading ;
       
   663         iFieldList[fieldIter++] = EPositionFieldHeadingError ;
       
   664         iFieldList[fieldIter++] = EPositionFieldMagneticHeading ;
       
   665         iFieldList[fieldIter++] = EPositionFieldMagneticHeadingError ;
       
   666         
       
   667         }
       
   668     
       
   669     
       
   670    iFieldList[fieldIter] = EPositionFieldNone  ;   //Field Termination 
       
   671    
       
   672   
       
   673   
       
   674    return KErrNone ;
       
   675    }
       
   676