|
1 /* |
|
2 * Copyright (c) 2002-2007 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 // INCLUDE FILES |
|
26 #include "senapplicationcontext.h" |
|
27 #include "senservercontext.h" |
|
28 #include "senclientcontext.h" |
|
29 #include "SenServiceConnection.h" // KErrSenInternal |
|
30 |
|
31 EXPORT_C CSenApplicationContext* CSenApplicationContext::NewL(TSecureId aSecureId, |
|
32 CSenServerContext& aServerContext) |
|
33 { |
|
34 CSenApplicationContext* pNew = CSenApplicationContext::NewLC(aSecureId, aServerContext); |
|
35 CleanupStack::Pop(); |
|
36 return pNew; |
|
37 } |
|
38 |
|
39 EXPORT_C CSenApplicationContext* CSenApplicationContext::NewLC(TSecureId aSecureId, |
|
40 CSenServerContext& aServerContext) |
|
41 { |
|
42 CSenApplicationContext* pNew = new (ELeave) CSenApplicationContext(aSecureId, aServerContext); |
|
43 CleanupStack::PushL(pNew); |
|
44 pNew->BaseConstructL(); |
|
45 return pNew; |
|
46 } |
|
47 |
|
48 EXPORT_C CSenApplicationContext::CSenApplicationContext(TSecureId aSecureId, |
|
49 CSenServerContext& aServerContext) |
|
50 : iSecureId(aSecureId), |
|
51 iServerContext(aServerContext), |
|
52 iClients(ETrue, ETrue) |
|
53 { |
|
54 } |
|
55 |
|
56 EXPORT_C CSenApplicationContext::~CSenApplicationContext() |
|
57 { |
|
58 } |
|
59 |
|
60 EXPORT_C void CSenApplicationContext::BaseConstructL() |
|
61 { |
|
62 // CSenContext::BaseConstructL(); |
|
63 } |
|
64 |
|
65 CSenServerContext& CSenApplicationContext::ServerContext() const |
|
66 { |
|
67 return iServerContext; |
|
68 } |
|
69 |
|
70 TSecureId CSenApplicationContext::SecureId() const |
|
71 { |
|
72 return iSecureId; |
|
73 } |
|
74 |
|
75 CSenClientContext& CSenApplicationContext::OpenClientContextL(TInt aClientId) |
|
76 { |
|
77 CSenClientContext* pCtx = NULL; |
|
78 // Check if requested client context already exists, held by this server context |
|
79 TInt index = iClients.Find( aClientId ); |
|
80 if ( index == KErrNotFound ) |
|
81 { |
|
82 // New client context needs to be created |
|
83 pCtx = CSenClientContext::NewLC(aClientId, *this ); |
|
84 TInt* pClientId = new (ELeave) TInt(aClientId); |
|
85 TInt err = iClients.Append( pClientId, pCtx ); |
|
86 if( err ) |
|
87 { |
|
88 // Append failed: cleanup and leave |
|
89 delete pClientId; // de-alloc this orphan |
|
90 CleanupStack::PopAndDestroy( pCtx ); |
|
91 User::Leave( err ); |
|
92 } |
|
93 else |
|
94 { |
|
95 // Remove the new context from cleanup stack, |
|
96 // it is now owned by this application context |
|
97 CleanupStack::Pop( pCtx ); |
|
98 } |
|
99 } |
|
100 else |
|
101 { |
|
102 // Return the existing client context |
|
103 pCtx = (CSenClientContext*)iClients.ValueAt( index ); |
|
104 if( !pCtx ) |
|
105 { |
|
106 // Should NOT occur: map failed => leave with internal error code |
|
107 User::Leave( KErrSenInternal ); |
|
108 } |
|
109 } |
|
110 return *pCtx; |
|
111 } |
|
112 |
|
113 TInt CSenApplicationContext::CloseClientContext(const CSenClientContext& aCtx) |
|
114 { |
|
115 TInt retVal(KErrNotFound); |
|
116 if ( aCtx.iSessions.Count() == 0 ) |
|
117 { |
|
118 // Note: RemoveByKey returns KErrNotFound or index of removed item(!) |
|
119 retVal = iClients.RemoveByKey( aCtx.ClientId() ); |
|
120 if( retVal != KErrNotFound ) |
|
121 { |
|
122 retVal = KErrNone; |
|
123 } |
|
124 } |
|
125 else |
|
126 { |
|
127 retVal = KErrInUse; |
|
128 } |
|
129 return retVal; |
|
130 } |
|
131 |
|
132 // From MSenApplicationContext: |
|
133 /* |
|
134 SenContext::TContextType CSenApplicationContext::Type() const |
|
135 { |
|
136 return SenContext::EMessageContext; |
|
137 } |
|
138 |
|
139 SenContext::TContextDirection CSenApplicationContext::Direction() const |
|
140 { |
|
141 return CSenContext::Direction(); |
|
142 } |
|
143 |
|
144 TInt CSenApplicationContext::Add(const TDesC8& aKey, const TDesC8& aValue) |
|
145 { |
|
146 return CSenContext::Add( aKey, aValue ); |
|
147 } |
|
148 |
|
149 TInt CSenApplicationContext::Update(const TDesC8& aKey, const TDesC8& aValue) |
|
150 { |
|
151 return CSenContext::Update( aKey, aValue ); |
|
152 } |
|
153 |
|
154 const TDesC8* CSenApplicationContext::GetDesC8L(const TDesC8& aKey) |
|
155 { |
|
156 return CSenContext::GetDesC8L( aKey ); |
|
157 } |
|
158 |
|
159 TInt CSenApplicationContext::Add(const TDesC8& aKey, TInt aValue) |
|
160 { |
|
161 return CSenContext::Add( aKey, aValue ); |
|
162 } |
|
163 |
|
164 TInt CSenApplicationContext::Update(const TDesC8& aKey, TInt aValue) |
|
165 { |
|
166 return CSenContext::Update( aKey, aValue ); |
|
167 } |
|
168 |
|
169 const TInt* CSenApplicationContext::GetIntL(const TDesC8& aKey) |
|
170 { |
|
171 return CSenContext::GetIntL( aKey ); |
|
172 } |
|
173 |
|
174 TInt CSenApplicationContext::Add(const TDesC8& aKey, CSenElement* aValue) |
|
175 { |
|
176 return CSenContext::Add( aKey, aValue ); |
|
177 } |
|
178 |
|
179 TInt CSenApplicationContext::Update(const TDesC8& aKey, CSenElement* aValue) |
|
180 { |
|
181 return CSenContext::Update( aKey, aValue ); |
|
182 } |
|
183 |
|
184 const CSenElement* CSenApplicationContext::GetSenElementL(const TDesC8& aKey) |
|
185 { |
|
186 return CSenContext::GetSenElementL( aKey ); |
|
187 } |
|
188 |
|
189 TInt CSenApplicationContext::Add(const TDesC8& aKey, TAny* aValue) |
|
190 { |
|
191 return CSenContext::Add( aKey, aValue ); |
|
192 } |
|
193 |
|
194 TInt CSenApplicationContext::Update(const TDesC8& aKey, TAny* aValue) |
|
195 { |
|
196 return CSenContext::Update( aKey, aValue ); |
|
197 } |
|
198 |
|
199 TAny* CSenApplicationContext::GetAny(const TDesC8& aKey) |
|
200 { |
|
201 return CSenContext::GetAny( aKey ); |
|
202 } |
|
203 |
|
204 TInt CSenApplicationContext::Remove(const TDesC8& aKey) |
|
205 { |
|
206 return CSenContext::Remove(aKey); |
|
207 } |
|
208 |
|
209 TInt CSenApplicationContext::Count() const |
|
210 { |
|
211 return CSenContext::Count(); |
|
212 } |
|
213 |
|
214 TPtrC8 CSenApplicationContext::KeyAtL(TInt aIndex) |
|
215 { |
|
216 return CSenContext::KeyAtL(aIndex); |
|
217 } |
|
218 |
|
219 void CSenApplicationContext::Reset() |
|
220 { |
|
221 CSenContext::Reset(); |
|
222 } |
|
223 |
|
224 CSenSoapMessage* CSenApplicationContext::GetCurrentSoapMessage() // DEPRECATED: |
|
225 { |
|
226 CSenSoapMessage* pSoapMessage = NULL; |
|
227 |
|
228 TInt index = iItems.Find( KSenCtxKeyCurrentSoapMessage ); |
|
229 if ( index != KErrNotFound ) |
|
230 { |
|
231 const CSenContextItem* pItem = iItems.ValueAt(index); |
|
232 pSoapMessage = &(pItem->ToSenSoapMessageL()); |
|
233 } |
|
234 return pSoapMessage; |
|
235 } |
|
236 |
|
237 TPtrC8 CSenApplicationContext::GetMessage() |
|
238 { |
|
239 TInt index = iItems.Find( KSenCtxKeyCurrentMessageAsDesc ); |
|
240 if ( index != KErrNotFound ) |
|
241 { |
|
242 const CSenContextItem* pItem = iItems.ValueAt(index); |
|
243 const TDesC8* desc = pItem->ToDesC8L(); |
|
244 return *desc; |
|
245 } |
|
246 return KNullDesC8(); |
|
247 } |
|
248 |
|
249 TInt CSenApplicationContext::Add(const TDesC8& aKey, CSenSoapEnvelope* aValue) |
|
250 { |
|
251 return CSenContext::Add( aKey, aValue ); |
|
252 } |
|
253 |
|
254 TInt CSenApplicationContext::Update(const TDesC8& aKey, CSenSoapEnvelope* aValue) |
|
255 { |
|
256 return CSenContext::Update( aKey, aValue ); |
|
257 } |
|
258 |
|
259 const CSenSoapEnvelope* CSenApplicationContext::GetSenSoapEnvelopeL(const TDesC8& aKey) |
|
260 { |
|
261 TInt index = iItems.Find( aKey ); |
|
262 if ( index != KErrNotFound ) |
|
263 { |
|
264 const CSenContextItem* pItem = iItems.ValueAt(index); |
|
265 const CSenSoapEnvelope* envelope = ((CSenSoapEnvelope*)&(pItem->ToSenSoapMessageL())); |
|
266 return envelope; |
|
267 } |
|
268 return NULL; |
|
269 } |
|
270 |
|
271 MSenMessage* CSenApplicationContext::Message() |
|
272 { |
|
273 TInt index = iItems.Find( KSenCtxKeyMessage ); |
|
274 if ( index != KErrNotFound ) |
|
275 { |
|
276 const CSenContextItem* pItem = iItems.ValueAt(index); |
|
277 return ((MSenMessage*)&(pItem->ToSenMessageL())); |
|
278 } |
|
279 return NULL; |
|
280 } |
|
281 |
|
282 TInt CSenApplicationContext::SetMessage(MSenMessage* apMessage, TBool aOwned) |
|
283 { |
|
284 TInt leaveCode(KErrNone); |
|
285 CSenContextItem* pItem = MessageToItem( apMessage, aOwned, leaveCode ); |
|
286 |
|
287 if( leaveCode != KErrNone ) |
|
288 { |
|
289 delete pItem; // should ALWAYS be NULL(!) |
|
290 return leaveCode; |
|
291 } |
|
292 |
|
293 TInt retCode(iItems.UpdateValue(&KSenCtxKeyMessage(), pItem)); |
|
294 if( retCode != KErrNone && aOwned ) |
|
295 { |
|
296 delete pItem; // delete the orphan item |
|
297 } |
|
298 return retCode; |
|
299 } |
|
300 |
|
301 |
|
302 CSenChunk* CSenApplicationContext::Chunk() |
|
303 { |
|
304 TInt index = iItems.Find( KSenCtxKeyChunk ); |
|
305 if ( index != KErrNotFound ) |
|
306 { |
|
307 const CSenContextItem* pItem = iItems.ValueAt(index); |
|
308 return ((CSenChunk*)&(pItem->ToSenChunkL())); |
|
309 } |
|
310 return NULL; |
|
311 } |
|
312 |
|
313 TInt CSenApplicationContext::SetChunk(CSenChunk* apMsgAsChunk, TBool aOwned) |
|
314 { |
|
315 TInt leaveCode(KErrNone); |
|
316 |
|
317 CSenContextItem* pItem = NULL; |
|
318 if( aOwned ) |
|
319 { |
|
320 TRAP( leaveCode, pItem = CSenContextItem::NewL(apMsgAsChunk); ) |
|
321 } |
|
322 else // chunk is not to be owned |
|
323 { |
|
324 TRAP( leaveCode, pItem = CSenContextItem::NewL(*apMsgAsChunk); ) |
|
325 } |
|
326 |
|
327 if( leaveCode != KErrNone ) |
|
328 { |
|
329 delete pItem; // should ALWAYS be NULL(!) |
|
330 return leaveCode; |
|
331 } |
|
332 |
|
333 TInt retCode(iItems.UpdateValue(&KSenCtxKeyChunk(), pItem)); |
|
334 if( retCode != KErrNone && aOwned ) |
|
335 { |
|
336 delete pItem; // delete the orphan item |
|
337 } |
|
338 return retCode; |
|
339 } |
|
340 |
|
341 |
|
342 TInt CSenApplicationContext::SetProperties(MSenProperties* apProperties, TBool aOwned) |
|
343 { |
|
344 if( !apProperties ) |
|
345 { |
|
346 return KErrArgument; |
|
347 } |
|
348 |
|
349 TInt retCode(KErrNone); |
|
350 if ( aOwned ) |
|
351 { |
|
352 delete ipOwnedTp; |
|
353 ipOwnedTp = NULL; |
|
354 ipOwnedTp = apProperties; |
|
355 } |
|
356 else |
|
357 { |
|
358 |
|
359 CSenContextItem* pItem = NULL; |
|
360 TInt leaveCode(KErrNone); |
|
361 // if( aOwned ) |
|
362 // { |
|
363 // TRAP( leaveCode, pItem = CSenContextItem::NewL(apProperties); ) |
|
364 // } |
|
365 // else // chunk is not to be owned |
|
366 // { |
|
367 TRAP( leaveCode, pItem = CSenContextItem::NewL(*apProperties); ) |
|
368 // } |
|
369 |
|
370 if( leaveCode != KErrNone ) |
|
371 { |
|
372 delete pItem; // should ALWAYS be NULL(!) |
|
373 return leaveCode; |
|
374 } |
|
375 |
|
376 retCode = iItems.UpdateValue(&KSenCtxKeyChunk(), pItem); |
|
377 if( retCode != KErrNone && aOwned ) |
|
378 { |
|
379 delete pItem; // delete the orphan item |
|
380 } |
|
381 } |
|
382 return retCode; |
|
383 } |
|
384 |
|
385 |
|
386 MSenProperties* CSenApplicationContext::Properties() |
|
387 { |
|
388 if( ipOwnedTp ) |
|
389 { |
|
390 return ipOwnedTp; |
|
391 } |
|
392 else |
|
393 { |
|
394 TInt index = iItems.Find( KSenCtxKeyMessageProperties ); |
|
395 if ( index != KErrNotFound ) |
|
396 { |
|
397 const CSenContextItem* pItem = iItems.ValueAt(index); |
|
398 if( pItem->Type() == MSenContextItem::EMSenProperties ) |
|
399 { |
|
400 MSenProperties* pProperties = (MSenProperties*)pItem; |
|
401 return pProperties; |
|
402 } |
|
403 } |
|
404 return NULL; |
|
405 } |
|
406 } |
|
407 |
|
408 // Method for adding an "intermediate" message behind certain key; used normally to conduct final "service message" |
|
409 TInt CSenApplicationContext::Add(const TDesC8& aKey, MSenMessage* apMessage, TBool aOwned) |
|
410 { |
|
411 if( iItems.Count() > 0 && iItems.Find(aKey) != KErrNotFound ) |
|
412 { |
|
413 return KErrAlreadyExists; |
|
414 } |
|
415 |
|
416 TInt leaveCode(KErrNone); |
|
417 CSenContextItem* pItem = MessageToItem( apMessage, aOwned, leaveCode ); |
|
418 if( leaveCode != KErrNone ) |
|
419 { |
|
420 return leaveCode; |
|
421 } |
|
422 |
|
423 TInt retCode(iItems.Append(&aKey, pItem)); |
|
424 if( retCode != KErrNone ) |
|
425 { |
|
426 delete pItem; |
|
427 } |
|
428 return retCode; |
|
429 } |
|
430 |
|
431 // Method for updating some "intermediate" message behind certain key; used normally to conduct final "service message" |
|
432 TInt CSenApplicationContext::Update(const TDesC8& aKey, MSenMessage* apMessage, TBool aOwned) |
|
433 { |
|
434 TInt leaveCode(KErrNone); |
|
435 CSenContextItem* pItem = MessageToItem( apMessage, aOwned, leaveCode ); |
|
436 if( leaveCode != KErrNone ) |
|
437 { |
|
438 return leaveCode; |
|
439 } |
|
440 |
|
441 TInt retCode(iItems.UpdateValue(&aKey, pItem)); |
|
442 if( retCode != KErrNone && aOwned ) |
|
443 { |
|
444 delete pItem; |
|
445 } |
|
446 return retCode; |
|
447 } |
|
448 |
|
449 // Method for getting "intermediate" message behind certain key; used normally to conduct final "service message" |
|
450 MSenMessage* CSenApplicationContext::GetMessage(const TDesC8& aKey) |
|
451 { |
|
452 TInt index = iItems.Find(aKey); |
|
453 if ( index != KErrNotFound ) |
|
454 { |
|
455 const CSenContextItem* pItem = iItems.ValueAt(index); |
|
456 if(pItem) |
|
457 { |
|
458 return &pItem->ToSenMessageL(); |
|
459 } |
|
460 } |
|
461 return NULL; |
|
462 } |
|
463 |
|
464 // private helper method(s): |
|
465 CSenContextItem* CSenApplicationContext::MessageToItem(MSenMessage* apMessage, TBool aOwned, TInt& aError) |
|
466 { |
|
467 aError = KErrNone; |
|
468 CSenContextItem* pItem = NULL; |
|
469 if( aOwned ) |
|
470 { |
|
471 if( apMessage->IsSafeToCast( MSenMessage::EMessageBase ) ) |
|
472 { |
|
473 CSenMessageBase* msgBase = (CSenMessageBase*) apMessage; |
|
474 TRAP( aError, pItem = CSenContextItem::NewL( msgBase ); ) |
|
475 } |
|
476 else if ( apMessage->IsSafeToCast( MSenMessage::ESoapEnvelope2 ) ) |
|
477 { |
|
478 CSenSoapEnvelope2* msgSoap2 = (CSenSoapEnvelope2*) apMessage; |
|
479 TRAP( aError, pItem = CSenContextItem::NewL( msgSoap2 ); ) |
|
480 } |
|
481 else |
|
482 { |
|
483 aError = KErrNotSupported; |
|
484 return NULL; |
|
485 } |
|
486 } |
|
487 else // provided message is *not to be owned* |
|
488 { |
|
489 TRAP( aError, pItem = CSenContextItem::NewL(*apMessage); ) |
|
490 } |
|
491 return pItem; |
|
492 } |
|
493 |
|
494 TInt CSenApplicationContext::SetDirection( SenContext::TContextDirection aDirection ) |
|
495 { |
|
496 CSenContext::SetDirection( aDirection ); |
|
497 return KErrNone; |
|
498 } |
|
499 |
|
500 const CSenXmlReader* CSenApplicationContext::GetParser() |
|
501 { |
|
502 return CSenContext::GetParser(); |
|
503 } |
|
504 */ |
|
505 // End of file |
|
506 |