23 #include "GPSWatcher.h" |
23 #include "GPSWatcher.h" |
24 #include "GPSTimeUpdater.h" |
24 #include "GPSTimeUpdater.h" |
25 #include "DRMClock.h" |
25 #include "DRMClock.h" |
26 #include "drmlog.h" |
26 #include "drmlog.h" |
27 |
27 |
|
28 // Wait time in microseconds: wait 5 minutes |
|
29 const TInt KGpsDefaultWaitTime = 300000000; |
|
30 const TInt KMaxRetryCounter = 20; |
28 |
31 |
29 // ============================ MEMBER FUNCTIONS =============================== |
32 // ============================ MEMBER FUNCTIONS =============================== |
30 |
33 |
31 |
34 |
32 // ----------------------------------------------------------------------------- |
35 // ----------------------------------------------------------------------------- |
34 // C++ default constructor can NOT contain any code, that |
37 // C++ default constructor can NOT contain any code, that |
35 // might leave. |
38 // might leave. |
36 // ----------------------------------------------------------------------------- |
39 // ----------------------------------------------------------------------------- |
37 // |
40 // |
38 CGPSWatcher::CGPSWatcher( CDRMClock* aClock ) : |
41 CGPSWatcher::CGPSWatcher( CDRMClock* aClock ) : |
39 CActive(EPriorityHigh), |
42 CTimer(EPriorityHigh), |
40 iClock( aClock ) |
43 iClock( aClock ), |
|
44 iRetryCounter( 0 ) |
41 { |
45 { |
42 CActiveScheduler::Add(this); |
46 CActiveScheduler::Add(this); |
43 } |
47 } |
44 |
48 |
45 // ----------------------------------------------------------------------------- |
49 // ----------------------------------------------------------------------------- |
78 // Symbian 2nd phase constructor can leave. |
82 // Symbian 2nd phase constructor can leave. |
79 // ----------------------------------------------------------------------------- |
83 // ----------------------------------------------------------------------------- |
80 // |
84 // |
81 void CGPSWatcher::ConstructL() |
85 void CGPSWatcher::ConstructL() |
82 { |
86 { |
|
87 CTimer::ConstructL(); |
|
88 |
83 User::LeaveIfError(iPosServer.Connect()); |
89 User::LeaveIfError(iPosServer.Connect()); |
84 |
90 |
85 // Immediately subscribe for module status events |
91 // Immediately subscribe for module status events |
86 iStatusEvent.SetRequestedEvents(TPositionModuleStatusEventBase::EEventDeviceStatus); |
92 iStatusEvent.SetRequestedEvents(TPositionModuleStatusEventBase::EEventDeviceStatus); |
87 Subscribe(); |
93 Subscribe(); |
106 // Inherited from CActive |
112 // Inherited from CActive |
107 // ----------------------------------------------------------------------------- |
113 // ----------------------------------------------------------------------------- |
108 // |
114 // |
109 void CGPSWatcher::RunL() |
115 void CGPSWatcher::RunL() |
110 { |
116 { |
|
117 // If there are errors just leave and stop watching: |
|
118 DRMLOG2(_L("CGPSWatcher::RunL: error: '%d'"), iStatus.Int()); |
|
119 |
111 // If we already updated the time: |
120 // If we already updated the time: |
112 if( iTimeUpdater && iTimeUpdater->TimeReceived() ) |
121 if( iTimeUpdater && iTimeUpdater->TimeReceived() ) |
113 { |
122 { |
114 DRMLOG( _L("CGPSWatcher::RunL: time updater exists, time received, deleting")); |
123 DRMLOG( _L("CGPSWatcher::RunL: time updater exists, time received, deleting")); |
115 iClock->Notify( CDRMClock::ENotifyGPSTimeReceived ); |
124 iClock->Notify( CDRMClock::ENotifyGPSTimeReceived ); |
116 DRMLOG( _L("CGPSWatcher::RunL: object deleted, returning")); |
125 DRMLOG( _L("CGPSWatcher::RunL: object deleted, returning")); |
117 return; |
126 return; |
118 } |
127 } |
|
128 |
|
129 // The server was killed: |
|
130 if( iStatus.Int() == KErrServerTerminated ) |
|
131 { |
|
132 if( iRetryCounter > KMaxRetryCounter ) |
|
133 { |
|
134 DRMLOG( _L("CGPSWatcher::RunL: Maximum retries reached, stopping watcher.") ); |
|
135 iClock->Notify( CDRMClock::ENotifyGPSTimeReceived ); |
|
136 return; |
|
137 } |
|
138 // If there are errors just leave and stop watching: |
|
139 DRMLOG2(_L("CGPSWatcher::RunL: server terminated, waiting '%d' microseconds"), KGpsDefaultWaitTime); |
|
140 After( TTimeIntervalMicroSeconds32(KGpsDefaultWaitTime) ); |
|
141 return; |
|
142 } |
119 |
143 |
120 Subscribe(); |
144 Subscribe(); |
121 TPositionModuleStatusEventBase::TModuleEvent occurredEvents = iStatusEvent.OccurredEvents(); |
145 TPositionModuleStatusEventBase::TModuleEvent occurredEvents = iStatusEvent.OccurredEvents(); |
122 DRMLOG2(_L("CGPSWatcher::RunL: occurredEvents = 0x%X"), occurredEvents); |
146 DRMLOG2(_L("CGPSWatcher::RunL: occurredEvents = 0x%X"), occurredEvents); |
|
147 |
123 |
148 |
124 // If time updater is not running, check module statuses |
149 // If time updater is not running, check module statuses |
125 if(!iTimeUpdater) |
150 if(!iTimeUpdater) |
126 CheckModules(); |
151 CheckModules(); |
127 } |
152 } |