|
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: Container of the one outgoing transaction handler |
|
15 * It process one handler until it is completed |
|
16 * canceled or some error ocures. |
|
17 * Its completion is signaled to the observer |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include <e32std.h> |
|
25 #include "CPEngOutGoingTransContainer.h" |
|
26 #include "MPEngOutgoingTransactionHandler.h" |
|
27 #include "MPEngPureDataHandler.h" |
|
28 #include "MPEngHandlerSendData.h" |
|
29 |
|
30 // Debug prints |
|
31 #include "PresenceDebugPrint.h" |
|
32 |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CPEngOutGoingTransContainer::CPEngOutGoingTransContainer |
|
38 // C++ default constructor can NOT contain any code, that |
|
39 // might leave. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CPEngOutGoingTransContainer::CPEngOutGoingTransContainer( |
|
43 MPEngHandlerSendData& aRequestHandler, |
|
44 MPEngPureDataHandler& aPureDataHandler, |
|
45 RPointerArray<MPEngOutgoingTransactionHandler>& |
|
46 aTransactionHandlersArray ) |
|
47 : CActive( CActive::EPriorityStandard ), |
|
48 iPureDataHandler( aPureDataHandler ), |
|
49 iRequestHandler( aRequestHandler ), |
|
50 iNewTransactionHandlers( aTransactionHandlersArray ) |
|
51 |
|
52 { |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CPEngOutGoingTransContainer::ConstructL |
|
57 // Symbian 2nd phase constructor can leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 void CPEngOutGoingTransContainer::ConstructL() |
|
61 { |
|
62 // add active object to the active scheduler |
|
63 CActiveScheduler::Add( this ); |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CPEngOutGoingTransContainer::NewL |
|
68 // Two-phased constructor. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CPEngOutGoingTransContainer* CPEngOutGoingTransContainer::NewL( |
|
72 MPEngHandlerSendData& aRequestHandler, |
|
73 MPEngPureDataHandler& aPureDataHandler, |
|
74 RPointerArray<MPEngOutgoingTransactionHandler>& |
|
75 aTransactionHandlersArray ) |
|
76 { |
|
77 CPEngOutGoingTransContainer* self = NewLC( aRequestHandler, |
|
78 aPureDataHandler, |
|
79 aTransactionHandlersArray ); |
|
80 |
|
81 CleanupStack::Pop( self ); |
|
82 |
|
83 return self; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CPEngOutGoingTransContainer::NewL |
|
88 // Two-phased constructor. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CPEngOutGoingTransContainer* CPEngOutGoingTransContainer::NewLC( |
|
92 MPEngHandlerSendData& aRequestHandler, |
|
93 MPEngPureDataHandler& aPureDataHandler, |
|
94 RPointerArray<MPEngOutgoingTransactionHandler>& |
|
95 aTransactionHandlersArray ) |
|
96 { |
|
97 CPEngOutGoingTransContainer* self = |
|
98 new( ELeave ) CPEngOutGoingTransContainer( |
|
99 aRequestHandler, |
|
100 aPureDataHandler, |
|
101 aTransactionHandlersArray ); |
|
102 |
|
103 CleanupStack::PushL( self ); |
|
104 self->ConstructL(); |
|
105 return self; |
|
106 } |
|
107 |
|
108 |
|
109 // Destructor |
|
110 CPEngOutGoingTransContainer::~CPEngOutGoingTransContainer() |
|
111 { |
|
112 PENG_DP( D_PENG_LIT( "CPEngOutGoingTransContainer::~CPEngOutGoingTransContainer()" ) ); |
|
113 Cancel(); |
|
114 delete iTransactionHandler; |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // -------- Function from the CActive ------------------------------------------ |
|
119 // ----------------------------------------------------------------------------- |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CPEngOutGoingTransContainer::StartTransaction |
|
123 // Start performing transaction |
|
124 // (other items were commented in a header). |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void CPEngOutGoingTransContainer::StartTransactionL( |
|
128 MPEngOutgoingTransactionHandler* aOutgoingTransaction ) |
|
129 { |
|
130 PENG_DP( D_PENG_LIT( "CPEngOutGoingTransContainer::StartTransactionL()" ) ); |
|
131 TPtr8 outgoingBuffer( iPureDataHandler.TransferBufferL() ); |
|
132 aOutgoingTransaction->RequestL( outgoingBuffer ); |
|
133 iTransactionId = iPureDataHandler.SendDataL( iStatus ); |
|
134 SetActive(); |
|
135 // take ownership of transaction |
|
136 iTransactionHandler = aOutgoingTransaction; |
|
137 } |
|
138 |
|
139 // ============================================================================= |
|
140 // ============== Function from the CActive ==================================== |
|
141 // ============================================================================= |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CPEngOutGoingTransContainer::RunL |
|
145 // Handles an active object’s request completion event. |
|
146 // (other items were commented in a header). |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CPEngOutGoingTransContainer::RunL() |
|
150 { |
|
151 // what is necessary depends how request went |
|
152 TInt errCode ( iStatus.Int() ); |
|
153 PENG_DP( D_PENG_LIT( "CPEngOutGoingTransContainer::RunL() - result: %d" ), |
|
154 errCode ); |
|
155 |
|
156 switch ( errCode ) |
|
157 { |
|
158 case KErrNone: |
|
159 { |
|
160 HBufC8* response = iPureDataHandler.ResponseL( iTransactionId ); |
|
161 User::LeaveIfNull( response ); |
|
162 CleanupStack::PushL( response ); |
|
163 TBool last ( iRequestHandler.LastRunningTransaction() ); |
|
164 if ( last ) |
|
165 { |
|
166 iTransactionHandler->LastRunningTransactionHandler(); |
|
167 } |
|
168 // TO-DO do processing asynchronous |
|
169 iTransactionHandler->ProcessResponseL( *response, iStatus ); |
|
170 CleanupStack::PopAndDestroy( response ); // response |
|
171 |
|
172 iTransactionHandler->NewTransactionHandlersL( |
|
173 iNewTransactionHandlers ); |
|
174 if ( iNewTransactionHandlers.Count() != 0 ) |
|
175 { |
|
176 // new transaction handlers were created, inform RequestHandler |
|
177 iRequestHandler.CreateNewContainersRunThemL(); |
|
178 } |
|
179 |
|
180 if ( !iTransactionHandler->TransactionCompleted() ) |
|
181 { |
|
182 // we are not done, just run another round |
|
183 StartTransactionL( iTransactionHandler ); |
|
184 return; |
|
185 } |
|
186 break; |
|
187 } |
|
188 |
|
189 default: |
|
190 { |
|
191 // transfer error code |
|
192 iTransactionHandler->ReleaseHandler(); |
|
193 } |
|
194 } |
|
195 // Get status and complete container, status ownership transfered |
|
196 CPEngTransactionStatus* status = |
|
197 iTransactionHandler->TransactionResult(); |
|
198 iRequestHandler.CompleteTransContainer( this, status, errCode ); |
|
199 PENG_DP( D_PENG_LIT( "CPEngOutGoingTransContainer::RunL() - End" ) ); |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CPEngOutGoingTransContainer::RunError |
|
204 // Handles a leave occurring in the request completion event handler RunL() |
|
205 // implementation should return KErrNone, if it handles the leave |
|
206 // (other items were commented in a header). |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 TInt CPEngOutGoingTransContainer::RunError( |
|
210 TInt aError ) |
|
211 { |
|
212 // release handler and complete container |
|
213 iTransactionHandler->ReleaseHandler(); |
|
214 // Get status and complete container, status ownership transfered |
|
215 CPEngTransactionStatus* status = |
|
216 iTransactionHandler->TransactionResult(); |
|
217 iRequestHandler.CompleteTransContainer( this, status, aError ); |
|
218 return KErrNone; |
|
219 } |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // CPEngOutGoingTransContainer::DoCancel |
|
223 // Implements cancellation of an outstanding request. |
|
224 // (other items were commented in a header). |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 void CPEngOutGoingTransContainer::DoCancel() |
|
228 { |
|
229 PENG_DP( D_PENG_LIT( "CPEngOutGoingTransContainer::DoCancel()" ) ); |
|
230 // request was canceled, cancel log in, update state and complete RMessage |
|
231 iPureDataHandler.CancelSending( iTransactionId ); |
|
232 iTransactionHandler->ReleaseHandler(); |
|
233 // Container is not removed here |
|
234 } |
|
235 |
|
236 // End of File |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |