qtmobility/src/location/qgeopositioninfosource_s60.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the Qt Mobility Components.
     7 ** This file is part of the Qt Mobility Components.
     8 **
     8 **
   122             return;
   122             return;
   123         }
   123         }
   124 
   124 
   125         //update the list array with the available method initially
   125         //update the list array with the available method initially
   126         updateDeviceStatus();
   126         updateDeviceStatus();
       
   127         
       
   128         // Set the PreferredPositioningMethods based on Supported methods
       
   129         QGeoPositionInfoSource::setPreferredPositioningMethods( mSupportedMethods );
   127 
   130 
   128         //devStatusUpdateAO->NotifyDeviceStatus(mStatusEvent);
   131         //devStatusUpdateAO->NotifyDeviceStatus(mStatusEvent);
   129 
   132 
   130         CleanupStack::PushL(mDevStatusUpdateAO);
   133         CleanupStack::PushL(mDevStatusUpdateAO);
   131 
   134 
   140 QGeoPositionInfo CQGeoPositionInfoSourceS60::lastKnownPosition(bool aFromSatellitePositioningMethodsOnly) const
   143 QGeoPositionInfo CQGeoPositionInfoSourceS60::lastKnownPosition(bool aFromSatellitePositioningMethodsOnly) const
   141 {
   144 {
   142 
   145 
   143     QGeoPositionInfo posUpdate;
   146     QGeoPositionInfo posUpdate;
   144     TPosition pos;
   147     TPosition pos;
   145     PositioningMethod type;
       
   146     TInt error = KErrNone;
   148     TInt error = KErrNone;
   147     RPositioner iLastKnownpositioner;
   149     RPositioner iLastKnownpositioner;
   148     TRequestStatus status;
   150     TRequestStatus status;
   149 
   151 
   150     error = iLastKnownpositioner.Open(*const_cast<RPositionServer*>(&mPositionServer));
   152     error = iLastKnownpositioner.Open(*const_cast<RPositionServer*>(&mPositionServer));
   164         error = status.Int();
   166         error = status.Int();
   165 
   167 
   166         iLastKnownpositioner.Close();
   168         iLastKnownpositioner.Close();
   167 
   169 
   168         if ((error == KErrNone) || (error == KPositionPartialUpdate)) {
   170         if ((error == KErrNone) || (error == KPositionPartialUpdate)) {
   169 
   171         
   170             bool typeSet = false;
   172             TPositionModuleInfo modInfo;
   171             for (int i = 0;i < mListSize ;i++) {
   173             mPositionServer.GetModuleInfoById(posInfo.ModuleId(), modInfo);
   172                 if (mList[i].mUid == posInfo.ModuleId()) {
   174             
   173                     type = mList[i].mPosMethod;
   175             if(!aFromSatellitePositioningMethodsOnly || (aFromSatellitePositioningMethodsOnly && (modInfo.Capabilities() & TPositionModuleInfo::ECapabilitySatellite))){
   174                     typeSet = true;
       
   175                     break;
       
   176                 }
       
   177             }
       
   178 
       
   179             if (!((aFromSatellitePositioningMethodsOnly == TRUE) && typeSet &&
       
   180                     (type != SatellitePositioningMethods))) {
       
   181                 QGeoCoordinate  coord;
   176                 QGeoCoordinate  coord;
   182 
   177 
   183                 posInfo.GetPosition(pos);
   178                 posInfo.GetPosition(pos);
   184 
   179 
   185                 coord.setLatitude(pos.Latitude());
   180                 coord.setLatitude(pos.Latitude());
   383     //time taken for the subsequent fix
   378     //time taken for the subsequent fix
   384     time_to_next_fix = quality.TimeToNextFix();
   379     time_to_next_fix = quality.TimeToNextFix();
   385 
   380 
   386 
   381 
   387     if ((i = checkModule(id)) == -1) {
   382     if ((i = checkModule(id)) == -1) {
       
   383         //update the properties of the module
       
   384 
       
   385         //TPositionModuleId of the module
       
   386         mList[mListSize].mUid = id;
       
   387 
       
   388         //positioning method method type
       
   389         mList[mListSize].mPosMethod = method;
       
   390 
       
   391         //status of the device
       
   392         mList[mListSize].mStatus = aStatus;
       
   393 
       
   394         //availablility of the module
       
   395         mList[mListSize].mIsAvailable = available;
       
   396 
       
   397         //horizontal accuracy of the module
       
   398         mList[mListSize].mHorizontalAccuracy = accuracy;
       
   399 
       
   400         //time required to get the first fix
       
   401         mList[mListSize].mTimeToFirstFix = time_to_first_fix;
       
   402 
       
   403         //time required for subsequent fix
       
   404         mList[mListSize].mTimeToNextFix = time_to_next_fix;
       
   405 
       
   406         //count on the mList array size
       
   407         mListSize++;
       
   408         
       
   409         //update the supported source types based on the device status
       
   410         updateAvailableTypes();
       
   411         
   388         //store the correct method in use from the mCurrentModuleId retireved earlier
   412         //store the correct method in use from the mCurrentModuleId retireved earlier
   389         if (id == mCurrentModuleId) {
   413         if (id == mCurrentModuleId) {
   390             mCurrentMethod = method;
   414             mCurrentMethod = method;
   391             QGeoPositionInfoSource::setPreferredPositioningMethods(mCurrentMethod);
   415         }
   392         }
       
   393         //update the properties of the module
       
   394 
       
   395         //TPositionModuleId of the module
       
   396         mList[mListSize].mUid = id;
       
   397 
       
   398         //positioning method method type
       
   399         mList[mListSize].mPosMethod = method;
       
   400 
       
   401         //status of the device
       
   402         mList[mListSize].mStatus = aStatus;
       
   403 
       
   404         //availablility of the module
       
   405         mList[mListSize].mIsAvailable = available;
       
   406 
       
   407         //horizontal accuracy of the module
       
   408         mList[mListSize].mHorizontalAccuracy = accuracy;
       
   409 
       
   410         //time required to get the first fix
       
   411         mList[mListSize].mTimeToFirstFix = time_to_first_fix;
       
   412 
       
   413         //time required for subsequent fix
       
   414         mList[mListSize].mTimeToNextFix = time_to_next_fix;
       
   415 
       
   416         //count on the mList array size
       
   417         mListSize++;
       
   418     } else {
   416     } else {
   419         //module's status has changed
   417         //module's status has changed
   420         if (mList[i].mStatus != aStatus)
   418         if (mList[i].mStatus != aStatus)
   421             mList[i].mStatus = aStatus;
   419             mList[i].mStatus = aStatus;
   422 
   420 
   433             mList[i].mTimeToFirstFix = time_to_first_fix;
   431             mList[i].mTimeToFirstFix = time_to_first_fix;
   434 
   432 
   435         //module's time to subsequent fix has changed
   433         //module's time to subsequent fix has changed
   436         if (mList[i].mTimeToNextFix != time_to_next_fix)
   434         if (mList[i].mTimeToNextFix != time_to_next_fix)
   437             mList[i].mTimeToFirstFix = time_to_next_fix;
   435             mList[i].mTimeToFirstFix = time_to_next_fix;
       
   436         
       
   437         //update the supported source types based on the device status
       
   438         updateAvailableTypes();
   438 
   439 
   439         //if the mCurrentModuleId is NULL, try updating the reg update with the available
   440         //if the mCurrentModuleId is NULL, try updating the reg update with the available
   440         //positioning method
   441         //positioning method
   441         if (mCurrentModuleId == TUid::Null() && (available == TRUE) &&
   442         if (mCurrentModuleId == TUid::Null() && (available == TRUE) &&
   442                 (aStatus != TPositionModuleStatus::EDeviceUnknown) &&
   443                 (aStatus != TPositionModuleStatus::EDeviceUnknown) &&
   462 
   463 
   463                 mCurrentModuleId = mList[i].mUid;
   464                 mCurrentModuleId = mList[i].mUid;
   464 
   465 
   465                 mCurrentMethod = mList[i].mPosMethod;
   466                 mCurrentMethod = mList[i].mPosMethod;
   466 
   467 
   467                 QGeoPositionInfoSource::setPreferredPositioningMethods(mCurrentMethod);
       
   468             }
   468             }
   469         }
   469         }
   470 
   470 
   471         //check if the status of the currently used modules for regular update or
   471         //check if the status of the currently used modules for regular update or
   472         //request update has changed
   472         //request update has changed
   510                     //method
   510                     //method
   511                     mRegUpdateAO = temp;
   511                     mRegUpdateAO = temp;
   512 
   512 
   513                     mCurrentModuleId = mList[index].mUid;
   513                     mCurrentModuleId = mList[index].mUid;
   514                     mCurrentMethod = mList[index].mPosMethod;
   514                     mCurrentMethod = mList[index].mPosMethod;
   515                     QGeoPositionInfoSource::setPreferredPositioningMethods(mCurrentMethod);
       
   516 
   515 
   517                     mRegUpdateAO->setUpdateInterval(interval);
   516                     mRegUpdateAO->setUpdateInterval(interval);
   518 
   517 
   519                     //to be uncommented when startUpdates are done
   518                     //to be uncommented when startUpdates are done
   520 
   519 
   524                 } else {
   523                 } else {
   525                     //no methods available,clean up the resources
   524                     //no methods available,clean up the resources
   526                     mRegUpdateAO = NULL;
   525                     mRegUpdateAO = NULL;
   527                     mCurrentModuleId = TUid::Null();
   526                     mCurrentModuleId = TUid::Null();
   528                     mCurrentMethod = PositioningMethod(0);
   527                     mCurrentMethod = PositioningMethod(0);
   529                     QGeoPositionInfoSource::setPreferredPositioningMethods(mCurrentMethod);
   528                     
   530                     emit updateTimeout();
   529                     emit updateTimeout();
   531                 }
   530                 }
   532 
   531 
   533             }
   532             }
   534 
   533 
   543 
   542 
   544         }
   543         }
   545 
   544 
   546     }   //end else
   545     }   //end else
   547 
   546 
   548     //update the supported source types based on the device status
       
   549     updateAvailableTypes();
       
   550 }
   547 }
   551 
   548 
   552 
   549 
   553 // Notification methods from active object. Notifies device status changes
   550 // Notification methods from active object. Notifies device status changes
   554 void CQGeoPositionInfoSourceS60::updateDeviceStatus(void)
   551 void CQGeoPositionInfoSourceS60::updateDeviceStatus(void)
   581             updateStatus(moduleInfo, moduleStatus.DeviceStatus());
   578             updateStatus(moduleInfo, moduleStatus.DeviceStatus());
   582 
   579 
   583             mModuleFlags |= (1 << i);
   580             mModuleFlags |= (1 << i);
   584         }
   581         }
   585     } else {
   582     } else {
   586         //UpdateDeviceStatus() called afetr registering for NotifyModuleStatusEvent
   583         //UpdateDeviceStatus() called after registering for NotifyModuleStatusEvent
   587 
   584 
   588         //get the module id from the status event
   585         //get the module id from the status event
   589         TPositionModuleId id = mStatusEvent.ModuleId();
   586         TPositionModuleId id = mStatusEvent.ModuleId();
   590 
   587 
   591         //get module information
   588         //get module information
   790     mRegUpdateAO->cancelUpdate();
   787     mRegUpdateAO->cancelUpdate();
   791 }
   788 }
   792 
   789 
   793 void CQGeoPositionInfoSourceS60::setPreferredPositioningMethods(PositioningMethods aMethods)
   790 void CQGeoPositionInfoSourceS60::setPreferredPositioningMethods(PositioningMethods aMethods)
   794 {
   791 {
       
   792     QGeoPositionInfoSource::setPreferredPositioningMethods(aMethods);
       
   793     
   795     PositioningMethods preferredMethod(PositioningMethods(0));
   794     PositioningMethods preferredMethod(PositioningMethods(0));
   796     TInt index = -1;
   795     TInt index = -1;
   797     // the poistioning methods are not supported
   796     // the poistioning methods are not supported
   798     // if the preferred positioning method is the current poistioning
   797     // if the preferred positioning method is the current poistioning
   799 
   798 
   849             //possibility of the minimumupdateinterval being changed
   848             //possibility of the minimumupdateinterval being changed
   850             if (value != updateInterval)
   849             if (value != updateInterval)
   851                 QGeoPositionInfoSource::setUpdateInterval(value);
   850                 QGeoPositionInfoSource::setUpdateInterval(value);
   852 
   851 
   853         }
   852         }
   854         QGeoPositionInfoSource::setPreferredPositioningMethods(mCurrentMethod);
       
   855     }
   853     }
   856 
   854 
   857 }
   855 }
   858 
   856 
   859 void CQGeoPositionInfoSourceS60::setUpdateInterval(int aMilliSec)
   857 void CQGeoPositionInfoSourceS60::setUpdateInterval(int aMilliSec)