28 |
28 |
29 #include "emailtrace.h" |
29 #include "emailtrace.h" |
30 #include "emailservermonitorutilities.h" |
30 #include "emailservermonitorutilities.h" |
31 #include "emailservermonitor.h" |
31 #include "emailservermonitor.h" |
32 #include "emailservermonitorconst.h" |
32 #include "emailservermonitorconst.h" |
|
33 #include "emailshutter.h" |
33 |
34 |
34 const TUint KOneSecondInMicroSeconds = 1000000; |
35 const TUint KOneSecondInMicroSeconds = 1000000; |
35 |
36 |
|
37 const TInt KExternalServiceRestartDelay = 5 * KOneSecondInMicroSeconds; |
|
38 const TInt KInstallatioFinishedFlagSettingDelay = 2 * KOneSecondInMicroSeconds; |
36 |
39 |
37 // ======== MEMBER FUNCTION DEFINITIONS ======== |
40 // ======== MEMBER FUNCTION DEFINITIONS ======== |
38 |
41 |
39 /** |
42 /** |
40 * Two-phased class constructor. |
43 * Two-phased class constructor. |
66 { |
69 { |
67 FUNC_LOG; |
70 FUNC_LOG; |
68 iApaLsSession.Close(); |
71 iApaLsSession.Close(); |
69 iProcess.Close(); |
72 iProcess.Close(); |
70 iDelayTimer.Close(); |
73 iDelayTimer.Close(); |
|
74 if( iExternalServiceRestartTimer ) |
|
75 { |
|
76 delete iExternalServiceRestartTimer; |
|
77 iExternalServiceRestartTimer = NULL; |
|
78 } |
71 } |
79 } |
72 |
80 |
73 /** |
81 /** |
74 * Default class constructor. |
82 * Default class constructor. |
75 * Only NewL can be called |
83 * Only NewL can be called |
76 */ |
84 */ |
77 CEmailServerMonitor::CEmailServerMonitor() |
85 CEmailServerMonitor::CEmailServerMonitor() |
78 : CActive( EPriorityStandard ), iState( EEsmStateIdle ), iRestarts( 0 ) |
86 : CActive( EPriorityStandard ), |
|
87 iState( EEsmStateIdle ), |
|
88 iRestarts( 0 ), |
|
89 iShutter( NULL ), |
|
90 iExternalServicesRestartState( EEsmEsrStateRestartNotNeeded ) |
79 { |
91 { |
80 FUNC_LOG; |
92 FUNC_LOG; |
81 } |
93 } |
82 |
94 |
83 /** |
95 /** |
98 void CEmailServerMonitor::Start() |
110 void CEmailServerMonitor::Start() |
99 { |
111 { |
100 FUNC_LOG; |
112 FUNC_LOG; |
101 iLastRestartTime.UniversalTime(); |
113 iLastRestartTime.UniversalTime(); |
102 |
114 |
103 // Set initializing state and complete self |
115 // Initiate delayed restart and set correct state |
104 // -> functionality will continue in RunL |
116 InitiateDelayedRestart(); |
105 iState = EEsmStateInitializing; |
117 iState = EEsmStateInitializing; |
106 TRequestStatus* status = &iStatus; |
118 } |
107 SetActive(); |
119 |
108 User::RequestComplete( status, KErrNone ); |
120 /** |
|
121 * Set pointer to shutter. |
|
122 */ |
|
123 void CEmailServerMonitor::SetShutter( CEmailShutter* aShutter ) |
|
124 { |
|
125 iShutter = aShutter; |
|
126 } |
|
127 |
|
128 /** |
|
129 * Set Restart External Services flag. |
|
130 */ |
|
131 void CEmailServerMonitor::SetRestartExternalServicesFlag( TBool aRestartFlag /*= ETrue*/ ) |
|
132 { |
|
133 if( aRestartFlag ) |
|
134 { |
|
135 iExternalServicesRestartState = EEsmEsrStateRestartNeeded; |
|
136 } |
|
137 else |
|
138 { |
|
139 iExternalServicesRestartState = EEsmEsrStateRestartNotNeeded; |
|
140 } |
|
141 } |
|
142 |
|
143 /** |
|
144 * Called when external service restart timer has expired, so it's time to do |
|
145 * some starting |
|
146 */ |
|
147 void CEmailServerMonitor::TimerEventL( CEmailServerMonitorTimer* /*aTriggeredTimer*/ ) |
|
148 { |
|
149 // Shutter is used in all cases, so verify it exists at the beginning |
|
150 if( iShutter ) |
|
151 { |
|
152 switch( iExternalServicesRestartState ) |
|
153 { |
|
154 case EEsmEsrStateRestartInitiated: |
|
155 { |
|
156 // Restart external services and change state |
|
157 iShutter->RestartServicesAfterInstallation(); |
|
158 iExternalServicesRestartState = EEsmEsrStateFirstServiceRestarted; |
|
159 |
|
160 // Restart the timer to set the installation finished flag |
|
161 // with some more delay |
|
162 iExternalServiceRestartTimer->Start( KInstallatioFinishedFlagSettingDelay ); |
|
163 } |
|
164 break; |
|
165 |
|
166 case EEsmEsrStateFirstServiceRestarted: |
|
167 { |
|
168 // Set the installation finished flag and clear state variable |
|
169 iShutter->SetPsKeyInstallationFinished(); |
|
170 iExternalServicesRestartState = EEsmEsrStateRestartNotNeeded; |
|
171 } |
|
172 break; |
|
173 |
|
174 default: |
|
175 // Do nothing, shouldn't happen |
|
176 break; |
|
177 } |
|
178 } |
109 } |
179 } |
110 |
180 |
111 /** |
181 /** |
112 * Start Email Server and start monitoring it |
182 * Start Email Server and start monitoring it |
113 */ |
183 */ |
239 { |
313 { |
240 // If start failed initiate new delayed restart |
314 // If start failed initiate new delayed restart |
241 INFO( "Initiating new delayed restart" ); |
315 INFO( "Initiating new delayed restart" ); |
242 InitiateDelayedRestart(); |
316 InitiateDelayedRestart(); |
243 } |
317 } |
|
318 // If Email server is up and running and iExternalServicesRestartState |
|
319 // flag is set, initiate delayed restart of external services |
|
320 else if( iExternalServicesRestartState == EEsmEsrStateRestartNeeded ) |
|
321 { |
|
322 // Once restart is initiated, update the state |
|
323 iExternalServicesRestartState = EEsmEsrStateRestartInitiated; |
|
324 |
|
325 // Create the timer and start it |
|
326 TInt timerError = KErrNone; |
|
327 if( !iExternalServiceRestartTimer ) |
|
328 { |
|
329 TRAP( timerError, iExternalServiceRestartTimer = CEmailServerMonitorTimer::NewL( this ) ); |
|
330 } |
|
331 if( timerError == KErrNone ) |
|
332 { |
|
333 iExternalServiceRestartTimer->Start( KExternalServiceRestartDelay ); |
|
334 } |
|
335 } |
244 } |
336 } |
245 break; |
337 break; |
246 |
338 |
247 case EEsmStateIdle: |
339 case EEsmStateIdle: |
248 default: |
340 default: |