|
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 "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: Request Handler to update data to the network server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPEngHandlerSendData.h" |
|
22 #include <e32std.h> |
|
23 |
|
24 #include "MPEngRequestHandlerObserver.h" |
|
25 #include "CPEngOutGoingTransContainer.h" |
|
26 #include "MPEngOutgoingTransactionHandler.h" |
|
27 #include "MPEngSubSession.h" |
|
28 #include "PEngWVPresenceErrors2.h" |
|
29 #include "CPEngTransactionStatus.h" |
|
30 |
|
31 // Debug prints |
|
32 #include "PresenceDebugPrint.h" |
|
33 |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CPEngHandlerSendData::CPEngHandlerSendData |
|
39 // C++ default constructor can NOT contain any code, that |
|
40 // might leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CPEngHandlerSendData::CPEngHandlerSendData( |
|
44 MPEngRequestHandlerObserver& aRequestHandlerObserver, |
|
45 MPEngPureDataHandler& aPureDataHandler, |
|
46 MPEngSubSession& aServSubSession, |
|
47 const RPEngMessage& aMessage, |
|
48 TInt32 aSessionId, |
|
49 TInt32 aSubSessionId ) |
|
50 : iRequestHandlerObserver( aRequestHandlerObserver ), |
|
51 iPureDataHandler( aPureDataHandler ), |
|
52 iServSubSession( aServSubSession ), |
|
53 iSessionId( aSessionId ), |
|
54 iSubSessionId( aSubSessionId ), |
|
55 iFunction( aMessage.Function() ) |
|
56 { |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CPEngHandlerSendData::ConstructHandlerFromTransactionHandlersL |
|
61 // Symbian 2nd phase constructor can leave. |
|
62 // Construct Send Data handler from the passed array of the outgoing Transaction handlers |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CPEngHandlerSendData::ConstructL( |
|
66 RPointerArray<MPEngOutgoingTransactionHandler>& aTransactions ) |
|
67 { |
|
68 // copy handlers from the given array, but just their pointers, it takes ownership |
|
69 for ( TInt x( aTransactions.Count() - 1 ) ; x >= 0 ; x-- ) |
|
70 { |
|
71 User::LeaveIfError( iOutgoingTransactionHandlers.Append( aTransactions[ x ] ) ); |
|
72 aTransactions.Remove( x ); |
|
73 } |
|
74 iTransactionStatus = CPEngTransactionStatus::NewL(); |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CPEngHandlerSendData::NewHandlerFromTransactionHandlersLC |
|
79 // Two-phased constructor. which creates Send Data handler from the passed array of the |
|
80 // Transaction handlers, no reading of the storage IDs from the client side is needed then |
|
81 // are readed from the client RPEngMessage |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CPEngHandlerSendData* CPEngHandlerSendData::NewLC( |
|
85 MPEngRequestHandlerObserver& aRequestHandlerObserver, |
|
86 MPEngPureDataHandler& aPureDataHandler, |
|
87 MPEngSubSession& aServSubSession, |
|
88 const RPEngMessage& aMessage, |
|
89 RPointerArray<MPEngOutgoingTransactionHandler>& aTransactions, |
|
90 TInt32 aSessionId, |
|
91 TInt32 aSubSessionId ) |
|
92 { |
|
93 CPEngHandlerSendData* self = new( ELeave ) CPEngHandlerSendData( |
|
94 aRequestHandlerObserver, |
|
95 aPureDataHandler, |
|
96 aServSubSession, |
|
97 aMessage, |
|
98 aSessionId, |
|
99 aSubSessionId ); |
|
100 |
|
101 CleanupStack::PushL( self ); |
|
102 self->ConstructL( aTransactions ); |
|
103 |
|
104 return self; |
|
105 } |
|
106 |
|
107 // Destructor |
|
108 CPEngHandlerSendData::~CPEngHandlerSendData() |
|
109 { |
|
110 PENG_DP( D_PENG_LIT( "CPEngHandlerSendData::~CPEngHandlerSendData" ) ); |
|
111 // cancel and delete all transaction containers |
|
112 iTrasactionContainersArray.ResetAndDestroy(); |
|
113 iOutgoingTransactionHandlers.ResetAndDestroy(); |
|
114 delete iTransactionStatus; |
|
115 |
|
116 // complete message with KErrCancel, just in case it was not completed yet |
|
117 iMessage.Complete( KErrCancel ); |
|
118 // remove handler from the CSP Session manager |
|
119 iRequestHandlerObserver.CompleteRequestHandler( this ); |
|
120 PENG_DP( D_PENG_LIT( "CPEngHandlerSendData::~CPEngHandlerSendData - End" ) ); |
|
121 } |
|
122 |
|
123 |
|
124 ///////////////////////////////////////////////////////////////////////////////// |
|
125 // =============== New Functions of the MPEngRequestHandler class ============== |
|
126 ///////////////////////////////////////////////////////////////////////////////// |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CPEngHandlerSendData::StartHandlerL |
|
130 // (other items were commented in a header). |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CPEngHandlerSendData::StartHandlerL( ) |
|
134 { |
|
135 PENG_DP( D_PENG_LIT( "CPEngHandlerSendData::StartHandlerL" ) ); |
|
136 // create containers and run them |
|
137 CreateNewContainersRunThemL(); |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CPEngHandlerSendData::SessionId |
|
142 // (other items were commented in a header). |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 TInt32 CPEngHandlerSendData::SessionId( ) const |
|
146 { |
|
147 return iSessionId; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CPEngHandlerSendData::SubSessionId |
|
152 // (other items were commented in a header). |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 TInt CPEngHandlerSendData::SubSessionId( ) const |
|
156 { |
|
157 return iSubSessionId; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CPEngHandlerSendData::RequestFunction |
|
162 // (other items were commented in a header). |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 TInt CPEngHandlerSendData::RequestFunction( ) const |
|
166 { |
|
167 return iFunction; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CPEngHandlerSendData::CancelRequest |
|
172 // (other items were commented in a header). |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void CPEngHandlerSendData::CancelRequestD( ) |
|
176 { |
|
177 PENG_DP( D_PENG_LIT( "CPEngHandlerSendData::CancelRequest" ) ); |
|
178 // delete containers and complete message |
|
179 iTrasactionContainersArray.ResetAndDestroy(); |
|
180 iMessage.Complete( KErrCancel ); |
|
181 // now we are done and handler can be deleted |
|
182 delete this; |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CPEngHandlerSendData::SetMessage |
|
187 // (other items were commented in a header). |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CPEngHandlerSendData::SetMessage( |
|
191 const RPEngMessage& aMessage ) |
|
192 { |
|
193 iMessage = aMessage; |
|
194 } |
|
195 |
|
196 |
|
197 ///////////////////////////////////////////////////////////////////////////////// |
|
198 // =============== New Functions of the MPEngHandlerSendData class ============= |
|
199 ///////////////////////////////////////////////////////////////////////////////// |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CPEngHandlerSendData::CompleteRequestD |
|
203 // Complete request handlers, store request result and delete itself |
|
204 // (other items were commented in a header). |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CPEngHandlerSendData::CompleteRequestD() |
|
208 { |
|
209 PENG_DP( D_PENG_LIT( "CPEngHandlerSendData::CompleteRequestL" ) ); |
|
210 // get transaction result and store it in SubSession |
|
211 HBufC8* volatile reqResult = NULL; |
|
212 TRAPD( e, reqResult = iTransactionStatus->PackResultsL() ); |
|
213 // if error complete with error |
|
214 if ( e != KErrNone ) |
|
215 { |
|
216 iMessage.Complete( e ); |
|
217 delete this; |
|
218 return; |
|
219 } |
|
220 iServSubSession.StoreRequestResponse( reqResult ); |
|
221 // complete RPEngMessage and delete itself |
|
222 iMessage.Complete( reqResult->Length() ); |
|
223 delete this; |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CPEngHandlerSendData::CreateContainersAndRunThemL |
|
228 // go through all transaction handlers in iOutgoingTransactionHandlers |
|
229 // array, create for each of then container with given Transaction handler |
|
230 // and start it |
|
231 // (other items were commented in a header). |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void CPEngHandlerSendData::CreateNewContainersRunThemL() |
|
235 { |
|
236 PENG_DP( D_PENG_LIT( "CPEngHandlerSendData::CreateNewContainersRunThemL" ) ); |
|
237 |
|
238 // we have to go through array from the end, created |
|
239 // transaction containers are taking owner ship of the transaction |
|
240 // handler from the array, so they have to be removed from there |
|
241 for ( TInt i( iOutgoingTransactionHandlers.Count() - 1 ) ; i >= 0 ; i-- ) |
|
242 { |
|
243 CPEngOutGoingTransContainer* newContainer = CPEngOutGoingTransContainer::NewLC( |
|
244 *this, |
|
245 iPureDataHandler, |
|
246 iOutgoingTransactionHandlers ); |
|
247 newContainer->StartTransactionL( iOutgoingTransactionHandlers[ i ] ); |
|
248 iOutgoingTransactionHandlers.Remove( i ); |
|
249 // remove trans. handler from the array since its ownership was |
|
250 // taken by transaction container |
|
251 iTrasactionContainersArray.AppendL( newContainer ); |
|
252 CleanupStack::Pop( newContainer ); // newContainer |
|
253 } |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CPEngHandlerSendData::CompleteTransContainer |
|
258 // Remove transaction container from the array of containers |
|
259 // (other items were commented in a header). |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 void CPEngHandlerSendData::CompleteTransContainer( |
|
263 CPEngOutGoingTransContainer* aTransContainer, |
|
264 CPEngTransactionStatus* aTransactionStatus, |
|
265 TInt aErrCode ) |
|
266 { |
|
267 PENG_DP( D_PENG_LIT( "CPEngHandlerSendData::CompleteTransContainer" ) ); |
|
268 |
|
269 // inport transaction status |
|
270 iTransactionStatus->ImportStatusFrom( *aTransactionStatus ); |
|
271 |
|
272 // find transaction and remove it from the list |
|
273 TInt index ( iTrasactionContainersArray.Find( aTransContainer ) ); |
|
274 if ( index != KErrNotFound ) |
|
275 { |
|
276 if ( KErrCancel != aErrCode && aErrCode != KPEngNwErrForcedLogout ) |
|
277 { |
|
278 //Skip the deletion if aErrCode is KErrCancel |
|
279 delete iTrasactionContainersArray[ index ]; |
|
280 } |
|
281 iTrasactionContainersArray.Remove( index ); |
|
282 } |
|
283 else |
|
284 { |
|
285 // if container was not found in array, complete it anyway, |
|
286 // however, it should not happen |
|
287 delete aTransContainer; |
|
288 } |
|
289 |
|
290 // end if there was some Symbian error |
|
291 if ( aErrCode != KErrNone ) |
|
292 { |
|
293 // cancel all active transaction |
|
294 iTrasactionContainersArray.ResetAndDestroy(); |
|
295 iMessage.Complete( aErrCode ); |
|
296 delete this; |
|
297 } |
|
298 else if ( iTrasactionContainersArray.Count() == 0 ) |
|
299 { |
|
300 // we can safely call complete, even this function was |
|
301 // most likely called from the destructor of the |
|
302 // Transaction Container, it was already removed from the array |
|
303 CompleteRequestD(); |
|
304 } |
|
305 PENG_DP( D_PENG_LIT( "CPEngHandlerSendData::CompleteTransContainer - End" ) ); |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // CPEngHandlerSendData::LastRunningTransaction |
|
310 // Check how many running transactions is still there, |
|
311 // and if calling one is last, return ETrue |
|
312 // (other items were commented in a header). |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 TBool CPEngHandlerSendData::LastRunningTransaction( ) |
|
316 { |
|
317 return ( 1 == iTrasactionContainersArray.Count() ); |
|
318 } |
|
319 |
|
320 // End of File |