omadrm/drmengine/drmclock/Src/GPSTimeUpdater.cpp
branchRCL_3
changeset 18 8a03a285ab14
child 31 908beac81e0a
equal deleted inserted replaced
17:e16d72588c28 18:8a03a285ab14
       
     1 
       
     2 /*
       
     3 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 * All rights reserved.
       
     5 * This component and the accompanying materials are made available
       
     6 * under the terms of "Eclipse Public License v1.0"
       
     7 * which accompanies this distribution, and is available
       
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 *
       
    10 * Initial Contributors:
       
    11 * Nokia Corporation - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 *
       
    15 * Description:  Implementation of the GPS time updater
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <e32debug.h>
       
    22 #include "GPSTimeUpdater.h"
       
    23 #include "DRMClock.h"
       
    24 #include "drmlog.h"
       
    25 
       
    26 
       
    27 _LIT(KDRMClockServerName, "DRMClockServer");
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CGPSTimeUpdater::CGPSTimeUpdater
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //   
       
    38 CGPSTimeUpdater::CGPSTimeUpdater( RPositionServer &aPosServer, 
       
    39                                   const TPositionModuleId& aModuleId,
       
    40                                   CDRMClock* aClock ) : 
       
    41 	CActive(EPriorityHigh),
       
    42 	iPosServer(aPosServer),
       
    43 	iModuleId(aModuleId),
       
    44 	iClock( aClock ),
       
    45 	iTimeReceived( EFalse )
       
    46 	{
       
    47 	CActiveScheduler::Add(this);
       
    48 	}
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CGPSTimeUpdater::~CGPSTimeUpdater
       
    52 // C++ destructor
       
    53 // -----------------------------------------------------------------------------
       
    54 // 
       
    55 CGPSTimeUpdater::~CGPSTimeUpdater()
       
    56 	{
       
    57 	DRMLOG(_L("CGPSTimeUpdater::~CGPSTimeUpdater"));
       
    58 	Cancel();
       
    59 	
       
    60 	iPositioner.Close();
       
    61 	}
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CGPSTimeUpdater::New
       
    65 // Two-phased constructor
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CGPSTimeUpdater* CGPSTimeUpdater::New( RPositionServer &aPosServer, 
       
    69                                        const TPositionModuleId& aModuleId,
       
    70                                        CDRMClock* aClock )
       
    71 	{
       
    72 	CGPSTimeUpdater* self = new CGPSTimeUpdater(aPosServer, aModuleId, aClock);
       
    73 	if(self)
       
    74 		{
       
    75 		TRAPD(err, self->ConstructL());
       
    76 		if(err!=KErrNone)
       
    77 			{
       
    78 			delete self;
       
    79 			self = 0;
       
    80 			}
       
    81 		}
       
    82 	return self;
       
    83 	}
       
    84 
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CGPSTimeUpdater::ConstructL
       
    88 // Symbian 2nd phase constructor can leave.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CGPSTimeUpdater::ConstructL()
       
    92 	{
       
    93 	DRMLOG(_L("CGPSTimeUpdater::ConstructL >>"));
       
    94 	
       
    95 	// Open positioner
       
    96 	User::LeaveIfError(iPositioner.Open(iPosServer, iModuleId));
       
    97 	User::LeaveIfError(iPositioner.SetRequestor(CRequestor::ERequestorService,
       
    98 	                   CRequestor::EFormatApplication, 
       
    99 	                   KDRMClockServerName));
       
   100 	
       
   101 	// Set update options
       
   102 	TPositionUpdateOptions updateOptions;
       
   103 	updateOptions.SetAcceptPartialUpdates(ETrue);
       
   104 	updateOptions.SetMaxUpdateAge(0);
       
   105 	updateOptions.SetUpdateInterval(TTimeIntervalMicroSeconds(0));
       
   106 	updateOptions.SetUpdateTimeOut(TTimeIntervalMicroSeconds(30*1000*1000));
       
   107 	User::LeaveIfError(iPositioner.SetUpdateOptions(updateOptions));
       
   108 	
       
   109 	// Request position update
       
   110 	iPositioner.NotifyPositionUpdate(iSatelliteInfo, iStatus);
       
   111 	SetActive();
       
   112 	
       
   113 	DRMLOG(_L("CGPSTimeUpdater::ConstructL <<"));
       
   114 	}
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CGPSTimeUpdater::RunL
       
   118 // Inherited from CActive
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void CGPSTimeUpdater::RunL()
       
   122 	{
       
   123 	DRMLOG(_L("CGPSTimeUpdater::RunL >>"));
       
   124 	
       
   125 	DRMLOG2(_L("CGPSTimeUpdater::RunL: iStatus=%d"), iStatus.Int());
       
   126 	
       
   127 	if( iStatus == KErrNone || iStatus == KPositionPartialUpdate )
       
   128 		{
       
   129 		DRMLOG(_L("CGPSTimeUpdater::RunL: position updated!"));
       
   130 		
       
   131 		DRMLOG2(_L("CGPSTimeUpdater::RunL: satellites used = %d"), iSatelliteInfo.NumSatellitesUsed());
       
   132 		TTime satelliteTime = iSatelliteInfo.SatelliteTime();
       
   133 		
       
   134 		TDateTime dt = satelliteTime.DateTime();
       
   135 		DRMLOG7(_L("CGPSTimeUpdater::RunL: satellite time = %02d-%02d-%04d, %02d:%02d:%02d"), dt.Day(), dt.Month(), dt.Year(), dt.Hour(), dt.Minute(), dt.Second());
       
   136 		    
       
   137 	    // If the time has not been received yet this function will leave and we re-issue the request from run error:    
       
   138 		iClock->ResetSecureTimeL( satelliteTime, 0 );    
       
   139 		
       
   140 		// Mark time as received
       
   141 		iTimeReceived = ETrue;
       
   142 		}
       
   143 		
       
   144     // if the call timed out try again		
       
   145     if( iStatus == KErrTimedOut ) 
       
   146 	    {
       
   147 	    // Request position update
       
   148 	    iPositioner.NotifyPositionUpdate(iSatelliteInfo, iStatus);
       
   149 	    SetActive();
       
   150 	    }	
       
   151 	else 	
       
   152 	    {    	
       
   153 	    iPositioner.Close();
       
   154         }
       
   155         
       
   156 	DRMLOG(_L("CGPSTimeUpdater::RunL <<"));
       
   157 	}
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CGPSTimeUpdater::DoCancel
       
   161 // Inherited from CActive
       
   162 // -----------------------------------------------------------------------------
       
   163 //	
       
   164 void CGPSTimeUpdater::DoCancel()
       
   165 	{
       
   166 	iPositioner.CancelRequest(EPositionerNotifyPositionUpdate);
       
   167 	}
       
   168 
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CGPSTimeUpdater::RunError
       
   172 // Inherited from CActive
       
   173 // -----------------------------------------------------------------------------
       
   174 //	
       
   175 TInt CGPSTimeUpdater::RunError( TInt /*aError*/ )
       
   176     {
       
   177     // Time received was invalid, wait for more updates
       
   178     iPositioner.NotifyPositionUpdate(iSatelliteInfo, iStatus);
       
   179     SetActive();
       
   180 	
       
   181     // ignore errors    
       
   182     return KErrNone;    
       
   183     }