|
1 /* |
|
2 * Copyright (c) 2002-2006 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 #include "senhostlettransportplugin.h" |
|
29 |
|
30 #include <SenServiceConnection.h> // errorcode constants, like KErrSenNoEndpoint |
|
31 |
|
32 #include "msenprovider.h" |
|
33 #include "senhostletrequest.h" // internal Provider\inc |
|
34 #include "senhostletresponse.h" // internal Provider\inc |
|
35 |
|
36 #include "senidentifier.h" // internal Utils\inc |
|
37 #include "senidentifier.h" // internal Utils\inc |
|
38 #include "sendebug.h" // internal Utils\inc - debugging MACROs |
|
39 |
|
40 #include "senprovider.h" // internal Framework\inc |
|
41 #include "sensyncrequester.h" // internal Framework\inc |
|
42 #include <SenTransportProperties.h> // internal Framework\inc |
|
43 #include "senservicesession.h" // internal Framework\inc |
|
44 #include "msentransport.h" // internal Framework\inc |
|
45 #include "msenremotehostlet.h" // internal Framework\inc |
|
46 |
|
47 #include "msencoreservicemanager.h" // internal: Core\inc |
|
48 |
|
49 #include "senchunk.h" // Internal Utils\inc |
|
50 #include "senlogger.h" // internal Logger\inc - logging MACROs |
|
51 |
|
52 #include "msenservicesession.h" |
|
53 #include "msenremoteserviceconsumer.h" |
|
54 |
|
55 #include "senlayeredtransportproperties.h" |
|
56 |
|
57 |
|
58 #include "senvtcptransportproperties.h" |
|
59 #include "SenHttpTransportProperties.h" |
|
60 |
|
61 namespace |
|
62 { |
|
63 } |
|
64 |
|
65 |
|
66 CSenHostletTransportPlugin* CSenHostletTransportPlugin::NewL(CSenTransportContext* apCtx) |
|
67 { |
|
68 CSenHostletTransportPlugin* pNew = NewLC(apCtx); |
|
69 CleanupStack::Pop(pNew); |
|
70 return pNew; |
|
71 } |
|
72 |
|
73 CSenHostletTransportPlugin* CSenHostletTransportPlugin::NewLC(CSenTransportContext* apCtx) |
|
74 { |
|
75 |
|
76 const CSenServiceSession* pSession = apCtx->GetSession(); |
|
77 if( pSession == NULL || pSession->Hostlet() == NULL) |
|
78 { |
|
79 User::Leave( KErrSenHostNotAvailable ); |
|
80 } |
|
81 CSenHostletTransportPlugin* pNew = new (ELeave) CSenHostletTransportPlugin(apCtx); |
|
82 CleanupStack::PushL(pNew); |
|
83 pNew->ConstructL(); |
|
84 return pNew; |
|
85 } |
|
86 |
|
87 CSenHostletTransportPlugin::CSenHostletTransportPlugin(CSenTransportContext* apCtx) |
|
88 : CSenTransport(apCtx), |
|
89 ipRequester(NULL), |
|
90 iInvokedProvider(NULL), |
|
91 iStatusCode(0), |
|
92 iTransactionID(0), |
|
93 // iConsumerMap(EFalse, ETrue), |
|
94 // iSessionMap(EFalse, EFalse), // iConsumerMap deletes the txnIds (using same "new reserved" TInt here!) |
|
95 iRequestMap(EFalse, ETrue), // CSenActiveHostletRequest (keys) objects are NOT owned! |
|
96 ipLayeredXmlProperties(NULL) |
|
97 { |
|
98 } |
|
99 |
|
100 CSenHostletTransportPlugin::~CSenHostletTransportPlugin() |
|
101 { |
|
102 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "Log file closed."); |
|
103 TLSLOG_CLOSE( KHostletTransportLogChannel ); |
|
104 |
|
105 TInt count( iRequestMap.Count() ); |
|
106 for ( TInt i = 0; i < count; i++ ) |
|
107 { |
|
108 CSenActiveHostletRequest* pReq = iRequestMap.KeyAt(i); |
|
109 if( pReq ) |
|
110 { |
|
111 pReq->Deque(); |
|
112 } |
|
113 } |
|
114 iRequestMap.Reset(); |
|
115 delete ipRequester; |
|
116 delete iInvokedProvider; |
|
117 delete ipLayeredXmlProperties; |
|
118 } |
|
119 |
|
120 void CSenHostletTransportPlugin::ConstructL() |
|
121 { |
|
122 // Open connection to the file logger server |
|
123 TLSLOG_OPEN(KHostletTransportLogChannel, KHostletTransportLogLevel, KLogDir, KLogFile); |
|
124 |
|
125 //LOG_CONNECT; |
|
126 // LOG_CREATELOG((KLogDir, KLogFile, EFileLoggingModeOverwrite)); |
|
127 //TLSLOG_L(KHostletTransportLogChannel, KHostletTransportLogLevel, "CSenHostletTransportPlugin::ConstructL(): log file opened."); |
|
128 MSenCoreServiceManager& core = Context().GetCoreL(); |
|
129 ipRequester = CSenSyncRequester::NewL(*this, core); |
|
130 ipLayeredXmlProperties = CSenLayeredTransportProperties::NewL(); |
|
131 } |
|
132 |
|
133 TInt CSenHostletTransportPlugin::SubmitL(const TDesC8& aEndpoint, |
|
134 const TDesC8& aMessage, |
|
135 const TDesC8& aTransportProperties, |
|
136 HBufC8*& apResponse, |
|
137 MSenRemoteServiceConsumer& /*aConsumer*/) |
|
138 { |
|
139 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "CSenHostletTransportPlugin::SubmitL:"); |
|
140 |
|
141 // Sanity check the endpoint |
|
142 if (aEndpoint.Length() <= 0) |
|
143 { |
|
144 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "- No endpoint!"); |
|
145 return KErrSenNoEndpoint; // from SenServiceConnection.h (public API) |
|
146 } |
|
147 |
|
148 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L8("- Endpoint: %S"), &aEndpoint)); |
|
149 // TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "- Message:"); |
|
150 // TLSLOG_ALL((KHostletTransportLogChannel, KHostletTransportLogLevel, aMessage )); |
|
151 TLSLOG_FORMAT((KHostletTransportLogChannel, KMaxLogLevel, _L8("- Message: %S"), &aMessage)); |
|
152 |
|
153 TInt leaveCode(KErrNone); |
|
154 TInt statusCode(KErrNone); |
|
155 |
|
156 /* |
|
157 statusCode = ipRequester->SubmitL(aEndpoint, // endpoint |
|
158 aMessage, // request body |
|
159 aTransportProperties, // request props |
|
160 apResponse); |
|
161 */ |
|
162 |
|
163 TRAP( leaveCode, statusCode = ipRequester->SubmitL(aEndpoint, // endpoint |
|
164 aMessage, // request body |
|
165 aTransportProperties, // request props |
|
166 apResponse); ) // response body |
|
167 |
|
168 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L8("CSenHostletTransportPlugin::SubmitL returned: (%d)"), statusCode)); |
|
169 |
|
170 if(leaveCode!=KErrNone) |
|
171 { |
|
172 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L8("CSenHostletTransportPlugin::SubmitL leaved: (%d)"), leaveCode)); |
|
173 if(statusCode==KErrNone) |
|
174 { |
|
175 statusCode = leaveCode; |
|
176 } |
|
177 } |
|
178 else // did not leave |
|
179 { |
|
180 if(!apResponse) |
|
181 { |
|
182 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "After calling CSenHostletTransportPlugin::SubmitL => response==NULL => leaving!"); |
|
183 User::Leave(KErrCorrupt); |
|
184 } |
|
185 TLSLOG_L(KHostletTransportLogChannel, KMaxLogLevel, "CSenHostletTransportPlugin::SubmitL response:"); |
|
186 // TLSLOG_ALL((KHostletTransportLogChannel, KHostletTransportLogLevel, *apResponse)); |
|
187 TLSLOG_FORMAT((KHostletTransportLogChannel, KMaxLogLevel, _L8("- Response: %S"), apResponse)); |
|
188 } |
|
189 |
|
190 return statusCode; |
|
191 } |
|
192 |
|
193 /* |
|
194 TInt CSenHostletTransportPlugin::SendL(const TDesC8& aEndpoint, |
|
195 const TDesC8& aMessage, |
|
196 const TDesC8& aTransportProperties, |
|
197 MSenServiceSession& aReplyTo, |
|
198 MSenRemoteServiceConsumer& aConsumer, // "addressee", could be CSenIdentifier |
|
199 TInt& aTxnId) |
|
200 { |
|
201 TLSLOG_L(KHostletTransportLogChannel, KHostletTransportLogLevel, "CSenHostletTransportPlugin::SendL:"); |
|
202 |
|
203 // Sanity check the endpoint |
|
204 if (aEndpoint.Length() <= 0) |
|
205 { |
|
206 TLSLOG_L(KHostletTransportLogChannel, KHostletTransportLogLevel, "- No endpoint!"); |
|
207 return KErrSenNoEndpoint; // from SenServiceConnection.h (public API) |
|
208 } |
|
209 |
|
210 TLSLOG_FORMAT((KHostletTransportLogChannel, KHostletTransportLogLevel, _L8("- Endpoint: %S"), &aEndpoint)); |
|
211 TLSLOG_L(KHostletTransportLogChannel, KHostletTransportLogLevel, "- Message:"); |
|
212 // TLSLOG_ALL((KHostletTransportLogChannel, KHostletTransportLogLevel, aMessage )); |
|
213 |
|
214 // MSenCoreServiceManager& core = Context().GetCoreL(); |
|
215 //const CSenServiceSession* pSession = Context().GetSession(); |
|
216 //if( pSession == NULL || pSession->Hostlet() == NULL) |
|
217 |
|
218 // NOTE: this solution requires following line in CSenClientSession::SendMsgL: |
|
219 /// iAllowShowDialogCount++; |
|
220 /// TInt transactionId( KErrNotFound ); |
|
221 /// pSenChunk->ChunkHeader().SetTransactionId( transactionId ); |
|
222 /// TInt sendRetCode(KErrNone); |
|
223 |
|
224 |
|
225 if(aReplyTo.Hostlet() == NULL) |
|
226 { |
|
227 User::Leave( KErrSenHostNotAvailable ); |
|
228 } |
|
229 |
|
230 CSenChunk* pChunk = NULL; |
|
231 TInt retVal = aConsumer.ChunkByTxnIdL(aTxnId, pChunk); |
|
232 if ( retVal >= KErrNone ) |
|
233 { |
|
234 iTransactionID++; |
|
235 TInt* txnID = new (ELeave) TInt(iTransactionID); |
|
236 aTxnId = iTransactionID; |
|
237 pChunk->ChunkHeader().SetTransactionId(aTxnId); |
|
238 |
|
239 MSenRemoteHostlet* pHostlet = aReplyTo.Hostlet(); |
|
240 TInt retVal = pHostlet->ProcessRequestFromConsumerL(aMessage, aTxnId, aConsumer); |
|
241 |
|
242 TLSLOG_FORMAT((KHostletTransportLogChannel, KHostletTransportLogLevel, _L("- ProcessRequestFromConsumerL returned: %d"), retVal )); |
|
243 // No leave occurred |
|
244 |
|
245 if( retVal == KErrNone ) |
|
246 { |
|
247 TInt retVal = iSessionMap.Append(&aReplyTo, txnID); |
|
248 if( retVal==KErrNone ) |
|
249 { |
|
250 retVal = iConsumerMap.Append(&aConsumer, txnID); |
|
251 if(retVal!=KErrNone) |
|
252 { |
|
253 TLSLOG_FORMAT((KHostletTransportLogChannel, KHostletTransportLogLevel, |
|
254 _L("- iConsumerMap.Append failed: %d"), retVal )); |
|
255 |
|
256 // Last entry to iSessionMap must be removed |
|
257 TInt removeRetVal = iSessionMap.Remove(*txnID); |
|
258 #ifdef _SENDEBUG |
|
259 if(removeRetVal==KErrNotFound) |
|
260 { |
|
261 TLSLOG_FORMAT((KHostletTransportLogChannel, KHostletTransportLogLevel, |
|
262 _L("- MAJOR: Could not remove session by txnId(%d)"), *txnID)); |
|
263 } |
|
264 #endif // _SENDEBUG |
|
265 removeRetVal = 0; // not used in release builds |
|
266 } |
|
267 } |
|
268 else |
|
269 { |
|
270 TLSLOG_FORMAT((KHostletTransportLogChannel, KHostletTransportLogLevel, _L("- FATAL: iConsumerMap.Append failed: %d"), retVal )); |
|
271 } |
|
272 } |
|
273 } |
|
274 |
|
275 return retVal; |
|
276 } |
|
277 */ |
|
278 |
|
279 /* |
|
280 RConsumerMap CSenHostletTransportPlugin::ConsumerMap() |
|
281 { |
|
282 return iConsumerMap; |
|
283 |
|
284 } |
|
285 RSessionMap CSenHostletTransportPlugin::SessionMap() |
|
286 { |
|
287 return iSessionMap; |
|
288 } |
|
289 */ |
|
290 |
|
291 TInt CSenHostletTransportPlugin::SendL(const TDesC8& aEndpoint, |
|
292 const TDesC8& aMessage, |
|
293 const TDesC8& /* aTransportProperties */, |
|
294 MSenServiceSession& aReplyTo, |
|
295 MSenRemoteServiceConsumer& aConsumer, // "addressee", could be CSenIdentifier |
|
296 TInt& aTxnId) |
|
297 { |
|
298 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "CSenHostletTransportPlugin::SendL:"); |
|
299 |
|
300 // Sanity check the endpoint |
|
301 if (aEndpoint.Length() <= 0) |
|
302 { |
|
303 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "- No endpoint!"); |
|
304 return KErrSenNoEndpoint; // from SenServiceConnection.h (public API) |
|
305 } |
|
306 |
|
307 if(aReplyTo.Hostlet() == NULL) |
|
308 { |
|
309 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "- Failure: no Hostlet for the session: leave with KErrSenHostNotAvailable"); |
|
310 return KErrSenHostNotAvailable; |
|
311 } |
|
312 |
|
313 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L8("- Endpoint: %S"), &aEndpoint)); |
|
314 // TLSLOG_L(KHostletTransportLogChannel, KHostletTransportLogLevel, "- Message:"); |
|
315 // TLSLOG_ALL((KHostletTransportLogChannel, KHostletTransportLogLevel, aMessage)); |
|
316 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L8("- Message: %S"), &aMessage)); |
|
317 |
|
318 |
|
319 iTransactionID++; |
|
320 TInt* txnID = new (ELeave) TInt(iTransactionID); |
|
321 aTxnId = iTransactionID; |
|
322 |
|
323 // MSenCoreServiceManager& core = Context().GetCoreL(); |
|
324 CSenActiveHostletRequest* pRequest = CSenActiveHostletRequest::NewLC( aEndpoint, |
|
325 //aMessage, |
|
326 //aTransportProperties, |
|
327 aReplyTo, |
|
328 aConsumer, |
|
329 *txnID, |
|
330 iRequestMap, |
|
331 *this, |
|
332 *ipCtx ); |
|
333 |
|
334 TInt retVal = iRequestMap.Append(pRequest, txnID); |
|
335 |
|
336 if(retVal==KErrNone) |
|
337 { |
|
338 CleanupStack::Pop(pRequest); |
|
339 if(!pRequest->IsActive()) |
|
340 { |
|
341 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "- Activating request / async call to the provider."); |
|
342 pRequest->SetActive(); |
|
343 } |
|
344 pRequest->iStatus = KRequestPending; |
|
345 TRequestStatus* status = &pRequest->iStatus; |
|
346 User::RequestComplete( status, CSenActiveHostletRequest::EInvokeService ); //iTransactionID ); |
|
347 TLSLOG_FORMAT((KHostletTransportLogChannel, KNormalLogLevel, _L8("- Request status: %d"), pRequest->iStatus.Int())); |
|
348 } |
|
349 else |
|
350 { |
|
351 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L("- FATAL: iRequestMap.Append failed: %d"), retVal )); |
|
352 CleanupStack::PopAndDestroy(pRequest); // orphanized request |
|
353 } |
|
354 return retVal; // status code |
|
355 } |
|
356 |
|
357 TInt CSenHostletTransportPlugin::SetPropertiesL(const TDesC8& /* aProperties */, |
|
358 MSenLayeredProperties::TSenPropertiesLayer /* aTargetLayer */, |
|
359 MSenRemoteServiceConsumer* /*aConsumer*/) |
|
360 { |
|
361 return KErrNotSupported; // not implemented |
|
362 } |
|
363 |
|
364 TInt CSenHostletTransportPlugin::PropertiesL(HBufC8*& /* aProperties */) |
|
365 { |
|
366 return KErrNotSupported; // not implemented |
|
367 } |
|
368 |
|
369 // ASYNC |
|
370 TInt CSenHostletTransportPlugin::CompleteTransaction(const TInt aTxnId, |
|
371 const TInt aCompletionCode) |
|
372 { |
|
373 TLSLOG_FORMAT((KHostletTransportLogChannel, KNormalLogLevel, |
|
374 _L("CSenHostletTransportPlugin::CompleteTransaction(%d, %d)"), aTxnId, aCompletionCode)); |
|
375 |
|
376 TInt index = iRequestMap.FindValue(aTxnId); |
|
377 |
|
378 // complete the request (transaction) |
|
379 if(index != KErrNotFound) |
|
380 { |
|
381 // Consumer found |
|
382 TLSLOG_FORMAT((KHostletTransportLogChannel, KNormalLogLevel, |
|
383 _L("- Pending transaction at index %d found. Completing it."), |
|
384 index)); |
|
385 |
|
386 CSenActiveHostletRequest* pRequest = iRequestMap.KeyAt(index); |
|
387 TRequestStatus status; |
|
388 TRequestStatus* pStatus = &status; |
|
389 index = pRequest->Complete(pStatus, aCompletionCode); |
|
390 TLSLOG_FORMAT((KHostletTransportLogChannel, KNormalLogLevel, _L("- Request.Complete() returned: %d"), index)); |
|
391 } |
|
392 #ifdef _SENDEBUG |
|
393 else |
|
394 { |
|
395 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "- Cannot find pending transaction with given ID."); |
|
396 } |
|
397 #endif |
|
398 return index; |
|
399 } |
|
400 |
|
401 |
|
402 TInt CSenHostletTransportPlugin::CancelTransaction( const TInt aTxnId ) |
|
403 { |
|
404 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L("CSenHostletTransportPlugin::CancelTransaction(%d)"), aTxnId)); |
|
405 return CompleteTransaction( aTxnId, KErrSenCancelled ); |
|
406 } |
|
407 |
|
408 TPtrC8 CSenHostletTransportPlugin::UriSchemeL() |
|
409 { |
|
410 return KSenHostletTransportUriScheme(); |
|
411 } |
|
412 |
|
413 MSenProperties& CSenHostletTransportPlugin::PropertiesL() |
|
414 { |
|
415 return *ipLayeredXmlProperties; |
|
416 } |
|
417 |
|
418 |
|
419 // ------------------------------------------------------------------------------- // |
|
420 |
|
421 CSenActiveHostletRequest* CSenActiveHostletRequest::NewLC(const TDesC8& aEndpoint, |
|
422 MSenServiceSession& aReplyTo, |
|
423 MSenRemoteServiceConsumer& aConsumer, |
|
424 TInt aTxnId, |
|
425 RLocalRequestMap& aRequestMap, |
|
426 MSenTransport& aParent, |
|
427 MSenTransportContext& aParentCtx) |
|
428 { |
|
429 CSenActiveHostletRequest* pNew = new (ELeave) CSenActiveHostletRequest(aEndpoint, aReplyTo, aConsumer, aTxnId, aRequestMap, aParent, aParentCtx); |
|
430 CleanupStack::PushL(pNew); |
|
431 pNew->ConstructL(); |
|
432 return pNew; |
|
433 } |
|
434 |
|
435 |
|
436 CSenActiveHostletRequest::CSenActiveHostletRequest(const TDesC8& aEndpoint, |
|
437 MSenServiceSession& aReplyTo, |
|
438 MSenRemoteServiceConsumer& aConsumer, |
|
439 TInt aTxnId, |
|
440 RLocalRequestMap& aRequestMap, |
|
441 MSenTransport& aParent, |
|
442 MSenTransportContext& aParentContext) |
|
443 : CActive(EPriorityStandard), |
|
444 iEndpoint(aEndpoint), |
|
445 iCompletionCode(KErrNone), |
|
446 iReplyTo(aReplyTo), |
|
447 iConsumer(aConsumer), |
|
448 iTxnId(aTxnId), |
|
449 iRequestMap(aRequestMap), |
|
450 iParent(aParent), |
|
451 iParentContext(aParentContext), |
|
452 iMessage(KNullDesC8), |
|
453 iProperties(KNullDesC8) |
|
454 { |
|
455 CActiveScheduler::Add(this); |
|
456 } |
|
457 |
|
458 |
|
459 CSenActiveHostletRequest::~CSenActiveHostletRequest() |
|
460 { |
|
461 if ( IsActive() ) |
|
462 { |
|
463 Cancel(); // calls CSenActiveHostletRequest::DoCancel() |
|
464 } |
|
465 else |
|
466 { |
|
467 RequestMap().Remove(TxnId()); |
|
468 } |
|
469 } |
|
470 |
|
471 // returns chunk index or an error |
|
472 CSenChunk* CSenActiveHostletRequest::FindChunkL(const TInt aTxnId, TInt& aRetVal) |
|
473 { |
|
474 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "CSenActiveHostletRequest::DataFromChunkL"); |
|
475 CSenChunk* pChunk = NULL; |
|
476 |
|
477 // This lookup needs to be performed at every state of this AO, |
|
478 // since the transaction (chunk) might have been removed.. |
|
479 aRetVal = iConsumer.ChunkByTxnIdL(aTxnId, pChunk); |
|
480 |
|
481 TLSLOG_FORMAT((KHostletTransportLogChannel, KNormalLogLevel, _L("- ChunkByTxnIdL() returned: %d"), aRetVal)); |
|
482 |
|
483 if( aRetVal == KErrNone ) |
|
484 { |
|
485 if ( pChunk ) |
|
486 { |
|
487 iMessage.Set(KNullDesC8); |
|
488 iProperties.Set(KNullDesC8); |
|
489 TInt error(KErrNone); |
|
490 if (pChunk->ChunkHeader().PropertiesType() == MSenProperties::ENotInUse ) |
|
491 { |
|
492 error = pChunk->DescFromChunk(iMessage); |
|
493 } |
|
494 else |
|
495 { |
|
496 error = pChunk->DescsFromChunk(iMessage, iProperties); |
|
497 } |
|
498 |
|
499 if( error ) |
|
500 { |
|
501 aRetVal = error; |
|
502 iMessage.Set(KNullDesC8); |
|
503 iProperties.Set(KNullDesC8); |
|
504 } |
|
505 } |
|
506 else |
|
507 { |
|
508 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "- Chunk from consumer == NULL, eventhough getter returned KErrNone(!)"); |
|
509 // No chunk, eventhough KErrNone was returned, should NEVER happen |
|
510 // ==> report "internal error" |
|
511 aRetVal = KErrSenInternal; // error code is from SenServiceConnection.h |
|
512 } |
|
513 } |
|
514 return pChunk; |
|
515 } |
|
516 |
|
517 TInt CSenActiveHostletRequest::RunError(TInt aError) |
|
518 { |
|
519 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L("CSenActiveHostletRequest::RunError(%d)"), aError)); |
|
520 delete this; |
|
521 return KErrNone; |
|
522 } |
|
523 |
|
524 CSenTransportProperties* CSenActiveHostletRequest::NewPropertiesByTypeL( MSenProperties::TSenPropertiesClassType aType, const TDesC8& aPropertiesAsXml ) |
|
525 { |
|
526 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "CSenActiveHostletRequest::NewPropertiesByTypeL - begin"); |
|
527 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L(" - aProperties: '%S'"), &aPropertiesAsXml )); |
|
528 |
|
529 CSenTransportProperties* pProps = NULL; |
|
530 CSenXmlReader& reader = *(iParentContext.GetCoreL().XMLReader()); |
|
531 |
|
532 // Check whether the response carries properties and allocate properties object, if it does |
|
533 switch ( aType ) |
|
534 { |
|
535 case MSenProperties::ENotInUse: |
|
536 { |
|
537 // pProps = NULL; |
|
538 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "Properties type: MSenProperties::ENotInUse"); |
|
539 } |
|
540 break; |
|
541 |
|
542 case MSenProperties::ESenHttpTransportProperties: |
|
543 { |
|
544 pProps = CSenHttpTransportProperties::NewL( iProperties, reader ); |
|
545 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "Properties type: MSenProperties::ESenHttpTransportProperties"); |
|
546 } |
|
547 break; |
|
548 |
|
549 case MSenProperties::ESenVtcpTransportProperties: |
|
550 { |
|
551 pProps = CSenVtcpTransportProperties::NewL( iProperties, reader ); |
|
552 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "Properties type: MSenProperties::ESenVtcpTransportProperties"); |
|
553 } |
|
554 break; |
|
555 |
|
556 case MSenProperties::ESenTransportProperties: |
|
557 { |
|
558 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "Properties type: MSenProperties::ESenTransportProperties"); |
|
559 pProps = CSenTransportProperties::NewL( iProperties, reader ); |
|
560 } |
|
561 break; |
|
562 |
|
563 default: |
|
564 { |
|
565 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "Properties type is unknown, defaulting to MSenProperties::ESenTransportProperties"); |
|
566 pProps = CSenTransportProperties::NewL( iProperties, reader ); |
|
567 } |
|
568 break; |
|
569 } |
|
570 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "CSenActiveHostletRequest::NewPropertiesByTypeL - end"); |
|
571 return pProps; |
|
572 } |
|
573 |
|
574 void CSenActiveHostletRequest::RunL() |
|
575 { |
|
576 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L("CSenActiveHostletRequest::RunL(), status: %d"), iStatus.Int())); |
|
577 TInt leaveCode(KErrNone); |
|
578 TInt retVal(KErrNone); // for UDEB, logging |
|
579 CSenChunk* pChunk = NULL; |
|
580 switch(iStatus.Int()) |
|
581 { |
|
582 |
|
583 case EInvokeService: |
|
584 { |
|
585 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "HostletTransport req AO::RunL -- EInvokeService -- "); |
|
586 MSenRemoteHostlet* pHostlet = iReplyTo.Hostlet(); |
|
587 if( pHostlet ) |
|
588 { |
|
589 TRAP( leaveCode, pChunk = FindChunkL(iTxnId, retVal) ); |
|
590 MSenProperties::TSenPropertiesClassType type = pChunk->ChunkHeader().PropertiesType(); |
|
591 |
|
592 if ( leaveCode != KErrNone ) |
|
593 { |
|
594 retVal = leaveCode; |
|
595 } |
|
596 |
|
597 if ( retVal == KErrNone ) |
|
598 { |
|
599 // CSenTransportProperties* pProps = NewPropertiesByTypeL( type, iProperties ); |
|
600 // if( pProps ) |
|
601 // { |
|
602 // CleanupStack::PushL( pProps ); |
|
603 // retVal = iReplyTo.SendToHostletL( *pHostlet, iMessage, iTxnId, iConsumer, pProps ); |
|
604 // CleanupStack::PopAndDestroy( pProps ); |
|
605 // } |
|
606 // else // no properties in this request |
|
607 // { |
|
608 retVal = iReplyTo.SendToHostletL( *pHostlet, iMessage, iTxnId, iConsumer ); |
|
609 // } |
|
610 TLSLOG_FORMAT((KHostletTransportLogChannel, KNormalLogLevel, _L8("- HostletTransport req AO::RunL: ProcessRequestFromConsumerL returned: %d "), retVal)); |
|
611 } |
|
612 } |
|
613 } |
|
614 break; |
|
615 |
|
616 case ECompleteTransaction: |
|
617 { |
|
618 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "HostletTransport req AO::RunL -- ECompleteTransaction -- "); |
|
619 |
|
620 // This lookup needs to be performed (again), since the transaction (chunk) might have been removed.. |
|
621 TRAP( leaveCode, pChunk = FindChunkL(iTxnId, retVal) ); |
|
622 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L("- FindChunkL() returned: %d [%d]"), retVal, leaveCode)); |
|
623 if( leaveCode != KErrNone ) |
|
624 { |
|
625 retVal = leaveCode; |
|
626 } |
|
627 |
|
628 if( retVal == KErrNone ) |
|
629 { |
|
630 // It is VERY important to change the chunk's (message's) direction to INBOUND. Among other things, |
|
631 // it will indicate that the descriptor(s) passed to session & consumer -- msg & props -- are in |
|
632 // chunk (no need to delete a copy from heap, etc) |
|
633 pChunk->ChunkHeader().SetMessageDirection(MSenMessage::EInbound); |
|
634 |
|
635 MSenProperties::TSenPropertiesClassType type = pChunk->ChunkHeader().PropertiesType(); |
|
636 |
|
637 HBufC8* pMessage = (HBufC8*)&iMessage; // This is OK, since we have set the message direction to INBOUND, and message will NOT be de-allocated(!), |
|
638 // Neither will it be copied to its own address (it is already in the chunk) |
|
639 // NOTE(!): Remote consumer checks chunk header's message direction and does not delete the desc behind this pointer |
|
640 // if the direction is already "inbound" |
|
641 |
|
642 CSenTransportProperties* pProps = NewPropertiesByTypeL( type, iProperties ); |
|
643 |
|
644 if( iCompletionCode < KErrNone ) // aCompletionCode == ERROR |
|
645 { |
|
646 if ( pProps ) |
|
647 { |
|
648 CleanupStack::PushL( pProps ); |
|
649 TRAP( leaveCode, retVal = iReplyTo.SendErrorToConsumerL(iCompletionCode, pMessage, iTxnId, iConsumer, pProps); ) |
|
650 CleanupStack::PopAndDestroy( pProps ); |
|
651 } |
|
652 else |
|
653 { |
|
654 TRAP( leaveCode, retVal = iReplyTo.SendErrorToConsumerL(iCompletionCode, pMessage, iTxnId, iConsumer); ) |
|
655 } |
|
656 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L("- SendErrorToConsumerL() returned: %d [%d]"), retVal, leaveCode)); |
|
657 } |
|
658 else // completionCode == KErrNone (all is fine) |
|
659 { |
|
660 if ( pProps ) |
|
661 { |
|
662 CleanupStack::PushL( pProps ); |
|
663 TRAP( leaveCode, retVal = iReplyTo.SendToConsumerL(pMessage, iTxnId, iConsumer, pProps); ) |
|
664 CleanupStack::PopAndDestroy( pProps ); |
|
665 } |
|
666 else |
|
667 { |
|
668 TRAP( leaveCode, retVal = iReplyTo.SendToConsumerL(pMessage, iTxnId, iConsumer); ) |
|
669 } |
|
670 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L("- SendToConsumerL() returned: %d [%d]"), retVal, leaveCode)); |
|
671 } |
|
672 if ( retVal == KErrNone && leaveCode != KErrNone) |
|
673 { |
|
674 retVal = leaveCode; |
|
675 } |
|
676 |
|
677 MSenRemoteHostlet* pHostlet = iReplyTo.Hostlet(); |
|
678 if( pHostlet ) |
|
679 { |
|
680 TRAP( leaveCode, retVal = pHostlet->OnServiceCompleteL(iTxnId, retVal, KNullDesC8); ) |
|
681 TLSLOG_FORMAT((KHostletTransportLogChannel, KMinLogLevel, _L8("- OnServiceCompleteL returned: %d [%d]"), retVal, leaveCode)); |
|
682 retVal = 0; // not used in release builds |
|
683 } |
|
684 #ifdef _SENDEBUG |
|
685 else |
|
686 { |
|
687 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "- Remote Hostlet == NULL"); |
|
688 } |
|
689 #endif |
|
690 } |
|
691 |
|
692 if(retVal == KErrNone) |
|
693 { |
|
694 retVal = RequestMap().Remove(iTxnId); // deletes the request (transaction) |
|
695 TLSLOG_FORMAT((KHostletTransportLogChannel, KNormalLogLevel, _L("- Remove() returned: %d"), retVal)); |
|
696 } |
|
697 // de-allocate this in EVERY CASE |
|
698 delete this; // (*) => this MUST ALWAYS BE PERFORMED! |
|
699 } |
|
700 break; |
|
701 |
|
702 default: |
|
703 { |
|
704 TLSLOG_FORMAT((KHostletTransportLogChannel, KNormalLogLevel, _L("- HostletTransport req AO::RunL: Unknown request: %d"), iStatus.Int())); |
|
705 } |
|
706 // unknown |
|
707 break; |
|
708 } |
|
709 TInt unused = leaveCode; leaveCode = unused; // not used in release builds |
|
710 unused = retVal; retVal = unused; // not used in release builds |
|
711 } |
|
712 |
|
713 TInt CSenActiveHostletRequest::Complete(TRequestStatus*& aStatus, TInt aCompletionCode) |
|
714 { |
|
715 iCompletionCode = aCompletionCode; |
|
716 if(!IsActive()) |
|
717 { |
|
718 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "CSenActiveHostletRequest::Complete()"); |
|
719 SetActive(); |
|
720 } |
|
721 #ifdef _SENDEBUG |
|
722 else |
|
723 { |
|
724 TLSLOG_L(KHostletTransportLogChannel, KMinLogLevel, "CSenActiveHostletRequest::Complete(): AO already active (?)"); |
|
725 } |
|
726 #endif // _SEDEBUG |
|
727 iStatus = KRequestPending; |
|
728 aStatus = &iStatus; |
|
729 User::RequestComplete( aStatus, CSenActiveHostletRequest::ECompleteTransaction ); |
|
730 return KErrNone; |
|
731 } |
|
732 |
|
733 |
|
734 void CSenActiveHostletRequest::DoCancel() |
|
735 { |
|
736 RequestMap().Remove(TxnId()); |
|
737 } |
|
738 |
|
739 void CSenActiveHostletRequest::ConstructL() |
|
740 { |
|
741 } |
|
742 |
|
743 RLocalRequestMap& CSenActiveHostletRequest::RequestMap() |
|
744 { |
|
745 return iRequestMap; |
|
746 } |
|
747 |
|
748 MSenServiceSession& CSenActiveHostletRequest::Session() const |
|
749 { |
|
750 return iReplyTo; |
|
751 } |
|
752 |
|
753 MSenRemoteServiceConsumer& CSenActiveHostletRequest::Consumer() const |
|
754 { |
|
755 return iConsumer; |
|
756 } |
|
757 |
|
758 |
|
759 TInt CSenActiveHostletRequest::TxnId() const |
|
760 { |
|
761 return iTxnId; |
|
762 } |
|
763 |
|
764 // END OF FILE |