qtmobility/src/location/qgeopositioninfosource_s60.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
   165 
   165 
   166         iLastKnownpositioner.Close();
   166         iLastKnownpositioner.Close();
   167 
   167 
   168         if ((error == KErrNone) || (error == KPositionPartialUpdate)) {
   168         if ((error == KErrNone) || (error == KPositionPartialUpdate)) {
   169 
   169 
       
   170             bool typeSet = false;
   170             for (int i = 0;i < mListSize ;i++) {
   171             for (int i = 0;i < mListSize ;i++) {
   171                 if (mList[i].mUid == posInfo.ModuleId()) {
   172                 if (mList[i].mUid == posInfo.ModuleId()) {
   172                     type = mList[i].mPosMethod;
   173                     type = mList[i].mPosMethod;
       
   174                     typeSet = true;
       
   175                     break;
   173                 }
   176                 }
   174             }
   177             }
   175 
   178 
   176             if (!((aFromSatellitePositioningMethodsOnly == TRUE) &&
   179             if (!((aFromSatellitePositioningMethodsOnly == TRUE) && typeSet &&
   177                     (type != SatellitePositioningMethods))) {
   180                     (type != SatellitePositioningMethods))) {
   178                 QGeoCoordinate  coord;
   181                 QGeoCoordinate  coord;
   179 
   182 
   180                 posInfo.GetPosition(pos);
   183                 posInfo.GetPosition(pos);
   181 
       
   182 
   184 
   183                 coord.setLatitude(pos.Latitude());
   185                 coord.setLatitude(pos.Latitude());
   184                 coord.setLongitude(pos.Longitude());
   186                 coord.setLongitude(pos.Longitude());
   185                 coord.setAltitude(pos.Altitude());
   187                 coord.setAltitude(pos.Altitude());
   186 
   188 
   191                 QDateTime dt(QDate(datetime.Year(), datetime.Month() + 1, datetime.Day() + 1),
   193                 QDateTime dt(QDate(datetime.Year(), datetime.Month() + 1, datetime.Day() + 1),
   192                              QTime(datetime.Hour(), datetime.Minute(), datetime.Second(),
   194                              QTime(datetime.Hour(), datetime.Minute(), datetime.Second(),
   193                                    datetime.MicroSecond() / 1000));
   195                                    datetime.MicroSecond() / 1000));
   194 
   196 
   195                 //store the time stamp
   197                 //store the time stamp
   196                 posUpdate.setDateTime(dt);
   198                 posUpdate.setTimestamp(dt);
   197 
   199 
   198                 //store the horizontal accuracy
   200                 //store the horizontal accuracy
   199                 posUpdate.setAttribute(QGeoPositionInfo::HorizontalAccuracy, pos.HorizontalAccuracy());
   201                 posUpdate.setAttribute(QGeoPositionInfo::HorizontalAccuracy, pos.HorizontalAccuracy());
   200 
   202 
   201                 //store the vertical accuracy
   203                 //store the vertical accuracy
   295 
   297 
   296 //private function : to get the index of the positioning method with time to first fix
   298 //private function : to get the index of the positioning method with time to first fix
   297 //lesser than timeout
   299 //lesser than timeout
   298 TInt CQGeoPositionInfoSourceS60::getMoreAccurateMethod(TInt aTimeout, TUint8 aBits)
   300 TInt CQGeoPositionInfoSourceS60::getMoreAccurateMethod(TInt aTimeout, TUint8 aBits)
   299 {
   301 {
   300     TInt index = -1, temp = INT_MAX;
   302     TInt index = -1;
       
   303     double temp = -1.0;
   301     PositioningMethods posMethods;
   304     PositioningMethods posMethods;
   302     TTimeIntervalMicroSeconds microSeconds;
   305     TTimeIntervalMicroSeconds microSeconds;
   303 
   306 
   304     posMethods = preferredPositioningMethods();
   307     posMethods = preferredPositioningMethods();
   305 
   308 
   311                 //&& posMethods.testFlag(mList[i].mPosMethod)
   314                 //&& posMethods.testFlag(mList[i].mPosMethod)
   312                 && (mList[i].mStatus != TPositionModuleStatus::EDeviceUnknown)
   315                 && (mList[i].mStatus != TPositionModuleStatus::EDeviceUnknown)
   313                 && (mList[i].mStatus != TPositionModuleStatus::EDeviceError)
   316                 && (mList[i].mStatus != TPositionModuleStatus::EDeviceError)
   314                 && (((aBits >> i) & 1))
   317                 && (((aBits >> i) & 1))
   315                 && (mList[i].mTimeToFirstFix < microSeconds)) {
   318                 && (mList[i].mTimeToFirstFix < microSeconds)) {
   316             if (mList[i].mHorizontalAccuracy < temp) {
   319             if ((temp == -1.0) || (mList[i].mHorizontalAccuracy < temp)) {
   317                 index = i;
   320                 index = i;
   318                 temp = mList[i].mHorizontalAccuracy;
   321                 temp = mList[i].mHorizontalAccuracy;
   319             }
   322             }
   320         }
   323         }
   321     }
   324     }
   424                                                   mList[i].mUid));
   427                                                   mList[i].mUid));
   425 
   428 
   426             if ((ret == KErrNone) && (temp != NULL)) {
   429             if ((ret == KErrNone) && (temp != NULL)) {
   427                 temp->setUpdateInterval(interval);
   430                 temp->setUpdateInterval(interval);
   428 
   431 
       
   432                 if (mRegUpdateAO)
       
   433                     delete mRegUpdateAO;
   429                 mRegUpdateAO = temp;
   434                 mRegUpdateAO = temp;
   430 
   435 
   431                 //to be uncommented when startUpdates are done
   436                 //to be uncommented when startUpdates are done
   432 
   437 
   433                 if (mStartUpdates)
   438                 if (mStartUpdates)
   434                     mRegUpdateAO->startUpdates();
   439                     mRegUpdateAO->startUpdates();
   435 
       
   436 
   440 
   437                 mCurrentModuleId = mList[i].mUid;
   441                 mCurrentModuleId = mList[i].mUid;
   438 
   442 
   439                 mCurrentMethod = mList[i].mPosMethod;
   443                 mCurrentMethod = mList[i].mPosMethod;
   440 
   444 
   454 
   458 
   455                 TUint8 bits;
   459                 TUint8 bits;
   456 
   460 
   457                 interval = QGeoPositionInfoSource::updateInterval();
   461                 interval = QGeoPositionInfoSource::updateInterval();
   458 
   462 
   459                 delete  mRegUpdateAO;
   463                 if (mRegUpdateAO)
   460 
   464                     delete  mRegUpdateAO;
   461 
   465 
   462                 bits = mModuleFlags;
   466                 bits = mModuleFlags;
   463 
   467 
   464                 do {
   468                 do {
   465                     //error = Get the index of the positioning module based on
   469                     //error = Get the index of the positioning module based on
   506 
   510 
   507             }
   511             }
   508 
   512 
   509             //check if device status of the request update module changed
   513             //check if device status of the request update module changed
   510             if (id == mReqModuleId) {
   514             if (id == mReqModuleId) {
   511                 delete mReqUpdateAO;
   515                 if (mRegUpdateAO)
       
   516                     delete mReqUpdateAO;
   512                 mReqUpdateAO = NULL;
   517                 mReqUpdateAO = NULL;
   513                 mReqModuleId = TUid::Null();
   518                 mReqModuleId = TUid::Null();
   514                 emit updateTimeout();
   519                 emit updateTimeout();
   515             }
   520             }
   516 
   521 
   541         error = mPositionServer.GetDefaultModuleId(mCurrentModuleId);
   546         error = mPositionServer.GetDefaultModuleId(mCurrentModuleId);
   542 
   547 
   543         if (error != KErrNone)
   548         if (error != KErrNone)
   544             mCurrentModuleId = TUid::Null();
   549             mCurrentModuleId = TUid::Null();
   545 
   550 
   546         for (TInt i = 0; i < modCount; i++) {
   551         for (TUint i = 0; i < modCount; i++) {
   547             //get module information
   552             //get module information
   548             mPositionServer.GetModuleInfoByIndex(i, moduleInfo);
   553             mPositionServer.GetModuleInfoByIndex(i, moduleInfo);
   549 
   554 
   550             //get module status
   555             //get module status
   551             mPositionServer.GetModuleStatus(moduleStatus, moduleInfo.ModuleId());
   556             mPositionServer.GetModuleStatus(moduleStatus, moduleInfo.ModuleId());
   600     QDateTime dt(QDate(datetime.Year() , datetime.Month() + 1, datetime.Day() + 1),
   605     QDateTime dt(QDate(datetime.Year() , datetime.Month() + 1, datetime.Day() + 1),
   601                  QTime(datetime.Hour() , datetime.Minute(), datetime.Second(),
   606                  QTime(datetime.Hour() , datetime.Minute(), datetime.Second(),
   602                        datetime.MicroSecond() / 1000));
   607                        datetime.MicroSecond() / 1000));
   603 
   608 
   604     //store the time stamp
   609     //store the time stamp
   605     aPosInfo2.setDateTime(dt);
   610     aPosInfo2.setTimestamp(dt);
   606 
   611 
   607     //store the horizontal accuracy
   612     //store the horizontal accuracy
   608     aPosInfo2.setAttribute(QGeoPositionInfo::HorizontalAccuracy, pos.HorizontalAccuracy());
   613     aPosInfo2.setAttribute(QGeoPositionInfo::HorizontalAccuracy, pos.HorizontalAccuracy());
   609 
   614 
   610     //store the vertical accuracy
   615     //store the vertical accuracy
   681 void CQGeoPositionInfoSourceS60::requestUpdate(int aTimeout)
   686 void CQGeoPositionInfoSourceS60::requestUpdate(int aTimeout)
   682 {
   687 {
   683     TInt index = -1;
   688     TInt index = -1;
   684     TUint8 bits;
   689     TUint8 bits;
   685 
   690 
   686     CQMLBackendAO *temp;
   691     CQMLBackendAO *temp= NULL;
   687 
   692 
   688     //return if already a request update is pending
   693     //return if already a request update is pending
   689     if (mReqUpdateAO && mReqUpdateAO->isRequestPending())
   694     if (mReqUpdateAO && mReqUpdateAO->isRequestPending())
   690         return;
   695         return;
   691 
   696 
       
   697     if (aTimeout == 0)
       
   698         aTimeout = 20000;
   692 
   699 
   693     bits = mModuleFlags;
   700     bits = mModuleFlags;
   694 
   701 
   695     do  {
   702     do  {
   696 
   703 
   710 
   717 
   711         TRAPD(ret, temp = CQMLBackendAO::NewL(this, OnceUpdate, mList[index].mUid));
   718         TRAPD(ret, temp = CQMLBackendAO::NewL(this, OnceUpdate, mList[index].mUid));
   712 
   719 
   713         if ((ret == KErrNone) && (temp != NULL)) {
   720         if ((ret == KErrNone) && (temp != NULL)) {
   714             //delete the old reqest update
   721             //delete the old reqest update
   715             delete mReqUpdateAO;
   722             if (mReqUpdateAO)
       
   723                 delete mReqUpdateAO;
   716 
   724 
   717             //set the requestAO to the newly created AO
   725             //set the requestAO to the newly created AO
   718             mReqUpdateAO = temp;
   726             mReqUpdateAO = temp;
   719 
   727 
   720             //set the request module ID
   728             //set the request module ID
   731     } while (index >= 0);
   739     } while (index >= 0);
   732 
   740 
   733     //cleanup resources if the invalid requpdate is still stored
   741     //cleanup resources if the invalid requpdate is still stored
   734     if (mReqUpdateAO) {
   742     if (mReqUpdateAO) {
   735         delete mReqUpdateAO;
   743         delete mReqUpdateAO;
       
   744         mReqUpdateAO = NULL;
   736         mReqModuleId = TUid::Null();
   745         mReqModuleId = TUid::Null();
   737     }
   746     }
   738 
   747 
   739 }
   748 }
   740 
   749 
   759     PositioningMethods preferredMethod(PositioningMethods(0));
   768     PositioningMethods preferredMethod(PositioningMethods(0));
   760     TInt index = -1;
   769     TInt index = -1;
   761     // the poistioning methods are not supported
   770     // the poistioning methods are not supported
   762     // if the preferred positioning method is the current poistioning
   771     // if the preferred positioning method is the current poistioning
   763 
   772 
   764     if (!(mSupportedMethods & aMethods) || (aMethods == AllPositioningMethods) ||
   773     if (!(mSupportedMethods & aMethods) || (aMethods == PositioningMethods(AllPositioningMethods)) ||
   765             (aMethods == mCurrentMethod))
   774             (aMethods == PositioningMethods(mCurrentMethod)))
   766 
   775 
   767         return;
   776         return;
   768 
   777 
   769     //TPositionModuleId moduleId = getPreferredPoistionModuleId(methods);
   778     //TPositionModuleId moduleId = getPreferredPoistionModuleId(methods);
   770 
   779 
   784 
   793 
   785         if (index >= 0) {
   794         if (index >= 0) {
   786 
   795 
   787             TRAPD(error, temp = CQMLBackendAO::NewL(this, RegularUpdate,
   796             TRAPD(error, temp = CQMLBackendAO::NewL(this, RegularUpdate,
   788                                                     mList[index].mUid));
   797                                                     mList[index].mUid));
   789             if (temp != NULL)
   798             if ((temp != NULL) && (error == KErrNone))
   790                 break;
   799                 break;
   791 
   800 
   792             bits = bits & (0XFF ^(1 << index));
   801             bits = bits & (0XFF ^(1 << index));
   793         }
   802         }
   794     } while (index >= 0);
   803     } while (index >= 0);