|
1 /* |
|
2 * Copyright (c) 2003 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: Class for describing imps sub session including Auxiliary class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CImpsSubSession_H |
|
20 #define CImpsSubSession_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <e32std.h> |
|
25 #include "impsclientsrv.h" |
|
26 |
|
27 // FORWARD DECLARATIONS |
|
28 class CImpsServer; |
|
29 class CImpsSession; |
|
30 class CImpsVariant; |
|
31 class CWvEvent; |
|
32 class CRequest; |
|
33 |
|
34 // CONSTANTS |
|
35 const TInt KImpsMaxBuffered = 10; // max nbr of queued events |
|
36 |
|
37 // CLASS DECLARATION |
|
38 |
|
39 /** |
|
40 * Auxiliary class to store OOM error op-id |
|
41 */ |
|
42 class TImpsOOMError |
|
43 { |
|
44 public: |
|
45 |
|
46 TImpsOOMError(); |
|
47 |
|
48 void SetOpId( TInt aOpId ); |
|
49 |
|
50 TInt OpId(); |
|
51 |
|
52 void SetAsSent(); |
|
53 |
|
54 TBool IsSent(); |
|
55 |
|
56 private: |
|
57 TInt iOpId; |
|
58 TBool iSent; |
|
59 }; |
|
60 |
|
61 /** |
|
62 * Auxiliary class to store OOM error op-id:s |
|
63 */ |
|
64 class TImpsOOMErrors |
|
65 { |
|
66 |
|
67 public: |
|
68 /** |
|
69 * Store error |
|
70 * @param aOpCode op-id that has failed |
|
71 */ |
|
72 void StoreOOM( TInt aOpCode ); |
|
73 |
|
74 /** |
|
75 * Get next OOM error and set is as a sent message. |
|
76 * @return op-id, 0 if not found any. |
|
77 */ |
|
78 TInt GetOOM(); |
|
79 |
|
80 /** |
|
81 * Remove the sent OOM error |
|
82 * @return op-id, 0 if not found any. |
|
83 */ |
|
84 TInt RemoveOOM(); |
|
85 |
|
86 /** |
|
87 * Clean opid codes |
|
88 */ |
|
89 void Reset(); |
|
90 |
|
91 /** |
|
92 * Check if there are OOM erros in the queue |
|
93 * @return ETrue if there are such errors |
|
94 */ |
|
95 TBool Exists(); |
|
96 |
|
97 private: |
|
98 TInt iR; |
|
99 TInt iW; |
|
100 TFixedArray<TImpsOOMError, KImpsMaxBuffered> iOOMList; |
|
101 |
|
102 }; |
|
103 |
|
104 /** |
|
105 * SOS Client-server framework sub-session for WV engine |
|
106 */ |
|
107 class CImpsSubSession : public CObject |
|
108 { |
|
109 public: // Constructors and destructor |
|
110 |
|
111 /** |
|
112 * Constructor |
|
113 * @param aSession client-server parent session |
|
114 * @param aType subsession type |
|
115 * @param aMessage service request from client |
|
116 * @return subsession entity |
|
117 */ |
|
118 static CImpsSubSession* NewL( |
|
119 CImpsSession* aSession, |
|
120 TImpsEventType aType, |
|
121 const RMessage2 aMessage ); |
|
122 |
|
123 /** |
|
124 * Destructor. |
|
125 */ |
|
126 virtual ~CImpsSubSession(); |
|
127 |
|
128 public: // New functions |
|
129 |
|
130 /** |
|
131 * Assign new id, that causes orphan message check. |
|
132 * @param sCSP CSP connection id |
|
133 */ |
|
134 void AssignIdL( TImpsSessIdent aCSP ); |
|
135 |
|
136 /** |
|
137 * Causes orphan message check. |
|
138 * @param sCSP CSP connection id |
|
139 */ |
|
140 void HandleAllOrphans( TImpsSessIdent aCSP ); |
|
141 |
|
142 /** |
|
143 * Search pending request using CSP transaction-id |
|
144 * @param aTid transaction-id |
|
145 * @param aOpId op-id if matching one found (OUT) |
|
146 * @param aRequestType request type if found (OUT) |
|
147 * @param aReqMsgType request CSP primitive if found (OUT) |
|
148 * @return ETrue if search match |
|
149 */ |
|
150 TBool CheckRequests( |
|
151 const TDesC& aTid, |
|
152 TInt& aOpId, |
|
153 TImpsServRequest& aRequestType, |
|
154 TImpsMessageType& aReqMsgType ); |
|
155 |
|
156 /** |
|
157 * Discard expired pending requests and send error event to client |
|
158 * @param aExpiryTime expiry time interval |
|
159 * @param aServiceType service type considered |
|
160 */ |
|
161 void DiscardRequests( |
|
162 TTime aExpiryTime, |
|
163 TImpsEventType aServiceType, |
|
164 MImpsCSPSession* aSess ); |
|
165 |
|
166 /** |
|
167 * Discard all pending requests and send error event to client |
|
168 * @param aError error code to be sent |
|
169 * @param aServiceType service type considered |
|
170 */ |
|
171 void DiscardRequests( |
|
172 TInt aError, |
|
173 TImpsEventType aServiceType, |
|
174 MImpsCSPSession* aSess ); |
|
175 |
|
176 /** |
|
177 * Discard a pending request and send error event to client |
|
178 * @param aTid transaction-id |
|
179 * @param aServiceType service type considered |
|
180 * @param aCode error code |
|
181 * @return ETrue if request found and deleted |
|
182 */ |
|
183 TBool DiscardRequest( |
|
184 const TDesC& aTid, |
|
185 TImpsEventType aServiceType, |
|
186 TInt aCode ); |
|
187 |
|
188 /** |
|
189 * Send or buffer new event to client |
|
190 * @param aFields data to be sent |
|
191 * @param aOpId corresponding op-id |
|
192 * @param aRequestType request type |
|
193 * @param aReqMsgType requesting CSP primitive starting |
|
194 * transaction if this client has initiated it. |
|
195 */ |
|
196 void SendEvent( |
|
197 CImpsFields* aFields, |
|
198 TInt aOpId, |
|
199 TImpsServRequest aRequestType, |
|
200 TImpsMessageType aReqMsgType ); |
|
201 |
|
202 /** |
|
203 * Send or buffer new status event to client |
|
204 * @param aStatus new status |
|
205 */ |
|
206 void SendEvent( |
|
207 EImpsInternalStatus aStatus ); |
|
208 |
|
209 /** |
|
210 * Send Logout event only for Access clients (=session type) |
|
211 * @param aRespStatus response status caused this |
|
212 * @param aOpId op-id, optional |
|
213 */ |
|
214 void SendLogoutEvent( TInt aRespStatus, TInt aOpId = 0 ); |
|
215 |
|
216 /** |
|
217 * Send Login event only for Access clients (=session type). |
|
218 * This can be used when existing CSP session is shared between |
|
219 * client sessions. |
|
220 * @param aRespStatus response status caused this |
|
221 * @param aOpId op-id, optional |
|
222 */ |
|
223 void SendLoginEvent( TInt aRespStatus, TInt aOpId = 0 ); |
|
224 |
|
225 /** |
|
226 * Send OOM error event |
|
227 * @return ETrue if OOM event was found and sent. |
|
228 */ |
|
229 TBool SendOOMError(); |
|
230 |
|
231 /** |
|
232 * Check if notification should be sent when TID not given |
|
233 * This means usually SAP originated transaction. |
|
234 * Takes care of content type limitations and filters |
|
235 * new messages off if they are not wanted in this subsession. |
|
236 * @param aFields data received from SAP. |
|
237 * @return ETrue if data should be sent to a client thread of |
|
238 * this Symbian client-server session. |
|
239 */ |
|
240 TBool CheckNotification( CImpsFields* aFields ); |
|
241 |
|
242 /** |
|
243 * Cancel the subsession. |
|
244 * Sends number of pending events to client. |
|
245 */ |
|
246 void Unregister(); |
|
247 |
|
248 /** |
|
249 * Deletes this subsession. |
|
250 * Removes this entity finally. |
|
251 */ |
|
252 void DeleteSub(); |
|
253 |
|
254 /** |
|
255 * Delete all pending events |
|
256 * @return number of events outstanding |
|
257 */ |
|
258 TInt DeleteAllEvents(); |
|
259 |
|
260 /** |
|
261 * Delete all waiting requests. |
|
262 */ |
|
263 void DeleteAllRequests(); |
|
264 |
|
265 /** |
|
266 * Delete a specified client request |
|
267 * @param aOpId corresponding op-id |
|
268 * @return ETrue if request found |
|
269 */ |
|
270 TBool DeleteRequest( TInt aOpId ); |
|
271 |
|
272 /** |
|
273 * Login |
|
274 * @param aReactive reactive presence auth negotiation |
|
275 */ |
|
276 void LoginL( TBool aReactive ); |
|
277 |
|
278 /** |
|
279 * Logout |
|
280 * @param sCSP CSP connection id |
|
281 * @param aCancel ETrue if Login cancel functionality wanted |
|
282 * @return CSP TID |
|
283 */ |
|
284 TPtrC LogoutL( TImpsSessIdent aCSP, TBool aCancel ); |
|
285 |
|
286 /** |
|
287 * Send CSP Primitive to SAP |
|
288 * @param aFunction client-server command |
|
289 * @param sCSP CSP connection id |
|
290 */ |
|
291 void SendPrimitiveL( const TInt aFunction, TImpsSessIdent aCSP ); |
|
292 |
|
293 /** |
|
294 * Generate and send GetBlokedlist primitive to SAP |
|
295 * @param sCSP CSP connection id |
|
296 */ |
|
297 void SendGetBlockedL( TImpsSessIdent aCSP ); |
|
298 |
|
299 /** |
|
300 * Serve next event request from client |
|
301 * @param aMsg next event request |
|
302 */ |
|
303 void NextEventL( const RMessage2& aMsg ); |
|
304 |
|
305 /** |
|
306 * Serve event body request from client |
|
307 * @param aMsg next event request |
|
308 */ |
|
309 void SendEventBodyL( const RMessage2& aMsg ); |
|
310 |
|
311 /** |
|
312 * Client cancels transaction. |
|
313 * @param aMsg client-server message including opid |
|
314 * @param sCSP CSP connection id |
|
315 * @return ETrue if request is found and cancelled |
|
316 */ |
|
317 TBool CancelTrans( RMessagePtr2 aMsg, TImpsSessIdent aCSP ); |
|
318 |
|
319 /** |
|
320 * Request expiry time mutator |
|
321 * @param aMsg client request |
|
322 */ |
|
323 void SetExpiryTime( RMessagePtr2 aMsg ); |
|
324 |
|
325 /** |
|
326 * Request expiry time mutator |
|
327 * @param aVal time in seconds, ignored if not > 0. |
|
328 */ |
|
329 void SetExpiryTime( TInt aVal ); |
|
330 |
|
331 /** |
|
332 * Request expiry time accessor |
|
333 * @return request expiry time in seconds |
|
334 */ |
|
335 TInt ExpiryTime(); |
|
336 |
|
337 /** |
|
338 * Indicate that the message request has been completed ??? |
|
339 */ |
|
340 inline void SetCompleted(); |
|
341 |
|
342 /** |
|
343 * Get current message of this session |
|
344 * That's for CImpsServer only |
|
345 * @return last data sent by client API |
|
346 */ |
|
347 inline CImpsFields* ImpsFields() const; |
|
348 |
|
349 /** |
|
350 * Get buffer for streamed message |
|
351 * return buffer |
|
352 */ |
|
353 inline HBufC8* StreamBuf() const; |
|
354 |
|
355 /** |
|
356 * Get buffer for streamed message |
|
357 * return buffer |
|
358 */ |
|
359 inline HBufC8** StreamBufAddr(); |
|
360 |
|
361 /** |
|
362 * Create new data structure without deleting old one. |
|
363 * This calls session's NewFieldsL |
|
364 */ |
|
365 inline void NewFieldsL(); |
|
366 |
|
367 /** |
|
368 * Is status observer on/off |
|
369 * @return ETrue if client has registered status observer |
|
370 */ |
|
371 inline TBool StatusObserver() const; |
|
372 |
|
373 /** |
|
374 * Event (service) type of this session |
|
375 * @return event type |
|
376 */ |
|
377 inline TImpsEventType Type() const; |
|
378 |
|
379 /** |
|
380 * iStatusObserver mutator |
|
381 * @param ETrue if status observer is set |
|
382 */ |
|
383 inline void SetStatusObserver( TBool aVal ); |
|
384 |
|
385 /** |
|
386 * iDetailedError mutator |
|
387 * @param ETrue if detailed error observer is set |
|
388 */ |
|
389 inline void SetDetailedError( TBool aVal ); |
|
390 |
|
391 /** |
|
392 * Handle Mutator |
|
393 * @param aVal subsession handle |
|
394 */ |
|
395 inline void SetHandle( TUint aVal ); |
|
396 |
|
397 /** |
|
398 * Handle Accessor |
|
399 * @return subsession handle |
|
400 */ |
|
401 inline TUint Handle( ); |
|
402 |
|
403 /** |
|
404 * Logout operation id accessor |
|
405 * @return iLogOpId |
|
406 */ |
|
407 inline TInt LogOpId(); |
|
408 |
|
409 protected: |
|
410 |
|
411 /** |
|
412 * Constructor |
|
413 * @param aSession client-server parent session |
|
414 * @param aType subsession type |
|
415 * @param aMessage service request from client |
|
416 */ |
|
417 void ConstructL( |
|
418 CImpsSession* aSession, |
|
419 TImpsEventType aType, |
|
420 const RMessage2 aMessage ); |
|
421 |
|
422 const RMessagePtr2 Message() const; |
|
423 |
|
424 CImpsServer* Server(); |
|
425 |
|
426 |
|
427 private: // New functions |
|
428 |
|
429 /** |
|
430 * Send regular event |
|
431 * @param aEvent event |
|
432 */ |
|
433 void DoSendBaseEvent( CWvEvent& aEvent ); |
|
434 |
|
435 /** |
|
436 * Send regular event headers to client thread (short message or error) |
|
437 * @param aEvent event |
|
438 */ |
|
439 void DoSendEventHeader( CWvEvent& aEvent ); |
|
440 |
|
441 /** |
|
442 * Send event including message body to client thread |
|
443 * @param aEvent event |
|
444 */ |
|
445 void DoSendEventBody( CWvEvent& aEvent ); |
|
446 |
|
447 /** |
|
448 * Create event item for IPC |
|
449 * @param aEvent event (IN) |
|
450 * @param aData IPC data (OUT) |
|
451 */ |
|
452 void DoCreateEventIPC( CWvEvent& aEvent, SImpsEventData* aData ); |
|
453 |
|
454 /** |
|
455 * Write event headers |
|
456 * @param aMsg client-server message |
|
457 * @param aData serialized IPC data |
|
458 * @return error code |
|
459 */ |
|
460 TInt DoWriteEventHeaders( RMessagePtr2 aMsg, const TDes& aData ); |
|
461 |
|
462 /** |
|
463 * Write event body |
|
464 * @param aMsg client-server message |
|
465 * @param aEvent event including serialized message body |
|
466 * @return error code |
|
467 */ |
|
468 TInt DoWriteEventBody( RMessagePtr2 aMsg, CWvEvent& aEvent ); |
|
469 |
|
470 /** |
|
471 * Send next event headers to a client |
|
472 */ |
|
473 void DoNextEvent(); |
|
474 |
|
475 /** |
|
476 * Send event body to a client |
|
477 */ |
|
478 void DoEventBodyL(); |
|
479 |
|
480 /** |
|
481 * Read serialized message data from client thread |
|
482 * Converts serialized message to internal data structure. |
|
483 */ |
|
484 void GetWVDataL(); |
|
485 |
|
486 // By default, prohibit copy constructor |
|
487 CImpsSubSession( const CImpsSubSession& ); |
|
488 // Prohibit assigment operator |
|
489 CImpsSubSession& operator= ( const CImpsSubSession& ); |
|
490 |
|
491 /** |
|
492 * Create an event entity and add it to event queue |
|
493 * @param aOpId op-id returned if match |
|
494 * @param aRequestType request type returned if match |
|
495 * @param aReqMesType request message type |
|
496 * @param aFields source data to be sent to client thread |
|
497 */ |
|
498 void DoCreateEventL( |
|
499 TInt aOpId, |
|
500 TImpsServRequest aRequestType, |
|
501 TImpsMessageType aReqMesType, |
|
502 CImpsFields* aFields ); |
|
503 |
|
504 /** |
|
505 * Create an status event entity and add it to event queue |
|
506 * @param aStatus new engine status |
|
507 */ |
|
508 void DoCreateEventL( |
|
509 EImpsInternalStatus aStatus ); |
|
510 |
|
511 /** |
|
512 * Create internal error events, like expiry events |
|
513 * @param aOpCode op-id |
|
514 * @param aStatus status |
|
515 * @param aReqMesType requesting CSP primitive |
|
516 * @param aRcvMesType received CSP primitive, optional |
|
517 * @param aReqType corresponding client-server request, optional |
|
518 */ |
|
519 void DoCreateEventL( |
|
520 TInt aOpCode, |
|
521 TInt aStatus, |
|
522 TImpsMessageType aReqMesType, |
|
523 TImpsMessageType aRcvMesType = EImpsMessageNone, |
|
524 TImpsServRequest aReqType = EImpsServNone ); |
|
525 |
|
526 /** |
|
527 * Split and convert GroupChnageNotice to |
|
528 * HandleNewUsersL, HandleLeftUsersL and HandleGroupEventsL events. |
|
529 * @param aOpId op-id returned if match |
|
530 * @param aRequestType request type returned if match |
|
531 * @param aFields source data to be sent to client thread |
|
532 */ |
|
533 void DoSplitGroupChangeL( |
|
534 TInt aOpId, |
|
535 TImpsServRequest aRequestType, |
|
536 CImpsFields* aFields ); |
|
537 |
|
538 /** |
|
539 * Check if notification should be sent when TID not given |
|
540 * This means usually SAP originated transaction. |
|
541 * Takes care of content type limitations and filters |
|
542 * new messages off if they are not wanted in this subsession. |
|
543 * @param aFields data received from SAP. |
|
544 * @return ETrue if data should be sent to a client thread of |
|
545 * this Symbian client-server session. |
|
546 */ |
|
547 TBool DoCheckNotificationL( CImpsFields* aFields ); |
|
548 |
|
549 /** |
|
550 * Send online status event to client thread |
|
551 * @param aEvent status event |
|
552 */ |
|
553 void DoSendStatusEvent( CWvEvent& aEvent ); |
|
554 |
|
555 /** |
|
556 * Convert CSP error code to IMPS error code used in client API. |
|
557 * @param aCSPError CSP error code |
|
558 * @return IMPS error code |
|
559 */ |
|
560 TInt ErrorCode( TInt aCSPError ); |
|
561 |
|
562 /** |
|
563 * Event counter |
|
564 * @return number of events in queue |
|
565 */ |
|
566 TInt NbrEvents(); |
|
567 |
|
568 /** |
|
569 * Store event msg pointer |
|
570 * @param aMsg client-server message |
|
571 */ |
|
572 void StoreEventMsg( RMessagePtr2 aMsg ); |
|
573 |
|
574 /** |
|
575 * Complete event msg pointer and delete it from a queue |
|
576 * @param aStatus completion status |
|
577 */ |
|
578 void CompleteEventMsg( TInt aStatus ); |
|
579 |
|
580 /** |
|
581 * Next Message request accessor |
|
582 * @return message |
|
583 */ |
|
584 inline RMessagePtr2 EventMsg(); |
|
585 |
|
586 /** |
|
587 * Event buffer size in client thread |
|
588 * @return buffer size |
|
589 */ |
|
590 TInt EventMsgBufSize( ) const; |
|
591 |
|
592 /** |
|
593 * C++ default constructor. |
|
594 */ |
|
595 CImpsSubSession( ); |
|
596 |
|
597 /** |
|
598 * Convert interna status code to a special error code for IPC |
|
599 * @param aStatus status code |
|
600 * @return error code |
|
601 */ |
|
602 TInt ConvertStatusCode( EImpsInternalStatus aStatus ) const; |
|
603 |
|
604 |
|
605 |
|
606 private: // Data |
|
607 TBool iCanceled; |
|
608 TImpsEventType iServiceType; |
|
609 TBool iHandleNew; |
|
610 |
|
611 // Event queue |
|
612 TDblQue<CWvEvent> iEventList; |
|
613 |
|
614 // Request queue |
|
615 TDblQue<CRequest> iRequestList; |
|
616 TUint iSubHandle; // handle of this subsession |
|
617 |
|
618 TBool iStatusObserver; // Status handler on/off |
|
619 TBool iDetailedError; // Detailed handler on/off |
|
620 |
|
621 CImpsSession* iSession; |
|
622 TImpsMessageType iLastEvent; // Type of last event _created_ excluding |
|
623 // status events |
|
624 CImpsVariant* iVariant; |
|
625 RMessagePtr2 iEventMsg; // next message request from client |
|
626 |
|
627 TImpsOOMErrors iOOMErr; |
|
628 TInt iExpiryTime; // request expiration in seconds |
|
629 }; |
|
630 |
|
631 #include "impssubsession.inl" |
|
632 |
|
633 |
|
634 #endif |
|
635 |
|
636 // End of File |