|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 // Local includes |
|
18 #include "cnwsstranslookuptable.h" |
|
19 #include "mnwsssessioneventhandler.h" |
|
20 #include "mnwsstransactioneventhandler.h" |
|
21 #include "mnwssoomhandler.h" |
|
22 #include "tnwsswsptrhndpanic.h" |
|
23 #include "testoom.h" |
|
24 |
|
25 // Class signature |
|
26 #include "cnwsswspcoeventdispatcher.h" |
|
27 |
|
28 |
|
29 |
|
30 CNwssWspCOEventDispatcher* CNwssWspCOEventDispatcher::NewL( |
|
31 RWSPCOConn& aWspSession, |
|
32 MNwssSessionEventHandler& aSessEventHnd, |
|
33 MNwssTransactionEventHandler& aTransEventHnd, |
|
34 MNwssOomHandler& aOutOfMemoryHnd |
|
35 ) |
|
36 { |
|
37 return new(ELeave)CNwssWspCOEventDispatcher(aWspSession, aSessEventHnd, |
|
38 aTransEventHnd, aOutOfMemoryHnd); |
|
39 } |
|
40 |
|
41 CNwssWspCOEventDispatcher::~CNwssWspCOEventDispatcher() |
|
42 { |
|
43 Cancel(); |
|
44 } |
|
45 |
|
46 CNwssWspCOEventDispatcher::CNwssWspCOEventDispatcher( |
|
47 RWSPCOConn& aWspSession, |
|
48 MNwssSessionEventHandler& aSessEventHnd, |
|
49 MNwssTransactionEventHandler& aTransEventHnd, |
|
50 MNwssOomHandler& aOutOfMemoryHnd |
|
51 ) |
|
52 : CActive(CActive::EPriorityHigh), |
|
53 iWspSession(aWspSession), iSessEventHnd(aSessEventHnd), |
|
54 iTransEventHnd(aTransEventHnd), iOutOfMemoryHnd(aOutOfMemoryHnd) |
|
55 { |
|
56 CActiveScheduler::Add(this); |
|
57 } |
|
58 |
|
59 void CNwssWspCOEventDispatcher::Start() |
|
60 { |
|
61 if (!IsActive()) |
|
62 { |
|
63 iWspSession.GetEvent(iWspEvent, iTransaction, iStatus); |
|
64 SetActive(); |
|
65 } |
|
66 } |
|
67 |
|
68 void CNwssWspCOEventDispatcher::RunL() |
|
69 { |
|
70 RWSPCOConn::TEventType event = (RWSPCOConn::TEventType)iWspEvent(); |
|
71 |
|
72 // Obtain the transaction ID for transaction events |
|
73 iTrId = KErrNotFound; |
|
74 if ( (event == RWSPCOConn::EMethodInvoke_cnf_t) || |
|
75 (event == RWSPCOConn::EMethodResult_ind_t) || |
|
76 (event == RWSPCOConn::EAbort_ind_t) ) |
|
77 { |
|
78 __TESTOOMD(stkErr, iTransaction.Id(iTrId)); |
|
79 User::LeaveIfError(stkErr); |
|
80 } |
|
81 |
|
82 // Testing only - simulate a WAP Stack OOM which would cause this AO to complete with KErrNoMemory |
|
83 TInt status = iStatus.Int(); |
|
84 #if defined (_DEBUG) && defined(__UNIT_TESTING__) |
|
85 TAny* _a = User::Alloc(sizeof(TInt)); |
|
86 User::Free(_a); |
|
87 if (_a == NULL) |
|
88 status = KErrNoMemory; |
|
89 #endif |
|
90 User::LeaveIfError(status); |
|
91 |
|
92 // Request the next event before processing this one. It is important to do this here, |
|
93 // and not after the following event handling - since the handler may decide to cancel this |
|
94 // dispatcher as a result of the event, or even close iWspSession. |
|
95 Start(); |
|
96 |
|
97 // Act according to the event type |
|
98 switch (event) |
|
99 { |
|
100 // dispatch session events to the session event handler |
|
101 case RWSPCOConn::EDisconnect_ind_s: |
|
102 { |
|
103 __DEBUGTESTLEAVE |
|
104 iSessEventHnd.HandleDisconnectIndL(); |
|
105 } break; |
|
106 case RWSPCOConn::ESuspend_ind_s: |
|
107 { |
|
108 __DEBUGTESTLEAVE |
|
109 iSessEventHnd.HandleSuspendIndL(); |
|
110 } break; |
|
111 case RWSPCOConn::EResume_cnf_s: |
|
112 { |
|
113 __DEBUGTESTLEAVE |
|
114 iSessEventHnd.HandleResumeCnfL(); |
|
115 } break; |
|
116 case RWSPCOConn::EConnect_cnf_s: |
|
117 { |
|
118 __DEBUGTESTLEAVE |
|
119 iSessEventHnd.HandleConnectCnfL(); |
|
120 } break; |
|
121 case RWSPCOConn::ERedirect_ind_s: |
|
122 { |
|
123 __DEBUGTESTLEAVE |
|
124 iSessEventHnd.HandleRedirectIndL(); |
|
125 } break; |
|
126 // dispatch transaction events to the transaction event handler |
|
127 case RWSPCOConn::EMethodInvoke_cnf_t: |
|
128 { |
|
129 __DEBUGTESTLEAVE |
|
130 iTransEventHnd.HandleMethodInvokeCnfL(iTrId); |
|
131 } break; |
|
132 case RWSPCOConn::EMethodResult_ind_t: |
|
133 { |
|
134 __DEBUGTESTLEAVE |
|
135 iTransEventHnd.HandleMethodResultIndL(iTrId); |
|
136 } break; |
|
137 case RWSPCOConn::EAbort_ind_t: |
|
138 { |
|
139 __DEBUGTESTLEAVE |
|
140 iTransEventHnd.HandleAbortIndL(iTrId); |
|
141 } break; |
|
142 // push events are not supported, and should indeed never arise if the |
|
143 // capability negotiations with the WAP proxy have been successful |
|
144 case RWSPCOConn::EPush_ind_t: |
|
145 case RWSPCOConn::EConfirmedPush_ind_t: |
|
146 { |
|
147 TNwssWspTrHndPanic::Panic(TNwssWspTrHndPanic::ECOPushNotSupported); |
|
148 } break; |
|
149 // exception event is treated like a session event |
|
150 case RWSPCOConn::EException_ind_e: |
|
151 { |
|
152 __DEBUGTESTLEAVE |
|
153 iSessEventHnd.HandleExceptionIndL(); |
|
154 } break; |
|
155 default: |
|
156 { |
|
157 TNwssWspTrHndPanic::Panic(TNwssWspTrHndPanic::EUnknownWspEvent); |
|
158 } break; |
|
159 }; |
|
160 } |
|
161 |
|
162 TInt CNwssWspCOEventDispatcher::RunError(TInt aError) |
|
163 { |
|
164 // Handle errors according to event type: if it's a transaction event, then send an AbortInd |
|
165 // for it. If it's a session event, then send DisconnectInd. |
|
166 RWSPCOConn::TEventType event = (RWSPCOConn::TEventType)iWspEvent(); |
|
167 TInt err = KErrNone; |
|
168 |
|
169 // Act according to the event type |
|
170 switch (event) |
|
171 { |
|
172 case RWSPCOConn::ESuspend_ind_s: |
|
173 case RWSPCOConn::EResume_cnf_s: |
|
174 case RWSPCOConn::EConnect_cnf_s: |
|
175 case RWSPCOConn::ERedirect_ind_s: |
|
176 case RWSPCOConn::EDisconnect_ind_s: |
|
177 { |
|
178 if (aError != KErrNoMemory) |
|
179 TRAP(err, __DEBUGTESTLEAVE \ |
|
180 iSessEventHnd.HandleDisconnectIndL()); |
|
181 if ((aError == KErrNoMemory) || (err == KErrNoMemory)) |
|
182 { |
|
183 // We need to disconnect the WAP stack if there is any risk of |
|
184 // the client and WAP stack's session state becoming different |
|
185 TBool disconStack = ( (event != RWSPCOConn::EDisconnect_ind_s) && |
|
186 (event != RWSPCOConn::ERedirect_ind_s) ); |
|
187 iOutOfMemoryHnd.SendOomDisconnect(disconStack); |
|
188 } |
|
189 } break; |
|
190 case RWSPCOConn::EMethodInvoke_cnf_t: |
|
191 case RWSPCOConn::EMethodResult_ind_t: |
|
192 case RWSPCOConn::EAbort_ind_t: |
|
193 { |
|
194 if (iTrId != KErrNotFound) // if we don't have a transaction ID we can't do anything |
|
195 { |
|
196 if (aError != KErrNoMemory) |
|
197 TRAP(err, __DEBUGTESTLEAVE \ |
|
198 iTransEventHnd.HandleAbortIndL(iTrId)); |
|
199 if ((aError == KErrNoMemory) || (err == KErrNoMemory)) |
|
200 iOutOfMemoryHnd.SendOomMethodAbort(iTrId, EFalse); |
|
201 } |
|
202 else |
|
203 { |
|
204 // We had an error whilst processing a transaction event, but we couldn't obtain |
|
205 // the transaction ID - so we'll have to disconnect the session instead. |
|
206 iOutOfMemoryHnd.SendOomDisconnect(ETrue); |
|
207 } |
|
208 } break; |
|
209 default: |
|
210 ; // ignore - nothing else we can do |
|
211 }; |
|
212 return KErrNone; |
|
213 } |
|
214 |
|
215 void CNwssWspCOEventDispatcher::DoCancel() |
|
216 { |
|
217 iWspSession.CancelGetEvent(); |
|
218 } |