locationmanager/locationtrail/src/locationremappingao.cpp
branchRCL_3
changeset 47 b73252188534
parent 17 50de4d668bb6
child 63 e538444823de
equal deleted inserted replaced
46:63c982fb92f2 47:b73252188534
    22 #include "mdeobjectdef.h" 
    22 #include "mdeobjectdef.h" 
    23 #include "mdeobjectquery.h"
    23 #include "mdeobjectquery.h"
    24 
    24 
    25 using namespace MdeConstants;
    25 using namespace MdeConstants;
    26 
    26 
       
    27 
       
    28 // --------------------------------------------------------------------------
       
    29 // CLocationRemappingAO::NewL()
       
    30 // --------------------------------------------------------------------------
       
    31 //
    27 CLocationRemappingAO* CLocationRemappingAO::NewL()
    32 CLocationRemappingAO* CLocationRemappingAO::NewL()
    28 	{
    33 	{
    29 	LOG( "CLocationRemappingAO::NewL" ); // DEBUG INFO
    34 	LOG( "CLocationRemappingAO::NewL" ); // DEBUG INFO
    30 	
    35 	
    31 	CLocationRemappingAO* self = new (ELeave) CLocationRemappingAO();
    36 	CLocationRemappingAO* self = new (ELeave) CLocationRemappingAO();
    33 	self->ConstructL();
    38 	self->ConstructL();
    34 	CleanupStack::Pop( self );
    39 	CleanupStack::Pop( self );
    35 	return self;
    40 	return self;
    36 	}
    41 	}
    37 
    42 
       
    43 // --------------------------------------------------------------------------
       
    44 // CLocationRemappingAO::ConstructL()
       
    45 // --------------------------------------------------------------------------
       
    46 //
    38 void CLocationRemappingAO::ConstructL()
    47 void CLocationRemappingAO::ConstructL()
    39 	{
    48 	{
    40 	LOG( "CLocationRemappingAO::ConstructL" ); // DEBUG INFO
    49 	LOG( "CLocationRemappingAO::ConstructL" ); // DEBUG INFO
    41 	CActiveScheduler::Add( this );
    50 	CActiveScheduler::Add( this );
    42 	iMdEClient = NULL;
    51 	iMdEClient = NULL;
    47 		LOG( "CLocationRemappingAO::ConstructL, Can not read timelimit value from CenRep");
    56 		LOG( "CLocationRemappingAO::ConstructL, Can not read timelimit value from CenRep");
    48 		iTimeLimit = TTimeIntervalSeconds( KRemappingTime );
    57 		iTimeLimit = TTimeIntervalSeconds( KRemappingTime );
    49 		}
    58 		}
    50 	}
    59 	}
    51 
    60 
       
    61 // --------------------------------------------------------------------------
       
    62 // CLocationRemappingAO::~CLocationRemappingAO()
       
    63 // --------------------------------------------------------------------------
       
    64 //
    52 CLocationRemappingAO::~CLocationRemappingAO()
    65 CLocationRemappingAO::~CLocationRemappingAO()
    53 	{
    66 	{
    54 	LOG( "CLocationRemappingAO::~CLocationRemappingAO" ); // DEBUG INFO
    67 	LOG( "CLocationRemappingAO::~CLocationRemappingAO" ); // DEBUG INFO
    55 
    68 
    56 	StopRemapping();
    69 	StopRemapping();
    57 	Cancel();
    70 	Cancel();
    58 	
    71 	
    59 	iObjects.ResetAndDestroy();
    72 	iObjects.ResetAndDestroy();
    60 	}
    73 	}
    61 
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // CLocationRemappingAO::CLocationRemappingAO()
       
    77 // --------------------------------------------------------------------------
       
    78 //
    62 CLocationRemappingAO::CLocationRemappingAO() : CActive( CActive::EPriorityStandard ),
    79 CLocationRemappingAO::CLocationRemappingAO() : CActive( CActive::EPriorityStandard ),
    63 	iState ( EIdle ),
    80 	iState ( EIdle ),
    64 	iContinue( EFalse ),
    81 	iContinue( EFalse ),
    65 	iTimed( EFalse ),
    82 	iTimed( EFalse ),
    66 	iRequested( EFalse ),
    83 	iRequested( EFalse ),
    69 	iTimeLimit( 0 )
    86 	iTimeLimit( 0 )
    70 	{
    87 	{
    71 	// No implementation required
    88 	// No implementation required
    72 	}
    89 	}
    73 
    90 
    74 
    91 // --------------------------------------------------------------------------
       
    92 // CLocationRemappingAO::InitialiseL()
       
    93 // --------------------------------------------------------------------------
       
    94 //
    75 void CLocationRemappingAO::InitialiseL(CMdESession* aMdEClient)
    95 void CLocationRemappingAO::InitialiseL(CMdESession* aMdEClient)
    76 	{
    96 	{
    77 	LOG( "CLocationRemappingAO::Initialise start" ); // DEBUG INFO
    97 	LOG( "CLocationRemappingAO::Initialise start" ); // DEBUG INFO
    78 	iMdEClient = aMdEClient;
    98 	iMdEClient = aMdEClient;
    79 	
    99 	
    95 	iContainsLocationRelDef = &iNamespaceDef->GetRelationDefL( Relations::KContainsLocation );
   115 	iContainsLocationRelDef = &iNamespaceDef->GetRelationDefL( Relations::KContainsLocation );
    96 	
   116 	
    97 	LOG( "CLocationRemappingAO::Initialise end" );
   117 	LOG( "CLocationRemappingAO::Initialise end" );
    98 	}
   118 	}
    99 
   119 
       
   120 
       
   121 // --------------------------------------------------------------------------
       
   122 // CLocationRemappingAO::Append()
       
   123 // --------------------------------------------------------------------------
       
   124 //
   100 void CLocationRemappingAO::Append( TRemapItem aItem )
   125 void CLocationRemappingAO::Append( TRemapItem aItem )
   101 	{
   126 	{
   102 	iRemapItems.Append( aItem );
   127 	iRemapItems.Append( aItem );
   103 	}
   128 	}
   104 
   129 
       
   130 
       
   131 // --------------------------------------------------------------------------
       
   132 // CLocationRemappingAO::ResetQueue()
       
   133 // --------------------------------------------------------------------------
       
   134 //
   105 void CLocationRemappingAO::ResetQueue()
   135 void CLocationRemappingAO::ResetQueue()
   106 	{
   136 	{
   107 	iRemapItems.Reset();
   137 	iRemapItems.Reset();
   108 	}
   138 	}
   109 
   139 
       
   140 
       
   141 // --------------------------------------------------------------------------
       
   142 // CLocationRemappingAO::ItemsInQueue()
       
   143 // --------------------------------------------------------------------------
       
   144 //
   110 TBool CLocationRemappingAO::ItemsInQueue()
   145 TBool CLocationRemappingAO::ItemsInQueue()
   111 	{
   146 	{
   112 	return iRemapItems.Count() > 0;
   147 	return iRemapItems.Count() > 0;
   113 	}
   148 	}
   114 
   149 
       
   150 
       
   151 // --------------------------------------------------------------------------
       
   152 // CLocationRemappingAO::CheckQueue()
       
   153 // --------------------------------------------------------------------------
       
   154 //
   115 TBool CLocationRemappingAO::CheckQueue()
   155 TBool CLocationRemappingAO::CheckQueue()
   116 	{
   156 	{
   117 	LOG( "CLocationRemappingAO::CheckQueue - start" );
   157 	LOG( "CLocationRemappingAO::CheckQueue - start" );
   118 	TBool create( EFalse );
   158 	TBool create( EFalse );
   119 	TInt index = iRemapItems.Count() - 1;
   159 	TInt index = iRemapItems.Count() - 1;
   163 	removeLocations.Close();
   203 	removeLocations.Close();
   164 	LOG( "CLocationRemappingAO::CheckQueue - end" );
   204 	LOG( "CLocationRemappingAO::CheckQueue - end" );
   165 	return create;
   205 	return create;
   166 	}
   206 	}
   167 
   207 
   168 
   208 // --------------------------------------------------------------------------
       
   209 // CLocationRemappingAO::StopRemapping()
       
   210 // --------------------------------------------------------------------------
       
   211 //
   169 void CLocationRemappingAO::StopRemapping()
   212 void CLocationRemappingAO::StopRemapping()
   170 	{
   213 	{
   171 	LOG( "CLocationRemappingAO::StopRemapping" ); // DEBUG INFO
   214 	LOG( "CLocationRemappingAO::StopRemapping" ); // DEBUG INFO
   172 	NextState(EIdle);
   215 	NextState(EIdle);
   173 	}
   216 	}
   174 
   217 
       
   218 
       
   219 // --------------------------------------------------------------------------
       
   220 // CLocationRemappingAO::StartRemappingObjects()
       
   221 // --------------------------------------------------------------------------
       
   222 //
   175 void CLocationRemappingAO::StartRemappingObjects( const TLocationData& aLocationData )
   223 void CLocationRemappingAO::StartRemappingObjects( const TLocationData& aLocationData )
   176 	{
   224 	{
   177 	iLocationData = aLocationData;
   225 	iLocationData = aLocationData;
   178 	LOG( "CLocationRemappingAO::StartRemappingObjects" ); // DEBUG INFO
   226 	LOG( "CLocationRemappingAO::StartRemappingObjects" ); // DEBUG INFO
   179 	TInt count = iRemapItems.Count();
   227 	TInt count = iRemapItems.Count();
   183 		return;
   231 		return;
   184 		}
   232 		}
   185 	NextState( ERemapObjects );
   233 	NextState( ERemapObjects );
   186 	}
   234 	}
   187 
   235 
       
   236 
       
   237 // --------------------------------------------------------------------------
       
   238 // CLocationRemappingAO::NextState()
       
   239 // --------------------------------------------------------------------------
       
   240 //
   188 void CLocationRemappingAO::NextState(TMappingState aState)
   241 void CLocationRemappingAO::NextState(TMappingState aState)
   189 	{
   242 	{
   190 	LOG1( "CLocationRemappingAO::NextState - state: %d", aState ); // DEBUG INFO
   243 	LOG1( "CLocationRemappingAO::NextState - state: %d", aState ); // DEBUG INFO
   191 	iState = aState;
   244 	iState = aState;
   192 	// Request complete if not idling
   245 	// Request complete if not idling
   196 		User::RequestComplete( pStatus, KErrNone );
   249 		User::RequestComplete( pStatus, KErrNone );
   197 		SetActive();
   250 		SetActive();
   198 		}	
   251 		}	
   199 	}
   252 	}
   200 
   253 
       
   254 
       
   255 // --------------------------------------------------------------------------
       
   256 // CLocationRemappingAO::DoCancel()
       
   257 // --------------------------------------------------------------------------
       
   258 //
   201 void CLocationRemappingAO::DoCancel()
   259 void CLocationRemappingAO::DoCancel()
   202 	{
   260 	{
   203 	LOG( "CLocationRemappingAO::DoCancel" ); // DEBUG INFO
   261 	LOG( "CLocationRemappingAO::DoCancel" ); // DEBUG INFO
   204 	// back to idle
   262 	// back to idle
   205 	NextState(EIdle);
   263 	NextState(EIdle);
   206 	}
   264 	}
   207 
   265 
       
   266 
       
   267 // --------------------------------------------------------------------------
       
   268 // CLocationRemappingAO::RunError()
       
   269 // --------------------------------------------------------------------------
       
   270 //
   208 TInt CLocationRemappingAO::RunError( TInt aError )
   271 TInt CLocationRemappingAO::RunError( TInt aError )
   209 	{
   272 	{
   210 	if (aError != KErrNone)
   273 	if (aError != KErrNone)
   211 		{
   274 		{
   212 		LOG1( "CLocationRemappingAO::RunError with error code: %d", aError ); // DEBUG INFO
   275 		LOG1( "CLocationRemappingAO::RunError with error code: %d", aError ); // DEBUG INFO
   214 	// back to idle
   277 	// back to idle
   215 	NextState(EIdle);
   278 	NextState(EIdle);
   216 	return KErrNone;
   279 	return KErrNone;
   217 	}
   280 	}
   218 
   281 
       
   282 
       
   283 // --------------------------------------------------------------------------
       
   284 // CLocationRemappingAO::RunL()
       
   285 // --------------------------------------------------------------------------
       
   286 //
   219 void CLocationRemappingAO::RunL()
   287 void CLocationRemappingAO::RunL()
   220 	{
   288 	{
   221 	LOG1( "CCameraTrailMonitorAO::RunL iStatus: %d", iStatus.Int() ); // DEBUG INFO
   289 	LOG1( "CCameraTrailMonitorAO::RunL iStatus: %d", iStatus.Int() ); // DEBUG INFO
   222 	
   290 	
   223 	switch(iState)
   291 	switch(iState)
   250 			break;
   318 			break;
   251 			}
   319 			}
   252 		}
   320 		}
   253 	}
   321 	}
   254 
   322 
   255 
   323 // --------------------------------------------------------------------------
       
   324 // CLocationRemappingAO::RemapObjectsL()
       
   325 // --------------------------------------------------------------------------
       
   326 //
   256 void CLocationRemappingAO::RemapObjectsL()
   327 void CLocationRemappingAO::RemapObjectsL()
   257 	{	
   328 	{	
   258 	LOG( "CLocationRemappingAO::RemapObjects - start" ); // DEBUG INFO
   329 	LOG( "CLocationRemappingAO::RemapObjects - start" ); // DEBUG INFO
   259 	// remap location data to location objects
   330 	// remap location data to location objects
   260 	TInt count = iRemapItems.Count();
   331 	TInt count = iRemapItems.Count();
   312 		{
   383 		{
   313 		CMdERelation* relation = NULL;
   384 		CMdERelation* relation = NULL;
   314 		relation = iMdEClient->GetRelationL( iRemapItems[i].iRelationId );
   385 		relation = iMdEClient->GetRelationL( iRemapItems[i].iRelationId );
   315 		
   386 		
   316 		if(relation)
   387 		if(relation)
   317 		    {   
   388 		    {
       
   389 		    CleanupStack::PushL(relation);
   318             TTime timestamp( 0 );
   390             TTime timestamp( 0 );
   319             timestamp.UniversalTime();
   391             timestamp.UniversalTime();
   320             relation->SetLastModifiedDate( timestamp );
   392             relation->SetLastModifiedDate( timestamp );
   321     	
   393     	
   322             iMdEClient->UpdateRelationL( *relation );
   394             iMdEClient->UpdateRelationL( *relation );
       
   395 		    CleanupStack::PopAndDestroy(relation);
   323 		    }
   396 		    }
   324 		}
   397 		}
   325 	
   398 	
   326 	LOG("CLocationRemappingAO::RemapObjectsL - relations updated");
   399 	LOG("CLocationRemappingAO::RemapObjectsL - relations updated");
   327 	
   400 	
   329 	ResetQueue();
   402 	ResetQueue();
   330 	
   403 	
   331 	LOG( "CLocationRemappingAO::RemapObjects - end" );
   404 	LOG( "CLocationRemappingAO::RemapObjects - end" );
   332 	}
   405 	}
   333 
   406 
       
   407 
       
   408 // --------------------------------------------------------------------------
       
   409 // CLocationRemappingAO::CommitObjectsL()
       
   410 // --------------------------------------------------------------------------
       
   411 //
   334 void CLocationRemappingAO::CommitObjectsL()
   412 void CLocationRemappingAO::CommitObjectsL()
   335 	{
   413 	{
   336 	LOG( "CLocationRemappingAO::CommitObjects" ); // DEBUG INFO
   414 	LOG( "CLocationRemappingAO::CommitObjects" ); // DEBUG INFO
   337 	// commit location objects
   415 	// commit location objects
   338 	if( iObjects.Count() > 0 )
   416 	if( iObjects.Count() > 0 )
   358 	iTimeLimit = TTimeIntervalSeconds( value );
   436 	iTimeLimit = TTimeIntervalSeconds( value );
   359 
   437 
   360     LOG( "CLocationRemappingAO::ReadTimeFromCenRepL(), end" );   
   438     LOG( "CLocationRemappingAO::ReadTimeFromCenRepL(), end" );   
   361 	}
   439 	}
   362 
   440 
   363 
   441 // --------------------------------------------------------------------------
       
   442 // CLocationRemappingAO::UpdateRelationsL()
       
   443 // --------------------------------------------------------------------------
       
   444 //
   364 void CLocationRemappingAO::UpdateRelationsL( TItemId aLocationId )
   445 void CLocationRemappingAO::UpdateRelationsL( TItemId aLocationId )
   365 	{ 
   446 	{ 
   366 	LOG("CLocationRemappingAO::UpdateRelationsL - start");
   447 	LOG("CLocationRemappingAO::UpdateRelationsL - start");
   367 	CMdENamespaceDef& namespaceDef = iMdEClient->GetDefaultNamespaceDefL();
   448 	CMdENamespaceDef& namespaceDef = iMdEClient->GetDefaultNamespaceDefL();
   368 	
   449 	
   379 				{
   460 				{
   380 				CMdERelation* relationObject = iMdEClient->NewRelationLC( containsRelDef,
   461 				CMdERelation* relationObject = iMdEClient->NewRelationLC( containsRelDef,
   381 						iRemapItems[i].iObjectId, aLocationId, 0 );
   462 						iRemapItems[i].iObjectId, aLocationId, 0 );
   382 				iMdEClient->AddRelationL( *relationObject );
   463 				iMdEClient->AddRelationL( *relationObject );
   383 				CleanupStack::PopAndDestroy( relationObject );
   464 				CleanupStack::PopAndDestroy( relationObject );
   384 				LOG("CLocationRemappingAO::UpdateRelationsL - new relation created");
   465 				LOG("new relation created");
   385 				}
   466 				}
   386 			else
   467 			else
   387 				{
   468 				{
   388 				CMdERelation* relationObject = iMdEClient->GetRelationL( iRemapItems[i].iRelationId );
   469 				CMdERelation* relationObject = iMdEClient->GetRelationL( iRemapItems[i].iRelationId );
       
   470                 CleanupStack::PushL(relationObject);
   389 				relationObject->SetRightObjectIdL( aLocationId );
   471 				relationObject->SetRightObjectIdL( aLocationId );
   390 				iMdEClient->UpdateRelationL( *relationObject );
   472 				iMdEClient->UpdateRelationL( *relationObject );
   391 				LOG("CLocationRemappingAO::UpdateRelationsL - old relation updated");
   473                 CleanupStack::PopAndDestroy(relationObject);
       
   474 				LOG("old relation updated");
   392 				}
   475 				}
   393 			iRemapItems.Remove( i );
   476 			iRemapItems.Remove( i );
   394 			}
   477 			}
   395 		}
   478 		}
   396 	LOG("CLocationRemappingAO::UpdateRelationsL - end");
   479 	LOG("CLocationRemappingAO::UpdateRelationsL - end");
   397 	}
   480 	}
       
   481 
       
   482 #ifdef LOC_REVERSEGEOCODE
       
   483 // --------------------------------------------------------------------------
       
   484 // CLocationRemapping::AttachGeoTagsL
       
   485 // --------------------------------------------------------------------------
       
   486 //
       
   487 void CLocationRemappingAO::AttachGeoTagsL( CTagCreator *aTagCreator,
       
   488                                          const TItemId aCountryTagId, const TItemId aCityTagId )
       
   489     { 
       
   490     LOG("CLocationRemapping::AttachGeoTagsL - start");
       
   491     
       
   492     TInt count = iObjectIds.Count() - 1;
       
   493     for( TInt i = count; i >= 0; i-- )
       
   494         {
       
   495         aTagCreator->AttachTagsL( iObjectIds[i], aCountryTagId, aCityTagId );
       
   496         }
       
   497     
       
   498     iObjectIds.Reset();
       
   499     
       
   500     LOG("CLocationRemapping::AttachGeoTagsL - end");
       
   501     }
       
   502 
       
   503 #endif //LOC_REVERSEGEOCODE
       
   504 
   398 
   505 
   399 // --------------------------------------------------------------------------
   506 // --------------------------------------------------------------------------
   400 // TRemapItem constructor
   507 // TRemapItem constructor
   401 // --------------------------------------------------------------------------
   508 // --------------------------------------------------------------------------
   402 //
   509 //
   407 	iTime( 0 )
   514 	iTime( 0 )
   408 	{
   515 	{
   409 	
   516 	
   410 	}
   517 	}
   411 
   518 
       
   519 // End of file