|
1 /* |
|
2 * Copyright (c) 2002-2005 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 <e32std.h> // for RPointerArray |
|
29 |
|
30 #include "SenServiceConnection.h" // session status constants |
|
31 #include "senservicesession.h" |
|
32 #include "SenXmlUtils.h" |
|
33 #include "senpolicy.h" |
|
34 #include "senserviceinvocationframework.h" |
|
35 #include "senprovider.h" |
|
36 #include "senidentifier.h" |
|
37 #include "sentransportbase.h" |
|
38 |
|
39 #include "msenlayeredproperties.h" |
|
40 |
|
41 #include "msenremotehostlet.h" // internal |
|
42 |
|
43 #include "sendebug.h" |
|
44 #include "senlogger.h" |
|
45 |
|
46 EXPORT_C CSenServiceSession::CSenServiceSession(TDescriptionClassType aType, |
|
47 MSIF& aFramework) : |
|
48 CSenWSDescription(aType), |
|
49 iStatus(KSenConnectionStatusNew), |
|
50 iFramework(aFramework), |
|
51 ipTransport(NULL) |
|
52 { |
|
53 } |
|
54 |
|
55 EXPORT_C CSenServiceSession::~CSenServiceSession() |
|
56 { |
|
57 // The REMOTE consumers are also sessions which are |
|
58 // owned by XMLDAO or ClientSession |
|
59 iConsumerList.Reset(); |
|
60 iFacets.ResetAndDestroy(); |
|
61 if (iTransportOwned) |
|
62 { |
|
63 delete ipTransport; |
|
64 } |
|
65 ipTransport = NULL; |
|
66 } |
|
67 |
|
68 // Constructor offered to subclasses: |
|
69 EXPORT_C void CSenServiceSession::BaseConstructL() |
|
70 { |
|
71 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenServiceSession::BaseConstructL - Version 2 [2006-05-09]"); |
|
72 |
|
73 // Sets the local name to "ServiceDescription" |
|
74 // and initiates the inner ipElement |
|
75 CSenWSDescription::ConstructL(); |
|
76 } |
|
77 |
|
78 EXPORT_C TInt CSenServiceSession::InitializeFromL(MSenServiceDescription& aServiceDescription) |
|
79 { |
|
80 _LIT8(KTouch, "touch"); |
|
81 CSenWSDescription& sd = (CSenWSDescription&)aServiceDescription; |
|
82 const TDesC8* attrValue = sd.AsElement().AttrValue(KTouch); |
|
83 if(attrValue != NULL) |
|
84 { |
|
85 AsElement().AddAttrL(KTouch, *attrValue); |
|
86 } |
|
87 _LIT8(KEndpointLocalname, "Endpoint"); |
|
88 CSenElement* pEndpointElement = sd.AsElement().Element(KEndpointLocalname); |
|
89 TPtrC8 transportCue; |
|
90 if(pEndpointElement) |
|
91 { |
|
92 _LIT8(KCue, "cue"); |
|
93 const TDesC8* cue = pEndpointElement->AttrValue(KCue); |
|
94 if(cue && cue->Length()>0) |
|
95 { |
|
96 transportCue.Set(*cue); |
|
97 SetTransportCueL(transportCue); |
|
98 } |
|
99 } |
|
100 |
|
101 if(IsLocalL()) |
|
102 { |
|
103 // Initialize local service sessions by trying to lookup the hostlet plug-in |
|
104 // behind a local endpoint, and if such exists, by asking it to add (facet) |
|
105 // data into this session. |
|
106 |
|
107 // Check transport cue; if such XML attribute |
|
108 // has been set to <Endpoint element, it is |
|
109 // "stronger" than actual endpoint scheme |
|
110 |
|
111 TPtrC8 hostletCue = aServiceDescription.Endpoint(); |
|
112 if( transportCue.Length() > 0 ) |
|
113 { |
|
114 hostletCue.Set( transportCue ); |
|
115 } |
|
116 |
|
117 |
|
118 |
|
119 CSenProvider* pHostlet = NULL; |
|
120 TInt leaveCode(KErrNone); |
|
121 TRAP(leaveCode, pHostlet = CSenProvider::NewL(hostletCue)); |
|
122 if(leaveCode == KErrNone && pHostlet) |
|
123 { |
|
124 CleanupStack::PushL(pHostlet); |
|
125 |
|
126 // Inside InitServiceSessionL, the hostlet can add it's facets into this |
|
127 // session and possibly initialize some other data required. |
|
128 CSenWSDescription* pSD = CSenWSDescription::NewLC(); |
|
129 pHostlet->DescribeServiceL(*pSD); // pHostlet->InitServiceSessionL(*this); |
|
130 this->InitializeFromL(*pSD); |
|
131 CleanupStack::PopAndDestroy(pSD); |
|
132 |
|
133 |
|
134 /* |
|
135 CSenWSDescription* pSD = pHostlet->SessionDescriptionLC(); |
|
136 // this->InitializeFacetsFromL(*pSD); |
|
137 |
|
138 // Copy the facets from local service provider session description |
|
139 RFacetArray facets; |
|
140 pSD->FacetsL(facets); |
|
141 CleanupClosePushL(facets); |
|
142 |
|
143 TInt count(facets.Count()); |
|
144 for (TInt i=0; i<count; i++) |
|
145 { |
|
146 SetFacetL(*facets[i]); |
|
147 } |
|
148 |
|
149 descFacets.ResetAndDestroy(); |
|
150 CleanupStack::Pop(); // facets.Close() |
|
151 |
|
152 CleanupStack::PopAndDestroy(); // pSD |
|
153 */ |
|
154 |
|
155 CleanupStack::PopAndDestroy(); //pHostlet |
|
156 } |
|
157 } |
|
158 |
|
159 |
|
160 RFacetArray descFacets; |
|
161 aServiceDescription.FacetsL(descFacets); |
|
162 CleanupClosePushL(descFacets); |
|
163 |
|
164 TInt count(descFacets.Count()); |
|
165 for (TInt i=0; i<count; i++) |
|
166 { |
|
167 SetFacetL(*descFacets[i]); |
|
168 } |
|
169 |
|
170 descFacets.ResetAndDestroy(); |
|
171 CleanupStack::Pop(); // descFacets.Close() |
|
172 |
|
173 return KErrNone; |
|
174 } |
|
175 |
|
176 EXPORT_C TInt CSenServiceSession::ParseResponseL(const TDesC8& aInput, |
|
177 HBufC8*& aOutput) |
|
178 { |
|
179 aOutput = HBufC8::NewL(aInput.Length()); |
|
180 aOutput->Des().Append(aInput); |
|
181 return KErrNone; |
|
182 } |
|
183 |
|
184 /** |
|
185 * Ask the ServiceManager to save a description |
|
186 * of this ServiceSession (in its DAO storage). |
|
187 * |
|
188 * This (convenience) method can be called from within other methods of |
|
189 * ServiceSession (and/or subclasses) and by ServiceInvocationFramework |
|
190 * implementations. |
|
191 * |
|
192 */ |
|
193 EXPORT_C void CSenServiceSession::SaveL() |
|
194 { |
|
195 iFramework.Manager().SaveL(*this); |
|
196 } |
|
197 |
|
198 /** |
|
199 * Return the status of this ServiceSession. |
|
200 * |
|
201 * @return TInt the status |
|
202 */ |
|
203 EXPORT_C TInt CSenServiceSession::StatusL() |
|
204 { |
|
205 return(iStatus); |
|
206 } |
|
207 |
|
208 |
|
209 |
|
210 /** |
|
211 * SetStatus |
|
212 * |
|
213 * Compute the status of the ServiceSession. If the status |
|
214 * changes to, or from, "KSenConnectionStatusReady" |
|
215 * inform service consumers about the new status. |
|
216 * |
|
217 * @return TInt indicating the CHANGED status that was set |
|
218 * |
|
219 */ |
|
220 EXPORT_C TInt CSenServiceSession::SetStatusL() |
|
221 { |
|
222 |
|
223 TInt currentStatus = iStatus; |
|
224 iStatus = ComputeStatusL(); |
|
225 if ( (currentStatus == KSenConnectionStatusReady |
|
226 && iStatus != KSenConnectionStatusReady) |
|
227 || |
|
228 (currentStatus != KSenConnectionStatusReady |
|
229 && iStatus == KSenConnectionStatusReady) ) |
|
230 { |
|
231 |
|
232 // notify clients |
|
233 RServiceConsumerArray consumers; |
|
234 CleanupClosePushL(consumers); |
|
235 TInt err = Consumers(consumers); |
|
236 |
|
237 if(err==KErrNone) |
|
238 { |
|
239 TInt count = consumers.Count(); |
|
240 for (TInt i=0; i<count; i++) |
|
241 { |
|
242 TRAPD(error, (consumers[i])->SetStatusL(iStatus)); |
|
243 if(error!=KErrNone) |
|
244 { |
|
245 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8("CSenServiceSession::SetStatusL() \ |
|
246 failed to set status of %d consumer, error code (%d)"), |
|
247 (i+1), error)); |
|
248 } |
|
249 } |
|
250 } |
|
251 CleanupStack::PopAndDestroy(); // close() consumers |
|
252 } |
|
253 return(iStatus); |
|
254 } |
|
255 |
|
256 /** |
|
257 * Compute the current status of the ServiceSession. |
|
258 * Subclasses __will__ override this. |
|
259 * This method does not actually set the status of the ServiceSession |
|
260 * and does not notify consumers about changes. |
|
261 * |
|
262 * @return TInt indicating the CURRENT computed status |
|
263 */ |
|
264 EXPORT_C TInt CSenServiceSession::ComputeStatusL() |
|
265 { |
|
266 TInt result = KSenConnectionStatusNew; |
|
267 TPtrC8 endpoint = Endpoint(); |
|
268 |
|
269 if(endpoint.Length()>1) |
|
270 result = KSenConnectionStatusReady; |
|
271 |
|
272 return result; |
|
273 } |
|
274 |
|
275 EXPORT_C MSenRemoteServiceConsumer* CSenServiceSession::RemoteConsumerL( |
|
276 const TDesC8& aSenderID) |
|
277 { |
|
278 TInt consumersCount(iConsumerList.Count()); |
|
279 |
|
280 for(TInt i=0; i<consumersCount; i++) |
|
281 { |
|
282 if(iConsumerList[i]->Id() == aSenderID) |
|
283 { |
|
284 return iConsumerList[i]; |
|
285 } |
|
286 } |
|
287 return NULL; // not found |
|
288 |
|
289 } |
|
290 |
|
291 |
|
292 EXPORT_C TInt CSenServiceSession::SubmitL(const TDesC8& aMessage, |
|
293 const TDesC8& aTransportProperties, |
|
294 MSenRemoteServiceConsumer& aConsumer, |
|
295 HBufC8*& aResponse) |
|
296 { |
|
297 // CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenServiceSession::SubmitL"); |
|
298 TPtrC8 endpoint = Endpoint(); |
|
299 ////////////////////////////////////////////////////////////////////////// |
|
300 //CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"***********************************************************"); |
|
301 //CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Endpoint: %S"), &endpoint)); |
|
302 //CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Request (%d bytes):"), aMessage.Length())); |
|
303 //CSLOG_ALL(aConsumer.ConnectionId() , KMaxLogLevel,( aMessage )); |
|
304 //CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"***********************************************************"); |
|
305 ////////////////////////////////////////////////////////////////////////// |
|
306 |
|
307 delete aResponse; |
|
308 aResponse = NULL; |
|
309 |
|
310 //MSenRemoteServiceConsumer* pConsumer = RemoteConsumerL(aSenderId); |
|
311 |
|
312 MSenTransport& transport = aConsumer.TransportL(); |
|
313 TInt retVal( transport.SubmitL(endpoint, aMessage, aTransportProperties, aResponse,aConsumer) ); |
|
314 if(retVal==KErrNone) |
|
315 { |
|
316 // attempt to parse the response. |
|
317 |
|
318 HBufC8* parsedResponse = NULL; |
|
319 TInt leaveCode(KErrNone); |
|
320 TRAP(leaveCode, ParseResponseL(*aResponse, parsedResponse)); |
|
321 if(leaveCode!=KErrNone) |
|
322 { |
|
323 // response is returned as it is: unparsed (for debugging reasons) |
|
324 retVal = leaveCode; |
|
325 } |
|
326 else |
|
327 { |
|
328 // parsing went OK. Release unparsed buffer |
|
329 delete aResponse; |
|
330 // assign the parsed buffer to aResponse |
|
331 aResponse = parsedResponse; |
|
332 } |
|
333 } |
|
334 // else directly return the error received from transport |
|
335 return retVal; |
|
336 } |
|
337 |
|
338 |
|
339 /* |
|
340 * @see CServiceConnection.Send(...) |
|
341 */ |
|
342 // add txnid, transport properties |
|
343 EXPORT_C TInt CSenServiceSession::SendL( const TDesC8& aMessage, |
|
344 const TDesC8& aTransportProperties, |
|
345 MSenRemoteServiceConsumer& aConsumer, |
|
346 TInt& aTxnId, |
|
347 HBufC8*& /*aRevalidationError*/ ) |
|
348 { |
|
349 //CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"CSenServiceSession::SendL:"); |
|
350 TPtrC8 endpoint = Endpoint(); |
|
351 ////////////////////////////////////////////////////////////////////////// |
|
352 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"***********************************************************"); |
|
353 //CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Endpoint: %S"), &endpoint)); |
|
354 //CSLOG_FORMAT((aConsumer.ConnectionId() , KMaxLogLevel, _L8("- Request (%d bytes):"), aMessage.Length())); |
|
355 //CSLOG_ALL(aConsumer.ConnectionId() , KMaxLogLevel,( aMessage )); |
|
356 CSLOG_L(aConsumer.ConnectionId() , KMaxLogLevel,"***********************************************************"); |
|
357 ////////////////////////////////////////////////////////////////////////// |
|
358 MSenTransport& t = aConsumer.TransportL(); |
|
359 TInt retVal(t.SendL(endpoint, aMessage, aTransportProperties, *this, aConsumer, aTxnId)); |
|
360 return retVal; |
|
361 } |
|
362 |
|
363 |
|
364 /* |
|
365 * @see CServiceConnection.IsReadyL() |
|
366 * *** Note: in Java reference implementation method's was named "isValid()"! |
|
367 */ |
|
368 EXPORT_C TBool CSenServiceSession::IsReadyL() |
|
369 { |
|
370 return (iStatus==KSenConnectionStatusReady); |
|
371 } |
|
372 |
|
373 EXPORT_C TInt CSenServiceSession::CompleteServerMessagesOnOffL( |
|
374 const TBool& aCompleteOnOff) |
|
375 { |
|
376 |
|
377 if (aCompleteOnOff) |
|
378 { |
|
379 CSenFacet* pFacet = CSenFacet::NewL(); |
|
380 CleanupStack::PushL(pFacet); |
|
381 pFacet->SetNameL(KCompleteMessagesFacet); |
|
382 pFacet->SetValueL(KSenFacetValTrue); |
|
383 SetFacetL(*pFacet); |
|
384 CleanupStack::PopAndDestroy(); // pFacet |
|
385 } |
|
386 else |
|
387 { |
|
388 RemoveFacet(KCompleteMessagesFacet); |
|
389 } |
|
390 |
|
391 return KErrNone; |
|
392 } |
|
393 |
|
394 |
|
395 EXPORT_C TInt CSenServiceSession::HasFacetL(const TDesC8& aURI, TBool& aHasFacet) |
|
396 { |
|
397 aHasFacet = EFalse; |
|
398 TInt count(iFacets.Count()); |
|
399 |
|
400 for (TInt i=0;i<count && !aHasFacet;i++) |
|
401 { |
|
402 if (iFacets[i]->Name() == aURI) |
|
403 { |
|
404 aHasFacet = ETrue; |
|
405 } |
|
406 } |
|
407 |
|
408 return KErrNone; |
|
409 } |
|
410 |
|
411 EXPORT_C TInt CSenServiceSession::FacetValue(TDesC8& aURI, HBufC8*& aValueTo) |
|
412 { |
|
413 delete aValueTo; |
|
414 aValueTo = NULL; |
|
415 |
|
416 TInt retVal = KErrNotFound; |
|
417 TInt count(iFacets.Count()); |
|
418 |
|
419 for (TInt i=0; i<count && retVal == KErrNotFound;i++) |
|
420 { |
|
421 if (iFacets[i]->Name() == aURI) |
|
422 { |
|
423 aValueTo = iFacets[i]->Value().Alloc(); |
|
424 if (aValueTo == NULL) |
|
425 { |
|
426 retVal = KErrNoMemory; |
|
427 } |
|
428 else |
|
429 { |
|
430 retVal = KErrNone; |
|
431 } |
|
432 } |
|
433 } |
|
434 return retVal; |
|
435 } |
|
436 |
|
437 EXPORT_C TInt CSenServiceSession::AddFacetL(const CSenFacet& aFacet) |
|
438 { |
|
439 // In XML SD, this does not equal with SetFacetL(), but checks |
|
440 // for duplicate, already reserved facet name and returns an |
|
441 // error if such exists. |
|
442 return SetFacetL(aFacet); |
|
443 } |
|
444 |
|
445 EXPORT_C TInt CSenServiceSession::SetFacetL(const CSenFacet& aFacet) |
|
446 { |
|
447 TBool hasFacet; |
|
448 HasFacetL(((CSenFacet&)aFacet).Name(),hasFacet); |
|
449 if (hasFacet) |
|
450 { |
|
451 RemoveFacet(((CSenFacet&)aFacet).Name()); |
|
452 } |
|
453 CSenFacet* pNewFacet = CSenFacet::NewL(((CSenFacet&)aFacet)); |
|
454 return iFacets.Append(pNewFacet); |
|
455 } |
|
456 |
|
457 EXPORT_C TInt CSenServiceSession::RemoveFacet(const TDesC8& aURI) |
|
458 { |
|
459 TInt count(iFacets.Count()); |
|
460 |
|
461 for (TInt i=0;i<count;i++) |
|
462 { |
|
463 if (iFacets[i]->Name() == aURI) |
|
464 { |
|
465 delete iFacets[i]; |
|
466 iFacets.Remove(i); |
|
467 return KErrNone; |
|
468 } |
|
469 } |
|
470 |
|
471 return KErrNotFound; |
|
472 } |
|
473 |
|
474 EXPORT_C TInt CSenServiceSession::FacetsL(RFacetArray& aFacetArray) |
|
475 { |
|
476 CSenFacet* pFacet = NULL; |
|
477 TInt count(iFacets.Count()); |
|
478 for (TInt i=0; i<count; i++) |
|
479 { |
|
480 pFacet = CSenFacet::NewL(*iFacets[i]); |
|
481 aFacetArray.Append(pFacet); |
|
482 } |
|
483 return KErrNone; |
|
484 } |
|
485 |
|
486 EXPORT_C TInt CSenServiceSession::ScoreMatchL(MSenServiceDescription& aPattern) |
|
487 { |
|
488 TInt score(0); |
|
489 |
|
490 if ( (aPattern.FrameworkId().Length() == 0) || |
|
491 ( (aPattern.FrameworkId().Length() > 0) && (aPattern.FrameworkId() == FrameworkId()) ) ) |
|
492 { |
|
493 if ((aPattern.Endpoint().Length() > 0) && (aPattern.Endpoint() == Endpoint())) |
|
494 { |
|
495 score = score + KSenServiceDescriptionBaseScore; |
|
496 } |
|
497 if ((aPattern.Contract().Length() > 0) && (aPattern.Contract() == Contract())) |
|
498 { |
|
499 score = score + KSenServiceDescriptionBaseScore; |
|
500 } |
|
501 } |
|
502 |
|
503 |
|
504 if ( score > 0 ) |
|
505 { |
|
506 RFacetArray otherFacets; |
|
507 CleanupClosePushL(otherFacets); |
|
508 aPattern.FacetsL(otherFacets); |
|
509 |
|
510 HBufC8* pFacetValue = NULL; |
|
511 TPtrC8 facetName; |
|
512 |
|
513 TInt count(otherFacets.Count()); |
|
514 for (TInt i=0; i<count; i++) |
|
515 { |
|
516 facetName.Set(otherFacets[i]->Name()); |
|
517 FacetValue(facetName,pFacetValue); |
|
518 if (pFacetValue && *pFacetValue == otherFacets[i]->Value()) score++; |
|
519 delete pFacetValue; |
|
520 pFacetValue = NULL; |
|
521 } |
|
522 |
|
523 otherFacets.ResetAndDestroy(); |
|
524 CleanupStack::Pop(); |
|
525 |
|
526 if ( ipHostlet ) |
|
527 { |
|
528 score++; |
|
529 } |
|
530 } |
|
531 |
|
532 return score; |
|
533 } |
|
534 |
|
535 EXPORT_C TBool CSenServiceSession::Matches(MSenServiceDescription& aOtherServiceDescription) |
|
536 { |
|
537 TPtrC8 patternEndpoint = aOtherServiceDescription.Endpoint(); |
|
538 TPtrC8 thisEndpoint = Endpoint(); |
|
539 |
|
540 if(patternEndpoint.Length()>0) |
|
541 { |
|
542 if(!(thisEndpoint.Length()>0 && patternEndpoint == thisEndpoint)) |
|
543 { |
|
544 return EFalse; |
|
545 } |
|
546 } |
|
547 |
|
548 TPtrC8 patternContract = aOtherServiceDescription.Contract(); |
|
549 TPtrC8 thisContract = Contract(); |
|
550 |
|
551 if(patternContract.Length()>0) |
|
552 { |
|
553 if(!(thisContract.Length()>0 && patternContract == thisContract)) |
|
554 { |
|
555 return EFalse; |
|
556 } |
|
557 } |
|
558 |
|
559 TPtrC8 patternFrameworkId = aOtherServiceDescription.FrameworkId(); |
|
560 TPtrC8 thisFrameworkId = FrameworkId(); |
|
561 if(patternFrameworkId.Length()>0) |
|
562 { |
|
563 if(!(thisFrameworkId.Length()>0 && patternFrameworkId == thisFrameworkId)) |
|
564 { |
|
565 return EFalse; |
|
566 } |
|
567 } |
|
568 |
|
569 |
|
570 TBool match(ETrue); |
|
571 TRAPD(retVal, |
|
572 RFacetArray otherFacets; |
|
573 CleanupClosePushL(otherFacets); |
|
574 aOtherServiceDescription.FacetsL(otherFacets); |
|
575 |
|
576 TPtrC8 facetName; |
|
577 TInt count(otherFacets.Count()); |
|
578 for (TInt i=0; i<count && match; i++) |
|
579 { |
|
580 facetName.Set(otherFacets[i]->Name()); |
|
581 HasFacetL(facetName, match); |
|
582 } |
|
583 otherFacets.ResetAndDestroy(); |
|
584 CleanupStack::Pop(); // otherFacets |
|
585 ); |
|
586 return match; |
|
587 } |
|
588 |
|
589 // implement the MSenRemoteServiceSession: |
|
590 EXPORT_C TPtrC8 CSenServiceSession::Endpoint() |
|
591 { |
|
592 return CSenWSDescription::Endpoint(); |
|
593 } |
|
594 |
|
595 EXPORT_C TPtrC8 CSenServiceSession::Contract() |
|
596 { |
|
597 return CSenWSDescription::Contract(); |
|
598 } |
|
599 |
|
600 // implement the MSenRemoteServiceSession: |
|
601 EXPORT_C TPtrC8 CSenServiceSession::FrameworkId() |
|
602 { |
|
603 return CSenWSDescription::FrameworkId(); |
|
604 } |
|
605 |
|
606 |
|
607 EXPORT_C RFileLogger* CSenServiceSession::Log() const |
|
608 { |
|
609 return iFramework.Manager().Log(); |
|
610 } |
|
611 |
|
612 EXPORT_C void CSenServiceSession::WriteExtensionsAsXMLToL(RWriteStream& aWriteStream) |
|
613 { |
|
614 HBufC8* pFacetAsXML = NULL; |
|
615 |
|
616 TInt count(iFacets.Count()); |
|
617 for (TInt i=0; i<count; i++) |
|
618 { |
|
619 if (iFacets[i]->Name() != KCompleteMessagesFacet) |
|
620 { |
|
621 pFacetAsXML = iFacets[i]->AsXmlL(); |
|
622 CleanupStack::PushL(pFacetAsXML); |
|
623 aWriteStream.WriteL(*pFacetAsXML); |
|
624 CleanupStack::PopAndDestroy(1); // pFacetAsXML |
|
625 } |
|
626 } |
|
627 } |
|
628 |
|
629 // This base class implementation passes the properties directly to consumer's transport |
|
630 EXPORT_C TInt CSenServiceSession::SetTransportPropertiesL( const TDesC8& aProperties, |
|
631 MSenRemoteServiceConsumer& aConsumer ) |
|
632 { |
|
633 |
|
634 return aConsumer.TransportL().SetPropertiesL(aProperties, MSenLayeredProperties::ESenConsumerSessionLayer, &aConsumer); |
|
635 } |
|
636 |
|
637 EXPORT_C TInt CSenServiceSession::TransportPropertiesL(HBufC8*& aProperties, |
|
638 MSenRemoteServiceConsumer& aConsumer ) |
|
639 { |
|
640 return aConsumer.TransportL().PropertiesL(aProperties); |
|
641 } |
|
642 |
|
643 EXPORT_C MSenServiceDescription::TDescriptionClassType CSenServiceSession::DescriptionClassType() |
|
644 { |
|
645 return CSenWSDescription::DescriptionClassType(); |
|
646 } |
|
647 |
|
648 |
|
649 |
|
650 EXPORT_C MSenServiceDescription& CSenServiceSession::AsServiceDescription() |
|
651 { |
|
652 return *this; |
|
653 } |
|
654 |
|
655 EXPORT_C TInt CSenServiceSession::RemoveConsumerL(MSenRemoteServiceConsumer& aConsumer) |
|
656 { |
|
657 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel ,"CSenServiceSession::RemoveConsumerL"); |
|
658 TInt count(iConsumerList.Count()); |
|
659 TInt index(KErrNotFound); |
|
660 for ( TInt i = 0; i < count; i++ ) |
|
661 { |
|
662 MSenRemoteServiceConsumer* consumer = iConsumerList[i]; |
|
663 if ( consumer ) |
|
664 { |
|
665 if ( consumer == &aConsumer ) |
|
666 { |
|
667 // match |
|
668 index = i; |
|
669 break; |
|
670 } |
|
671 |
|
672 if ( consumer->Id() == aConsumer.Id() ) |
|
673 { |
|
674 // match |
|
675 index = i; |
|
676 break; |
|
677 } |
|
678 } |
|
679 } |
|
680 if( index != KErrNotFound ) |
|
681 { |
|
682 //CSLOG_FORMAT((aConsumer.ConnectionId() , KNormalLogLevel, _L8("- Removing consumer: %d/%d"), (index+1), iConsumerList.Count())); |
|
683 iConsumerList.Remove(index); |
|
684 index = KErrNone; // success |
|
685 //CSLOG_FORMAT((aConsumer.ConnectionId() , KNormalLogLevel, _L8("- Consumer count now: %d"), iConsumerList.Count())); |
|
686 //CSLOG_FORMAT((aConsumer.ConnectionId() , KNormalLogLevel, _L8("- Hostlet: %d"), ipHostlet?1:0)); |
|
687 //CSLOG_FORMAT((aConsumer.ConnectionId() , KNormalLogLevel, _L8("- Transport: %d"), ipTransport?1:0)); |
|
688 |
|
689 if(ipTransport && iConsumerList.Count() == 0 && !ipHostlet) |
|
690 { |
|
691 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- this session has no consumer(s) and no hostlet; deleting the transport -- START:"); |
|
692 delete ipTransport; |
|
693 CSLOG_L(aConsumer.ConnectionId() , KMinLogLevel,"- deleting transport --- END"); |
|
694 ipTransport = NULL; |
|
695 } |
|
696 } |
|
697 if (iTransportOwned) |
|
698 { |
|
699 delete ipTransport; |
|
700 ipTransport = NULL; |
|
701 } |
|
702 |
|
703 return index; |
|
704 } |
|
705 |
|
706 EXPORT_C void CSenServiceSession::SetTransportL(CSenTransportBase* aTransport) |
|
707 { |
|
708 if (aTransport) |
|
709 { |
|
710 if(ipTransport && ipTransport != aTransport) |
|
711 { |
|
712 // delete the current transport, if it does not match with new one |
|
713 delete ipTransport; // this will naturally cancel all pending txns |
|
714 ipTransport = NULL; |
|
715 } |
|
716 ipTransport = aTransport; |
|
717 iTransportOwned = aTransport->SessionOwned(); |
|
718 } |
|
719 } |
|
720 EXPORT_C MSenTransport* CSenServiceSession::Transport() const |
|
721 { |
|
722 return ipTransport; |
|
723 } |
|
724 |
|
725 EXPORT_C MSenTransport& CSenServiceSession::TransportL(MSenRemoteServiceConsumer& aRequestor) |
|
726 { |
|
727 if(!ipTransport) |
|
728 { |
|
729 MSenTransport& transport = aRequestor.TransportL(); |
|
730 ipTransport = (CSenTransportBase*) &transport; |
|
731 } |
|
732 return *ipTransport; |
|
733 } |
|
734 |
|
735 EXPORT_C TInt CSenServiceSession::SetHostletL(MSenRemoteHostlet* aHostlet) |
|
736 { |
|
737 ipHostlet = aHostlet; |
|
738 if(!ipHostlet && iConsumerList.Count() == 0) |
|
739 { |
|
740 delete ipTransport; |
|
741 ipTransport = NULL; |
|
742 } |
|
743 return KErrNone; // return value not used atm |
|
744 } |
|
745 |
|
746 EXPORT_C MSenRemoteHostlet* CSenServiceSession::Hostlet() const |
|
747 { |
|
748 return ipHostlet; |
|
749 } |
|
750 |
|
751 EXPORT_C TBool CSenServiceSession::HasSuperClass( TDescriptionClassType aType ) |
|
752 { |
|
753 if( aType == MSenServiceDescription::EWSDescription ) // direct superclass! |
|
754 { |
|
755 // If asked type is the know *direct* father/mother, return true: |
|
756 return ETrue; |
|
757 } |
|
758 else |
|
759 { |
|
760 // Otherwise, ask from superclass (chain, recursively) |
|
761 return CSenWSDescription::HasSuperClass( aType ); |
|
762 } |
|
763 } |
|
764 |
|
765 EXPORT_C TInt CSenServiceSession::SendToHostletL(MSenRemoteHostlet& aReceiver, |
|
766 const TDesC8& aMessage, |
|
767 const TInt aTxnId, |
|
768 MSenRemoteServiceConsumer& aFrom, |
|
769 MSenProperties* /* aProperties */) |
|
770 { |
|
771 // default impelementation routes the request directly to the hostlet |
|
772 // Handler aware framework could load the required handlers in here |
|
773 // to enable addressing / message correlation etc. |
|
774 return aReceiver.ProcessRequestFromConsumerL(aMessage, aTxnId, aFrom /*, aProperties */); |
|
775 } |
|
776 |
|
777 EXPORT_C TInt CSenServiceSession::ProvideHostletResponseL( MSenRemoteHostlet& /* aProvider */, |
|
778 const TInt aTxnId, |
|
779 const TInt aServiceCode, |
|
780 const TDesC8& /* aRecipientsConsumerId */, |
|
781 CSenChunk& /* aMessageChunk */ ) |
|
782 { |
|
783 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"CSenServiceSession::ProvideHostletResponseL"); |
|
784 TInt retVal(KErrNone); |
|
785 MSenTransport* pTransport = Transport(); |
|
786 if ( pTransport ) |
|
787 { |
|
788 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8("- Completing the transaction %d"), aTxnId)); |
|
789 retVal = pTransport->CompleteTransaction( aTxnId, aServiceCode ); |
|
790 } |
|
791 else |
|
792 { |
|
793 TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel ,"- Fatal - Transport is NULL."); |
|
794 retVal = KErrSenInternal; |
|
795 } |
|
796 return retVal; |
|
797 } |
|
798 |
|
799 EXPORT_C TInt CSenServiceSession::SetTransportCueL(const TDesC8& aCue) |
|
800 { |
|
801 return CSenWSDescription::SetTransportCueL(aCue); |
|
802 } |
|
803 |
|
804 EXPORT_C TPtrC8 CSenServiceSession::TransportCue() |
|
805 { |
|
806 return CSenWSDescription::TransportCue(); |
|
807 } |
|
808 |
|
809 EXPORT_C TInt CSenServiceSession::RefreshMTL(HBufC8*& /*aRevalidationError*/) |
|
810 { |
|
811 return KErrNotSupported; |
|
812 } |
|
813 |
|
814 // End of File |
|
815 |