|
1 /* |
|
2 * Copyright (c) 2007-2008 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 "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: Base class for online operations |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "emailtrace.h" |
|
21 #include "ipsplgheaders.h" |
|
22 |
|
23 |
|
24 // ---------------------------------------------------------------------------- |
|
25 // CIpsPlgOnlineOperation::~CIpsPlgOnlineOperation() |
|
26 // ---------------------------------------------------------------------------- |
|
27 // |
|
28 CIpsPlgOnlineOperation::~CIpsPlgOnlineOperation() |
|
29 { |
|
30 FUNC_LOG; |
|
31 Cancel(); |
|
32 delete iOperation; |
|
33 delete iBaseMtm; |
|
34 delete iMtmReg; |
|
35 } |
|
36 |
|
37 // ---------------------------------------------------------------------------- |
|
38 // CIpsPlgOnlineOperation::CIpsPlgOnlineOperation() |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 CIpsPlgOnlineOperation::CIpsPlgOnlineOperation( |
|
42 CMsvSession& aMsvSession, |
|
43 TInt aPriority, |
|
44 TRequestStatus& aObserverRequestStatus, |
|
45 CIpsPlgTimerOperation& aActivityTimer, |
|
46 TFSMailMsgId aFSMailBoxId, |
|
47 MFSMailRequestObserver& aFSOperationObserver, |
|
48 TInt aFSRequestId, |
|
49 TBool aSignallingAllowed ) |
|
50 : |
|
51 CIpsPlgBaseOperation( aMsvSession, aPriority, aObserverRequestStatus, |
|
52 aFSRequestId, aFSMailBoxId ), |
|
53 iActivityTimer( &aActivityTimer ), |
|
54 iBaseMtm( NULL ), |
|
55 iMtmReg( NULL ), |
|
56 iOperation( NULL ), |
|
57 iError( KErrNone ), |
|
58 iSignallingAllowed( aSignallingAllowed ), |
|
59 iFSOperationObserver( aFSOperationObserver ) |
|
60 { |
|
61 FUNC_LOG; |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // CIpsPlgOnlineOperation::BaseConstructL() |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 void CIpsPlgOnlineOperation::BaseConstructL(TUid aMtmType) |
|
69 { |
|
70 FUNC_LOG; |
|
71 // reset timer, if operation not completed after timer fires causes |
|
72 // disconnection |
|
73 if( iActivityTimer ) |
|
74 { |
|
75 iActivityTimer->ResetTimerOperation(); |
|
76 } |
|
77 |
|
78 iMtmReg = CClientMtmRegistry::NewL( iMsvSession ); |
|
79 |
|
80 iBaseMtm = iMtmReg->NewMtmL( aMtmType ); |
|
81 |
|
82 iObserverRequestStatus = KRequestPending; |
|
83 CActiveScheduler::Add(this); |
|
84 } |
|
85 |
|
86 // ---------------------------------------------------------------------------- |
|
87 // CIpsPlgOnlineOperation::DoCancel() |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 void CIpsPlgOnlineOperation::DoCancel() |
|
91 { |
|
92 FUNC_LOG; |
|
93 if( iOperation ) |
|
94 { |
|
95 iOperation->Cancel(); |
|
96 } |
|
97 CompleteObserver( KErrCancel ); |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // CIpsPlgOnlineOperation::RunL() |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 void CIpsPlgOnlineOperation::RunL() |
|
105 { |
|
106 FUNC_LOG; |
|
107 |
|
108 TInt err = KErrNone; |
|
109 TRAP( err, DoRunL() ); |
|
110 |
|
111 // Just end the operation, if something has gone wrong |
|
112 if ( err != KErrNone ) |
|
113 { |
|
114 CompleteObserver( err ); |
|
115 } |
|
116 else if ( iError != KErrNone ) |
|
117 { |
|
118 CompleteObserver( iError ); |
|
119 } |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // CIpsPlgOnlineOperation::RunError() |
|
124 // ---------------------------------------------------------------------------- |
|
125 // |
|
126 TInt CIpsPlgOnlineOperation::RunError( TInt aError ) |
|
127 { |
|
128 FUNC_LOG; |
|
129 CompleteObserver( aError ); |
|
130 return KErrNone; // RunError must return KErrNone to active sheduler. |
|
131 } |
|
132 |
|
133 // ---------------------------------------------------------------------------- |
|
134 // CIpsPlgOnlineOperation::CompleteObserver() |
|
135 // ---------------------------------------------------------------------------- |
|
136 // |
|
137 void CIpsPlgOnlineOperation::CompleteObserver( TInt aStatus ) |
|
138 { |
|
139 FUNC_LOG; |
|
140 TRequestStatus* status = &iObserverRequestStatus; |
|
141 if (status && status->Int() == KRequestPending) |
|
142 { |
|
143 |
|
144 SignalFSObserver( aStatus ); |
|
145 // removed checks to prevent unwanted disconnections |
|
146 //if we're connected, reset activitytimer. if not, there is no reason to. |
|
147 if( iActivityTimer ) |
|
148 { |
|
149 iActivityTimer->ResetTimerOperation(); |
|
150 } |
|
151 User::RequestComplete(status, aStatus); |
|
152 } |
|
153 } |
|
154 |
|
155 // ---------------------------------------------------------------------------- |
|
156 // CIpsPlgOnlineOperation::CompleteThis() |
|
157 // ---------------------------------------------------------------------------- |
|
158 // |
|
159 void CIpsPlgOnlineOperation::CompleteThis() |
|
160 { |
|
161 FUNC_LOG; |
|
162 |
|
163 TRequestStatus* status = &iStatus; |
|
164 User::RequestComplete(status, KErrNone); |
|
165 } |
|
166 |
|
167 // ---------------------------------------------------------------------------- |
|
168 // CIpsPlgOnlineOperation::InvokeClientMtmAsyncFunctionL() |
|
169 // ---------------------------------------------------------------------------- |
|
170 // |
|
171 void CIpsPlgOnlineOperation::InvokeClientMtmAsyncFunctionL( |
|
172 TInt aFunctionId, |
|
173 TMsvId aEntryId, |
|
174 TMsvId aContextId, |
|
175 const TDesC8& aParams) |
|
176 { |
|
177 FUNC_LOG; |
|
178 |
|
179 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
180 CleanupStack::PushL( sel ); |
|
181 sel->AppendL( aEntryId ); |
|
182 InvokeClientMtmAsyncFunctionL(aFunctionId, *sel, aContextId, aParams); |
|
183 CleanupStack::PopAndDestroy( sel ); |
|
184 } |
|
185 |
|
186 // ---------------------------------------------------------------------------- |
|
187 // CIpsPlgOnlineOperation::InvokeClientMtmAsyncFunctionL() |
|
188 // ---------------------------------------------------------------------------- |
|
189 // |
|
190 void CIpsPlgOnlineOperation::InvokeClientMtmAsyncFunctionL( |
|
191 TInt aFunctionId, |
|
192 const CMsvEntrySelection& aSel, |
|
193 TMsvId aContextId, |
|
194 const TDesC8& aParams) |
|
195 { |
|
196 FUNC_LOG; |
|
197 |
|
198 TMsvEntry tEntry; |
|
199 TMsvId service; |
|
200 if ( aSel.Count() ) |
|
201 { |
|
202 iMsvSession.GetEntry( aSel.At(0), service, tEntry ); |
|
203 } |
|
204 |
|
205 if( aContextId != tEntry.iServiceId ) |
|
206 { |
|
207 // Client context must be service for FetchL(). |
|
208 iBaseMtm->SwitchCurrentEntryL( tEntry.iServiceId ); |
|
209 } |
|
210 else |
|
211 { |
|
212 iBaseMtm->SwitchCurrentEntryL( aContextId ); |
|
213 } |
|
214 HBufC8* params = aParams.AllocLC(); |
|
215 TPtr8 ptr(params->Des()); |
|
216 // Delete previous operation if it exist |
|
217 if ( iOperation ) |
|
218 { |
|
219 delete iOperation; |
|
220 iOperation = NULL; |
|
221 } |
|
222 iOperation = iBaseMtm->InvokeAsyncFunctionL(aFunctionId, aSel, ptr, iStatus); |
|
223 CleanupStack::PopAndDestroy( params ); |
|
224 } |
|
225 |
|
226 // ---------------------------------------------------------------------------- |
|
227 // CIpsPlgOnlineOperation::SignalFSObserver() |
|
228 // ---------------------------------------------------------------------------- |
|
229 // |
|
230 void CIpsPlgOnlineOperation::SignalFSObserver( TInt aStatus ) |
|
231 { |
|
232 FUNC_LOG; |
|
233 if( iSignallingAllowed ) |
|
234 { |
|
235 TFSProgress prog; |
|
236 prog.iError = aStatus; |
|
237 // Initialize the progress data |
|
238 // it would be better to get fs progress from inherited class |
|
239 // by calling FSProgressL method?? |
|
240 if ( prog.iError == KErrCancel ) |
|
241 { |
|
242 prog.iProgressStatus = TFSProgress::EFSStatus_RequestCancelled; |
|
243 } |
|
244 else |
|
245 { |
|
246 prog.iProgressStatus = TFSProgress::EFSStatus_RequestComplete; |
|
247 } |
|
248 // At least in the attachment download, FS UI assumes that |
|
249 // the counter fields are greater than 0 |
|
250 prog.iMaxCount = 1; |
|
251 prog.iCounter = 1; |
|
252 |
|
253 |
|
254 //in case of autoconnect, we don't have valid observer |
|
255 if( &iFSOperationObserver ) |
|
256 { |
|
257 TRAP_IGNORE( iFSOperationObserver.RequestResponseL( prog, iFSRequestId ) ); |
|
258 } |
|
259 } |
|
260 } |
|
261 |
|
262 // ---------------------------------------------------------------------------- |
|
263 // ---------------------------------------------------------------------------- |
|
264 TInt CIpsPlgOnlineOperation::IpsOpType() const |
|
265 { |
|
266 FUNC_LOG; |
|
267 return EIpsOpTypeOnlineOp; |
|
268 } |
|
269 |