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