omadrm/drmengine/drmclock/Src/GPSTimeUpdater.cpp
branchRCL_3
changeset 32 457cd4423b8c
parent 18 8a03a285ab14
equal deleted inserted replaced
25:04da681812a9 32:457cd4423b8c
    24 #include "drmlog.h"
    24 #include "drmlog.h"
    25 
    25 
    26 
    26 
    27 _LIT(KDRMClockServerName, "DRMClockServer");
    27 _LIT(KDRMClockServerName, "DRMClockServer");
    28 
    28 
       
    29 const TInt KGPSUpdateInterval   = 1000000;  // One second
       
    30 const TInt KGPSUpdateAge        = 500000;   // Half a second
       
    31 const TInt KGPSUpdateTimeOut    = 30000000; // Thirty seconds
       
    32 
    29 // ============================ MEMBER FUNCTIONS ===============================
    33 // ============================ MEMBER FUNCTIONS ===============================
    30 
    34 
    31 
    35 
    32 // -----------------------------------------------------------------------------
    36 // -----------------------------------------------------------------------------
    33 // CGPSTimeUpdater::CGPSTimeUpdater
    37 // CGPSTimeUpdater::CGPSTimeUpdater
    34 // C++ default constructor can NOT contain any code, that
    38 // C++ default constructor can NOT contain any code, that
    35 // might leave.
    39 // might leave.
    36 // -----------------------------------------------------------------------------
    40 // -----------------------------------------------------------------------------
    37 //   
    41 //   
    38 CGPSTimeUpdater::CGPSTimeUpdater( RPositionServer &aPosServer, 
    42 CGPSTimeUpdater::CGPSTimeUpdater( const TPositionModuleId& aModuleId,
    39                                   const TPositionModuleId& aModuleId,
       
    40                                   CDRMClock* aClock ) : 
    43                                   CDRMClock* aClock ) : 
    41 	CActive(EPriorityHigh),
    44 	CActive(EPriorityHigh),
    42 	iPosServer(aPosServer),
       
    43 	iModuleId(aModuleId),
    45 	iModuleId(aModuleId),
    44 	iClock( aClock ),
    46 	iClock( aClock ),
    45 	iTimeReceived( EFalse )
    47 	iTimeReceived( EFalse )
    46 	{
    48 	{
    47 	CActiveScheduler::Add(this);
    49 	CActiveScheduler::Add(this);
    56 	{
    58 	{
    57 	DRMLOG(_L("CGPSTimeUpdater::~CGPSTimeUpdater"));
    59 	DRMLOG(_L("CGPSTimeUpdater::~CGPSTimeUpdater"));
    58 	Cancel();
    60 	Cancel();
    59 	
    61 	
    60 	iPositioner.Close();
    62 	iPositioner.Close();
       
    63 	iPosServer.Close();
    61 	}
    64 	}
    62 
    65 
    63 // -----------------------------------------------------------------------------
    66 // -----------------------------------------------------------------------------
    64 // CGPSTimeUpdater::New
    67 // CGPSTimeUpdater::New
    65 // Two-phased constructor
    68 // Two-phased constructor
    66 // -----------------------------------------------------------------------------
    69 // -----------------------------------------------------------------------------
    67 //
    70 //
    68 CGPSTimeUpdater* CGPSTimeUpdater::New( RPositionServer &aPosServer, 
    71 CGPSTimeUpdater* CGPSTimeUpdater::New( const TPositionModuleId& aModuleId,
    69                                        const TPositionModuleId& aModuleId,
       
    70                                        CDRMClock* aClock )
    72                                        CDRMClock* aClock )
    71 	{
    73 	{
    72 	CGPSTimeUpdater* self = new CGPSTimeUpdater(aPosServer, aModuleId, aClock);
    74 	CGPSTimeUpdater* self = new CGPSTimeUpdater(aModuleId, aClock);
    73 	if(self)
    75 	if(self)
    74 		{
    76 		{
    75 		TRAPD(err, self->ConstructL());
    77 		TRAPD(err, self->ConstructL());
    76 		if(err!=KErrNone)
    78 		if(err!=KErrNone)
    77 			{
    79 			{
    90 //
    92 //
    91 void CGPSTimeUpdater::ConstructL()
    93 void CGPSTimeUpdater::ConstructL()
    92 	{
    94 	{
    93 	DRMLOG(_L("CGPSTimeUpdater::ConstructL >>"));
    95 	DRMLOG(_L("CGPSTimeUpdater::ConstructL >>"));
    94 	
    96 	
       
    97 	User::LeaveIfError( iPosServer.Connect() );
       
    98 	
    95 	// Open positioner
    99 	// Open positioner
    96 	User::LeaveIfError(iPositioner.Open(iPosServer, iModuleId));
   100 	User::LeaveIfError(iPositioner.Open(iPosServer, iModuleId));
    97 	User::LeaveIfError(iPositioner.SetRequestor(CRequestor::ERequestorService,
   101 	User::LeaveIfError(iPositioner.SetRequestor(CRequestor::ERequestorService,
    98 	                   CRequestor::EFormatApplication, 
   102 	                   CRequestor::EFormatApplication, 
    99 	                   KDRMClockServerName));
   103 	                   KDRMClockServerName));
   100 	
   104 	
   101 	// Set update options
   105 	// Set update options
   102 	TPositionUpdateOptions updateOptions;
   106 	TPositionUpdateOptions updateOptions;
   103 	updateOptions.SetAcceptPartialUpdates(ETrue);
   107 	updateOptions.SetAcceptPartialUpdates(ETrue);
   104 	updateOptions.SetMaxUpdateAge(0);
   108 	updateOptions.SetMaxUpdateAge(KGPSUpdateAge);
   105 	updateOptions.SetUpdateInterval(TTimeIntervalMicroSeconds(0));
   109 	updateOptions.SetUpdateInterval(TTimeIntervalMicroSeconds(KGPSUpdateInterval));
   106 	updateOptions.SetUpdateTimeOut(TTimeIntervalMicroSeconds(30*1000*1000));
   110 	updateOptions.SetUpdateTimeOut(TTimeIntervalMicroSeconds(KGPSUpdateTimeOut));
   107 	User::LeaveIfError(iPositioner.SetUpdateOptions(updateOptions));
   111 	User::LeaveIfError(iPositioner.SetUpdateOptions(updateOptions));
   108 	
   112 	
   109 	// Request position update
   113 	// Request position update
   110 	iPositioner.NotifyPositionUpdate(iSatelliteInfo, iStatus);
   114 	iPositioner.NotifyPositionUpdate(iSatelliteInfo, iStatus);
   111 	SetActive();
   115 	SetActive();
   122 	{
   126 	{
   123 	DRMLOG(_L("CGPSTimeUpdater::RunL >>"));
   127 	DRMLOG(_L("CGPSTimeUpdater::RunL >>"));
   124 	
   128 	
   125 	DRMLOG2(_L("CGPSTimeUpdater::RunL: iStatus=%d"), iStatus.Int());
   129 	DRMLOG2(_L("CGPSTimeUpdater::RunL: iStatus=%d"), iStatus.Int());
   126 	
   130 	
   127 	if( iStatus == KErrNone || iStatus == KPositionPartialUpdate )
   131 	// We got some kind of an update:
       
   132 	if( iStatus == KErrNone || 
       
   133 	    iStatus == KPositionPartialUpdate )
   128 		{
   134 		{
   129 		DRMLOG(_L("CGPSTimeUpdater::RunL: position updated!"));
   135 		DRMLOG(_L("CGPSTimeUpdater::RunL: position updated!"));
   130 		
   136 		
   131 		DRMLOG2(_L("CGPSTimeUpdater::RunL: satellites used = %d"), iSatelliteInfo.NumSatellitesUsed());
   137 		DRMLOG2(_L("CGPSTimeUpdater::RunL: satellites used = %d"), iSatelliteInfo.NumSatellitesUsed());
   132 		TTime satelliteTime = iSatelliteInfo.SatelliteTime();
   138 		TTime satelliteTime = iSatelliteInfo.SatelliteTime();
   138 		iClock->ResetSecureTimeL( satelliteTime, 0 );    
   144 		iClock->ResetSecureTimeL( satelliteTime, 0 );    
   139 		
   145 		
   140 		// Mark time as received
   146 		// Mark time as received
   141 		iTimeReceived = ETrue;
   147 		iTimeReceived = ETrue;
   142 		}
   148 		}
   143 		
   149 
   144     // if the call timed out try again		
   150     // We only try once, if it fails it fails and we will try again when it is activated the next time.
   145     if( iStatus == KErrTimedOut ) 
   151 	iPositioner.Close();
   146 	    {
       
   147 	    // Request position update
       
   148 	    iPositioner.NotifyPositionUpdate(iSatelliteInfo, iStatus);
       
   149 	    SetActive();
       
   150 	    }	
       
   151 	else 	
       
   152 	    {    	
       
   153 	    iPositioner.Close();
       
   154         }
       
   155         
   152         
   156 	DRMLOG(_L("CGPSTimeUpdater::RunL <<"));
   153 	DRMLOG(_L("CGPSTimeUpdater::RunL <<"));
   157 	}
   154 	}
   158 
   155 
   159 // -----------------------------------------------------------------------------
   156 // -----------------------------------------------------------------------------