diff -r aa5a574040a4 -r a3cc46f37772 locationmanager/geotagger/src/cinternalgeotagger.cpp --- a/locationmanager/geotagger/src/cinternalgeotagger.cpp Tue Jul 06 14:44:37 2010 +0300 +++ b/locationmanager/geotagger/src/cinternalgeotagger.cpp Fri Sep 17 16:54:49 2010 +0300 @@ -24,12 +24,12 @@ #include "mdeconstants.h" #include "mdesession.h" #include "cinternalgeotagger.h" -#include "reversegeocoderplugin.h" using namespace MdeConstants; _LIT ( KCountry, "country:"); // country:india -const TUid KReverseGeoCodeUid = {0x2002DD12}; + +const TReal64 KZeroLatLon (0.000000 ); // -------------------------------------------------------------------------- // CInternalGeoTagger::NewL @@ -59,13 +59,15 @@ iIndex(0), iSessionReady( EFalse ), iObserver( aObserver ), - iTagCreator(NULL), iASW(NULL), - iTagPendingHandlerFlag(EFalse), - iRevGeocoderPlugin(NULL) -#ifdef LOC_GEOTAGGING_CELLID + iTagPendingHandlerFlag(EFalse) +#ifdef LOC_GEOTAGGING_CELLID ,iGeoConverter(NULL) #endif +#ifdef LOC_REVERSEGEOCODE + ,iTagCreator(NULL) + ,iRevGeocoderPlugin(NULL) +#endif { iMdeSessionOwnFlag = (iMdeSession == NULL); } @@ -82,10 +84,12 @@ LOG("Not owning mds session"); iMdeSessionOwnFlag = EFalse; //object is not owning iMdeSession + iSessionReady = ETrue; +#ifdef LOC_REVERSEGEOCODE iTagCreator = CTagCreator::NewL(); - iSessionReady = ETrue; iTagCreator->SetSession( iMdeSession ); +#endif //LOC_REVERSEGEOCODE } else { @@ -93,7 +97,9 @@ iASW = new (ELeave) CActiveSchedulerWait(); iMdeSession = CMdESession::NewL( *this ); //for creating tags +#ifdef LOC_REVERSEGEOCODE iTagCreator = CTagCreator::NewL(); +#endif iASW->Start(); delete iASW; @@ -102,20 +108,18 @@ //for reverse geocoding (geo-tagging) - if (!iRevGeocoderPlugin) - { - - TRAP_IGNORE( - iRevGeocoderPlugin = reinterpret_cast( - REComSession::CreateImplementationL(KReverseGeoCodeUid, iDtorKey));) - - if(iRevGeocoderPlugin) - { - iRevGeocoderPlugin->AddObserverL(*this); - - } - - } +#ifdef LOC_REVERSEGEOCODE + + TInt pluginerr = KErrNone; + TRAP(pluginerr,iRevGeocoderPlugin = CReverseGeoCoderPlugin::NewL()); + + if(pluginerr == KErrNone) + { + iRevGeocoderPlugin->AddObserverL(*this); + } + + +#endif //LOC_REVERSEGEOCODE LOG("CInternalGeoTagger::ConstructL ,end"); } @@ -139,26 +143,35 @@ iRelationQuery->RemoveObserver(*this); iRelationQuery->Cancel(); delete iRelationQuery; + iRelationQuery = NULL; } if(iLocationQuery) { iLocationQuery->RemoveObserver(*this); iLocationQuery->Cancel(); delete iLocationQuery; + iLocationQuery = NULL; } if(iTagQuery) { iTagQuery->RemoveObserver(*this); iTagQuery->Cancel(); delete iTagQuery; + iTagQuery = NULL; } +#ifdef LOC_REVERSEGEOCODE + delete iTagCreator; + iTagCreator = NULL; delete iRevGeocoderPlugin; iRevGeocoderPlugin = NULL; - REComSession::DestroyedImplementation(iDtorKey); + +#endif //LOC_REVERSEGEOCODE if(iMdeSessionOwnFlag) { delete iMdeSession; + iMdeSession = NULL; delete iASW; + iASW = NULL; } LOG("CInternalGeoTagger::~CInternalGeoTagger ,end"); } @@ -189,7 +202,7 @@ void CInternalGeoTagger::HandleSessionOpened(CMdESession& /*aSession*/, TInt aError) { LOG("CInternalGeoTagger::HandleSessionOpened ,begin"); - if ( iMdeSessionOwnFlag && iASW && iASW->IsStarted() ) + if ( iASW && iASW->IsStarted() ) { iASW->AsyncStop(); } @@ -198,9 +211,11 @@ { iSessionReady = ETrue; +#ifdef LOC_REVERSEGEOCODE iTagCreator->SetSession( iMdeSession ); +#endif } - else if(iMdeSessionOwnFlag) + else { delete iMdeSession; iMdeSession = NULL; @@ -215,16 +230,15 @@ void CInternalGeoTagger::HandleSessionError(CMdESession& /*aSession*/, TInt /*aError*/) { LOG("CInternalGeoTagger::HandleSessionError ,begin"); - if ( iMdeSessionOwnFlag && iASW && iASW->IsStarted() ) + if (iASW && iASW->IsStarted() ) { iASW->AsyncStop(); } iSessionReady = EFalse; - if(iMdeSessionOwnFlag) - { - delete iMdeSession; - iMdeSession = NULL; - } + + delete iMdeSession; + iMdeSession = NULL; + LOG("CInternalGeoTagger::HandleSessionError ,end"); } @@ -355,6 +369,7 @@ if(GPSInfoExists()) { // GPS info exist go for reverse geo coding. +#ifdef LOC_REVERSEGEOCODE if(iRevGeocoderPlugin) { TRAP_IGNORE( @@ -362,6 +377,7 @@ ( iLocationData.iPosition, iConnectionOption ) ); } else +#endif //LOC_REVERSEGEOCODE { IterateNextLocation(); //Go through next location } @@ -369,7 +385,6 @@ else { if ( iLocationData.iNetworkInfo.iCellId > 0 && - iLocationData.iNetworkInfo.iLocationAreaCode > 0 && iLocationData.iNetworkInfo.iCountryCode.Length() > 0 && iLocationData.iNetworkInfo.iNetworkId.Length() > 0 ) { @@ -383,8 +398,21 @@ if(err == KErrNone && iGeoConverter != NULL) { + // there is no field to store type of network. + // but it's safe to take decission based on area code. + if(iLocationData.iNetworkInfo.iLocationAreaCode > 0) + { + LOG("Valid areacode. Treat as GSM n/w"); + iLocationData.iNetworkInfo.iAccess = CTelephony::ENetworkAccessGsm; + } + else + { + LOG("Areacode is 0. Treat as 3G n/w"); + iLocationData.iNetworkInfo.iAccess = CTelephony::ENetworkAccessUtran; + } TRAP(err, iGeoConverter->ConvertL(iLocationData.iNetworkInfo);) } + LOG1("Error - %d", err); if(err != KErrNone) { HandleConversionError(err); @@ -415,7 +443,9 @@ LOG("CInternalGeoTagger::GPSInfoExists"); TBool gpsInfoExists = EFalse; if ( !Math::IsNaN( iLocationData.iPosition.Latitude() ) && - !Math::IsNaN( iLocationData.iPosition.Longitude() )) //lat, long is there + !Math::IsNaN( iLocationData.iPosition.Longitude() ) && + KZeroLatLon != iLocationData.iPosition.Latitude() && + KZeroLatLon != iLocationData.iPosition.Longitude() ) //lat, long is there { LOG("Valid lat/lon\n"); @@ -424,6 +454,7 @@ return gpsInfoExists; } + // -------------------------------------------------------------------------- // CInternalGeoTagger::StartGeoTagging() // -------------------------------------------------------------------------- @@ -481,20 +512,43 @@ iLocationData.iPosition.SetCoordinate( latProp->Real64ValueL(), lonProp->Real64ValueL() ); } + else + { + iLocationData.iPosition.SetCoordinate( KZeroLatLon, + KZeroLatLon ); + } locationObject->Property( cellIdDef, cellProp, 0 ); locationObject->Property( lacCodeDef, lacProp, 0 ); locationObject->Property( countryCodeDef, countryProp, 0 ); locationObject->Property( networkCodeDef, networkProp, 0 ); - if ( cellProp && lacProp && countryProp && networkProp) + if ( cellProp && countryProp && networkProp) { iLocationData.iNetworkInfo.iCellId = cellProp->Uint32ValueL(); - iLocationData.iNetworkInfo.iLocationAreaCode = lacProp->Uint32ValueL(); iLocationData.iNetworkInfo.iCountryCode = countryProp->TextValueL(); iLocationData.iNetworkInfo.iNetworkId = networkProp->TextValueL(); - + } + else + { + // set to invalid values. + iLocationData.iNetworkInfo.iCellId = 0; + iLocationData.iNetworkInfo.iAccess = CTelephony::ENetworkAccessUnknown; + iLocationData.iNetworkInfo.iLocationAreaCode = 0; + iLocationData.iNetworkInfo.iAreaKnown = EFalse; + iLocationData.iNetworkInfo.iCountryCode.Zero(); + iLocationData.iNetworkInfo.iNetworkId.Zero(); } + iLocationData.iNetworkInfo.iAreaKnown = EFalse; + if(lacProp) + { + iLocationData.iNetworkInfo.iLocationAreaCode = lacProp->Uint32ValueL(); + if(iLocationData.iNetworkInfo.iLocationAreaCode > 0) + { + iLocationData.iNetworkInfo.iAreaKnown = ETrue; + } + } + delete locationObject; LOG("CInternalGeoTagger::GetLocationInfoL ,end"); } @@ -517,12 +571,16 @@ TItemId tagId = relation.RightObjectId(); CMdEObject* object = NULL; TRAP_IGNORE( object = iMdeSession->GetObjectL( tagId ) ); - - error = object->Uri().Find( KCountry ); - if ( error == KErrNone ) + if(object) { - i = count; - tagFound = ETrue; + error = object->Uri().Find( KCountry ); + delete object; + if ( error == KErrNone ) + { + i = count; + tagFound = ETrue; + break; + } } } @@ -532,36 +590,6 @@ } -// -------------------------------------------------------------------------- -// CInternalGeoTagger::AddressInfo() -// -------------------------------------------------------------------------- -// -void CInternalGeoTagger::AddressInfoL( const TItemId aCountryTagId, const TItemId aCityTagId ) - { - LOG("CInternalGeoTagger::AddressInfoL ,begin"); - - const TInt count = iRelationQuery->Count(); - - for ( TInt i = 0; i < count; i++ ) - { - CMdERelation& relation = iRelationQuery->Result( i ); - TItemId imageId = relation.LeftObjectId(); - - if ( !GPSInfoExists() ) //to update EXIF - { - // update relation timestamp, composer will then update exif data - TTime timestamp( 0 ); - timestamp.UniversalTime(); - relation.SetLastModifiedDate( timestamp ); - iMdeSession->UpdateRelationL( relation ); - } - - iTagCreator->AttachTagsL( imageId, aCountryTagId, aCityTagId ); - } - - LOG("CInternalGeoTagger::AddressInfoL ,end"); - } - // -------------------------------------------------------------------------- // CInternalGeoTagger::IterateNextLocation() @@ -626,42 +654,6 @@ LOG("CInternalGeoTagger::GetAllLocationsL ,end"); } -// -------------------------------------------------------------------------- -// CInternalGeoTagger::ReverseGeocodeComplete() -// Get address details like street, city, state, etc. -// -------------------------------------------------------------------------- -// -void CInternalGeoTagger::ReverseGeocodeComplete( TInt& aErrorcode, MAddressInfo& aAddressInfo ) - { - LOG("CInternalGeoTagger::ReverseGeocodeComplete ,begin"); - TItemId countryTagId(0); - TItemId cityTagId(0); - - // create country and city tags - if( aErrorcode == KErrNone ) - { - TPtrC countryPtr( aAddressInfo.GetCountryName() ); - TPtrC cityPtr( aAddressInfo.GetCity() ); - - TRAP_IGNORE( iTagCreator->CreateLocationTagsL( countryPtr, countryTagId, cityPtr, cityTagId ) ); - - TRAP_IGNORE(AddressInfoL( countryTagId, cityTagId )); - - IterateNextLocation(); - } - else - { - //handle error - if ( iObserver ) - { - iIndex = 0; - iObserver->GeoTaggingCompleted( aErrorcode ); - } - } - - - LOG("CInternalGeoTagger::ReverseGeocodeComplete ,end"); - } // -------------------------------------------------------------------------- // CInternalGeoTagger::GetTagsL() @@ -702,6 +694,82 @@ } #ifdef LOC_GEOTAGGING_CELLID + +// -------------------------------------------------------------------------- +// CInternalGeoTagger::UpdateGPSInfoL() +// -------------------------------------------------------------------------- +// +void CInternalGeoTagger::UpdateGPSInfoL(const TLocality& aPosition) + { + + LOG("CInternalGeoTagger::UpdateGPSInfoL ,start"); + if(Math::IsNaN( aPosition.Latitude()) || + Math::IsNaN( aPosition.Longitude()) ) + { + LOG("Not a valid location info."); + LOG("CInternalGeoTagger::UpdateGPSInfoL ,end"); + return; + } + + CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); + CMdEObjectDef& locObjDef = namespaceDef.GetObjectDefL( Location::KLocationObject ); + CMdEObject* location = iMdeSession->OpenObjectL(iLocationId, locObjDef); + CleanupStack::PushL( location ); + + CMdEPropertyDef& propLatDef = locObjDef.GetPropertyDefL( Location::KLatitudeProperty ); + CMdEPropertyDef& propLongDef = locObjDef.GetPropertyDefL( Location::KLongitudeProperty ); + CMdEPropertyDef& propAltDef = locObjDef.GetPropertyDefL( Location::KAltitudeProperty ); + CMdEPropertyDef& qualityDef = locObjDef.GetPropertyDefL( Location::KQualityProperty ); + + if (location->PropertyCount(propLatDef) == 0) + { + location->AddReal64PropertyL(propLatDef, aPosition.Latitude() ); //iLatitude + } + if (location->PropertyCount(propLongDef) == 0) + { + location->AddReal64PropertyL(propLongDef, aPosition.Longitude() ); //iLongitude + } + if (location->PropertyCount(propAltDef) == 0 && + !Math::IsNaN( aPosition.Altitude()) ) + { + location->AddReal64PropertyL(propAltDef, aPosition.Altitude()); + } + LOG1( "Updating quality - %d", aPosition.HorizontalAccuracy()); + if (location->PropertyCount(qualityDef) == 0 ) + { + location->AddReal32PropertyL(qualityDef, aPosition.HorizontalAccuracy()); + } + + CMdEProperty* modProp = NULL; + CMdEObjectDef& objImageDef = namespaceDef.GetObjectDefL( Image::KImageObject ); + CMdEPropertyDef& propModifiedDef = objImageDef.GetPropertyDefL( Object::KLastModifiedDateProperty ); + location->Property( propModifiedDef, modProp, 0 ); + if ( modProp ) + { + TTime timestamp( 0 ); + timestamp.UniversalTime(); + modProp->SetTimeValueL( timestamp ); + } + // commit to DB + iMdeSession->CommitObjectL(*location); + CleanupStack::PopAndDestroy( location ); + + // update the relation + const TInt count = iRelationQuery->Count(); + LOG1("Relation count - %d", count); + for ( TInt i = 0; i < count; i++ ) + { + CMdERelation& relation = iRelationQuery->Result( i ); + // update relation timestamp, composer will then update exif data + + TTime timestamp( 0 ); + timestamp.UniversalTime(); + relation.SetLastModifiedDate( timestamp ); + iMdeSession->UpdateRelationL( relation ); + } + LOG("CInternalGeoTagger::UpdateGPSInfoL ,end"); + } + // -------------------------------------------------------------------------- // CInternalGeoTagger::ConversionCompletedL() // -------------------------------------------------------------------------- @@ -714,13 +782,17 @@ if(aError == KErrNone) { iLocationData.iPosition.SetCoordinate - ( aPosition.Latitude(), aPosition.Longitude()); + ( aPosition.Latitude(), aPosition.Longitude(), aPosition.Altitude()); + iLocationData.iQuality = aPosition.HorizontalAccuracy(); + UpdateGPSInfoL(aPosition); +#ifdef LOC_REVERSEGEOCODE if(iRevGeocoderPlugin) { iRevGeocoderPlugin->GetAddressByCoordinateL ( iLocationData.iPosition, iConnectionOption ) ; } else +#endif //LOC_REVERSEGEOCODE { IterateNextLocation(); //Go through next location } @@ -745,7 +817,7 @@ LOG("CInternalGeoTagger::HandleConversionError, end"); } -#endif +#endif //LOC_GEOTAGGING_CELLID // -------------------------------------------------------------------------- // CInternalGeoTagger::PendingGeoTagsL() @@ -764,7 +836,7 @@ } else { - if(!iTagPendingHandlerFlag) + if(!iTagPendingHandlerFlag && iIndex <= 0) { LOG("Processing the request.\n"); // tag pending request is not going on @@ -781,6 +853,73 @@ LOG("CInternalGeoTagger::PendingGeoTagsL ,end"); } + +#ifdef LOC_REVERSEGEOCODE +// -------------------------------------------------------------------------- +// CInternalGeoTagger::AddressInfo() +// -------------------------------------------------------------------------- +// +void CInternalGeoTagger::AddressInfoL( const TItemId aCountryTagId, const TItemId aCityTagId ) + { + LOG("CInternalGeoTagger::AddressInfoL ,begin"); + + const TInt count = iRelationQuery->Count(); + + for ( TInt i = 0; i < count; i++ ) + { + CMdERelation& relation = iRelationQuery->Result( i ); + TItemId imageId = relation.LeftObjectId(); + + if ( !GPSInfoExists() ) //to update EXIF + { + // update relation timestamp, composer will then update exif data + TTime timestamp( 0 ); + timestamp.UniversalTime(); + relation.SetLastModifiedDate( timestamp ); + iMdeSession->UpdateRelationL( relation ); + } + + iTagCreator->AttachTagsL( imageId, aCountryTagId, aCityTagId ); + } + + LOG("CInternalGeoTagger::AddressInfoL ,end"); + } + + +// -------------------------------------------------------------------------- +// CInternalGeoTagger::ReverseGeocodeComplete() +// Get address details like street, city, state, etc. +// -------------------------------------------------------------------------- +// +void CInternalGeoTagger::ReverseGeocodeComplete( TInt& aErrorcode, MAddressInfo& aAddressInfo ) + { + LOG("CInternalGeoTagger::ReverseGeocodeComplete ,begin"); + TItemId countryTagId(0); + TItemId cityTagId(0); + + // create country and city tags + if( aErrorcode == KErrNone ) + { + TPtrC countryPtr( aAddressInfo.GetCountryName() ); + TPtrC cityPtr( aAddressInfo.GetCity() ); + + TRAP_IGNORE( iTagCreator->CreateLocationTagsL( countryPtr, countryTagId, cityPtr, cityTagId ) ); + + TRAP_IGNORE(AddressInfoL( countryTagId, cityTagId )); + + IterateNextLocation(); + } + else + { + LOG1("Reverse geocode err - %d", aErrorcode); + + IterateNextLocation(); + } + + + LOG("CInternalGeoTagger::ReverseGeocodeComplete ,end"); + } + // ---------------------------------------------------------------------------- // CInternalGeoTagger::GetCurrentRegisterNw() // ---------------------------------------------------------------------------- @@ -809,5 +948,7 @@ return iObserver->GetHomeNetworkInfo(aHomeNwInfoAvailableFlag); } +#endif //LOC_REVERSEGEOCODE + // End of file