1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of CPushMtmAutoFetchOperation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "PushMtmAutoFetchOperation.h" |
|
23 #include "PushMtmFetchOperation.h" |
|
24 #include "PushContentHandlerPanic.h" |
|
25 #include "PushMtmLog.h" |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 /// Max retry. |
|
30 LOCAL_D const TInt KMaxTry = 2; |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 |
|
34 // --------------------------------------------------------- |
|
35 // CPushMtmAutoFetchOperation::NewL |
|
36 // --------------------------------------------------------- |
|
37 // |
|
38 CPushMtmAutoFetchOperation* CPushMtmAutoFetchOperation::NewL |
|
39 ( |
|
40 const TDesC& aRequestedUrl, |
|
41 TInt aTimeDelayInSec, |
|
42 TRequestStatus& aObserverRequestStatus |
|
43 ) |
|
44 { |
|
45 CPushMtmAutoFetchOperation* op = |
|
46 new (ELeave) CPushMtmAutoFetchOperation |
|
47 ( aTimeDelayInSec, aObserverRequestStatus ); |
|
48 CleanupStack::PushL( op ); |
|
49 op->ConstructL( aRequestedUrl ); |
|
50 CleanupStack::Pop(); // op |
|
51 return op; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // CPushMtmAutoFetchOperation::~CPushMtmAutoFetchOperation |
|
56 // --------------------------------------------------------- |
|
57 // |
|
58 CPushMtmAutoFetchOperation::~CPushMtmAutoFetchOperation() |
|
59 { |
|
60 Cancel(); |
|
61 delete iFetchOp; |
|
62 delete iRequestedUrl; |
|
63 iTimer.Close(); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------- |
|
67 // CPushMtmAutoFetchOperation::StartL |
|
68 // --------------------------------------------------------- |
|
69 // |
|
70 void CPushMtmAutoFetchOperation::StartL() |
|
71 { |
|
72 PUSHLOG_ENTERFN("CPushMtmAutoFetchOperation::StartL") |
|
73 |
|
74 Cancel(); |
|
75 |
|
76 iTry = 0; |
|
77 iState = EFetch; |
|
78 |
|
79 SetActive(); |
|
80 TRequestStatus* status = &iStatus; |
|
81 User::RequestComplete( status, KErrNone ); |
|
82 |
|
83 PUSHLOG_LEAVEFN("CPushMtmAutoFetchOperation::StartL") |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------- |
|
87 // CPushMtmAutoFetchOperation::CPushMtmAutoFetchOperation |
|
88 // --------------------------------------------------------- |
|
89 // |
|
90 CPushMtmAutoFetchOperation::CPushMtmAutoFetchOperation |
|
91 |
|
92 ( |
|
93 TInt aTimeDelayInSec, |
|
94 TRequestStatus& aObserverRequestStatus |
|
95 ) |
|
96 : CActive( EPriorityStandard ), |
|
97 iObserver( aObserverRequestStatus ), |
|
98 iState( EInit ), |
|
99 iTimeDelayInSec( aTimeDelayInSec ) |
|
100 { |
|
101 CActiveScheduler::Add( this ); |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------- |
|
105 // CPushMtmAutoFetchOperation::ConstructL |
|
106 // --------------------------------------------------------- |
|
107 // |
|
108 void CPushMtmAutoFetchOperation::ConstructL( const TDesC& aRequestedUrl ) |
|
109 { |
|
110 PUSHLOG_ENTERFN("CPushMtmAutoFetchOperation::ConstructL") |
|
111 |
|
112 iRequestedUrl = HBufC::NewMaxL( aRequestedUrl.Length() ); |
|
113 iRequestedUrl->Des().Copy( aRequestedUrl ); |
|
114 |
|
115 User::LeaveIfError( iTimer.CreateLocal() ); |
|
116 |
|
117 PUSHLOG_LEAVEFN("CPushMtmAutoFetchOperation::ConstructL") |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------- |
|
121 // CPushMtmAutoFetchOperation::FetchL |
|
122 // --------------------------------------------------------- |
|
123 // |
|
124 void CPushMtmAutoFetchOperation::FetchL() |
|
125 { |
|
126 PUSHLOG_ENTERFN("CPushMtmAutoFetchOperation::FetchL") |
|
127 |
|
128 delete iFetchOp; |
|
129 iFetchOp = NULL; |
|
130 iStatus = KRequestPending; |
|
131 SetActive(); |
|
132 iFetchOp = CPushMtmFetchOperation::NewL( *iRequestedUrl, iStatus ); |
|
133 PUSHLOG_WRITE(" Fetch op created") |
|
134 |
|
135 ++iTry; // Increase indicator. |
|
136 PUSHLOG_WRITE_FORMAT(" Try: %d",iTry) |
|
137 iFetchOp->StartL(); |
|
138 iState = ECheck; // Next state. |
|
139 PUSHLOG_WRITE(" Fetch op started") |
|
140 |
|
141 PUSHLOG_LEAVEFN("CPushMtmAutoFetchOperation::FetchL") |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CPushMtmAutoFetchOperation::DoCancel |
|
146 // --------------------------------------------------------- |
|
147 // |
|
148 void CPushMtmAutoFetchOperation::DoCancel() |
|
149 { |
|
150 if ( iFetchOp ) |
|
151 { |
|
152 iFetchOp->Cancel(); |
|
153 } |
|
154 |
|
155 iTimer.Cancel(); |
|
156 |
|
157 TRequestStatus* status = &iObserver; |
|
158 User::RequestComplete( status, KErrCancel ); |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------- |
|
162 // CPushMtmAutoFetchOperation::RunL |
|
163 // --------------------------------------------------------- |
|
164 // |
|
165 void CPushMtmAutoFetchOperation::RunL() |
|
166 { |
|
167 PUSHLOG_ENTERFN("CPushMtmAutoFetchOperation::RunL") |
|
168 |
|
169 __ASSERT_DEBUG( iState != EInit && iState != EDone, |
|
170 ContHandPanic( EPushContHandPanAutBadState ) ); |
|
171 |
|
172 switch ( iState ) |
|
173 { |
|
174 case EFetch: |
|
175 { |
|
176 PUSHLOG_WRITE(" EFetch") |
|
177 FetchL(); |
|
178 break; |
|
179 } |
|
180 |
|
181 case ECheck: |
|
182 { |
|
183 PUSHLOG_WRITE_FORMAT2(" ECheck: %d,%d",iStatus.Int(),iTry) |
|
184 if ( iStatus.Int() != KErrNone && iTry < KMaxTry ) |
|
185 { |
|
186 // Wait and Retry. |
|
187 iTimer.Cancel(); |
|
188 iStatus = KRequestPending; |
|
189 SetActive(); |
|
190 TTimeIntervalMicroSeconds32 delayInMSec = |
|
191 iTimeDelayInSec * 1000000; |
|
192 iTimer.After( iStatus, delayInMSec ); |
|
193 iState = EFetch; |
|
194 } |
|
195 else |
|
196 { |
|
197 // No error or no more trial allowed. |
|
198 iState = EDone; |
|
199 PUSHLOG_WRITE_FORMAT(" SignalObs: %d",iStatus.Int()); |
|
200 TRequestStatus* status = &iObserver; |
|
201 User::RequestComplete( status, iStatus.Int() ); |
|
202 } |
|
203 break; |
|
204 } |
|
205 |
|
206 default: |
|
207 { |
|
208 PUSHLOG_WRITE(" default") |
|
209 // JIC. |
|
210 iState = EDone; |
|
211 TRequestStatus* status = &iObserver; |
|
212 User::RequestComplete( status, KErrNone ); |
|
213 break; |
|
214 } |
|
215 } |
|
216 |
|
217 PUSHLOG_LEAVEFN("CPushMtmAutoFetchOperation::RunL") |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------- |
|
221 // CPushMtmAutoFetchOperation::RunError |
|
222 // --------------------------------------------------------- |
|
223 // |
|
224 TInt CPushMtmAutoFetchOperation::RunError( TInt aError ) |
|
225 { |
|
226 PUSHLOG_WRITE_FORMAT("CPushMtmAutoFetchOperation::RunError <%d>",aError); |
|
227 |
|
228 // Signal the observer that a leave has occured. |
|
229 TRequestStatus* status = &iObserver; |
|
230 User::RequestComplete( status, aError ); |
|
231 |
|
232 return KErrNone; |
|
233 } |
|
234 |
|
235 // End of file. |
|