|
1 /* |
|
2 * Copyright (c) 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: Implementation of CGbaClientRequestHandler |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32svr.h> |
|
19 #include "GbaClientrequesthandler.h" |
|
20 #include "GbaServerSession.h" |
|
21 #include "GBALogger.h" |
|
22 #include "GbaCommon.h" |
|
23 |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CGbaClientRequestHandler::NewL() |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 CGbaClientRequestHandler* CGbaClientRequestHandler::NewL(MGbaObserver& aObserver) |
|
30 { |
|
31 CGbaClientRequestHandler* self = CGbaClientRequestHandler::NewLC(aObserver); |
|
32 CleanupStack::Pop( self ); |
|
33 return(self) ; |
|
34 } |
|
35 |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CGbaClientRequestHandler::NewLC() |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CGbaClientRequestHandler* CGbaClientRequestHandler::NewLC(MGbaObserver& aObserver) |
|
42 { |
|
43 CGbaClientRequestHandler* self = new (ELeave) CGbaClientRequestHandler(aObserver); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CGbaClientRequestHandler::NewL() |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CGbaClientRequestHandler* CGbaClientRequestHandler::NewL() |
|
55 { |
|
56 CGbaClientRequestHandler* self = NewLC(); |
|
57 CleanupStack::Pop( self ); |
|
58 return(self) ; |
|
59 } |
|
60 |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CGbaClientRequestHandler::NewLC() |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CGbaClientRequestHandler* CGbaClientRequestHandler::NewLC() |
|
67 { |
|
68 CGbaClientRequestHandler* self = new (ELeave) CGbaClientRequestHandler(); |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(); |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CGbaClientRequestHandler::ConstructL() |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void CGbaClientRequestHandler::ConstructL() |
|
80 { |
|
81 iSession = new(ELeave) RGbaServerSession(); |
|
82 User::LeaveIfError(iSession->Connect()); |
|
83 } |
|
84 |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CGbaClientRequestHandler::CGbaClientRequestHandler() |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 CGbaClientRequestHandler::CGbaClientRequestHandler(MGbaObserver& aObserver) |
|
91 : CActive(EPriorityStandard), |
|
92 iObserver(&aObserver), |
|
93 iBootstrapState(EBootstrapNone) |
|
94 { |
|
95 CActiveScheduler::Add(this); |
|
96 } |
|
97 |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CGbaClientRequestHandler::CGbaClientRequestHandler() |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 CGbaClientRequestHandler::CGbaClientRequestHandler() |
|
104 : CActive(EPriorityStandard), |
|
105 iBootstrapState(EBootstrapNone) |
|
106 { |
|
107 iObserver = NULL; |
|
108 CActiveScheduler::Add(this); |
|
109 } |
|
110 |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CGbaClientRequestHandler::~CGbaClientRequestHandler() |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 CGbaClientRequestHandler::~CGbaClientRequestHandler() |
|
117 { |
|
118 if(IsActive()) |
|
119 { |
|
120 Cancel(); |
|
121 } |
|
122 if ( iSession ) |
|
123 { |
|
124 iSession->Close(); |
|
125 } |
|
126 delete iSession; |
|
127 } |
|
128 |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CGbaClientRequestHandler::RunL() |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CGbaClientRequestHandler::RunL() |
|
135 { |
|
136 GBA_TRACE_DEBUG_NUM(("CGbaClientRequestHandler::RunL iStatus=%d"),iStatus.Int()); |
|
137 |
|
138 // only when the observer is in use, the runl function should be called. |
|
139 // if observer in runl is NULL, that means the factory function and bootstrap function |
|
140 // that user used that doesnot match. |
|
141 if( !iObserver ) |
|
142 { |
|
143 return; |
|
144 } |
|
145 if( iStatus.Int() == KErrCancel && (iBootstrapState == EBootstrapCancelling)) |
|
146 { |
|
147 iBootstrapState = EBootstrapNone; |
|
148 return; |
|
149 } |
|
150 if( iStatus.Int() < KErrNone ) |
|
151 { |
|
152 iObserver->BootstrapComplete( iStatus.Int() ); |
|
153 return; |
|
154 } |
|
155 |
|
156 switch (iBootstrapState) |
|
157 { |
|
158 case EBootstrapping: |
|
159 { |
|
160 GBA_TRACE_DEBUG(("BTID")); |
|
161 GBA_TRACE_DEBUG_BINARY(iGbaOutputParams->iBTID); |
|
162 GBA_TRACE_DEBUG(("Ks_NAF")); |
|
163 GBA_TRACE_DEBUG_BINARY(iGbaOutputParams->iKNAF); |
|
164 iBootstrapState = EBootstrapNone; |
|
165 iObserver->BootstrapComplete( KErrNone ); |
|
166 GBA_TRACE_DEBUG(("Ks_NAF 2")); |
|
167 } |
|
168 break ; |
|
169 |
|
170 default: |
|
171 { |
|
172 GBA_TRACE_DEBUG(("Unexpected state")); |
|
173 iBootstrapState = EBootstrapNone; |
|
174 iObserver->BootstrapComplete( KErrUnknown ); |
|
175 } |
|
176 break ; |
|
177 } |
|
178 } |
|
179 |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CGbaClientRequestHandler::RunError() |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 TInt CGbaClientRequestHandler::RunError(TInt aError) |
|
186 { |
|
187 //when bootstrap fails, the error value from server |
|
188 //will be passed back to client. |
|
189 GBA_TRACE_DEBUG_NUM(("CGbaClientRequestHandler::RunError =%d"),aError ); |
|
190 if (iBootstrapState == EBootstrapping) |
|
191 { |
|
192 GBA_TRACE_DEBUG(("Call HandleUnexpected") ); |
|
193 iObserver->BootstrapComplete(aError); |
|
194 GBA_TRACE_DEBUG(("Call HandleUnexpected End") ); |
|
195 } |
|
196 return KErrNone; |
|
197 } |
|
198 |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CGbaClientRequestHandler::DoCancel() |
|
202 // ----------------------------------------------------------------------------- |
|
203 // |
|
204 void CGbaClientRequestHandler::DoCancel() |
|
205 { |
|
206 if ( iBootstrapState == EBootstrapping ) |
|
207 { |
|
208 CancelBootstrap(); |
|
209 } |
|
210 } |
|
211 |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CGbaClientRequestHandler::Bootstrap() |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 TInt CGbaClientRequestHandler::Bootstrap( const TGBABootstrapInputParams aInput, TGBABootstrapOutputParams& aOutput ) |
|
218 { |
|
219 if ( !iObserver ) |
|
220 { |
|
221 return KErrGeneral; |
|
222 } |
|
223 |
|
224 if ( iBootstrapState == EBootstrapping ) |
|
225 { |
|
226 return KErrInUse; |
|
227 } |
|
228 |
|
229 iGbaInputParams.iNAFName.Copy(aInput.iNAFName); |
|
230 iGbaInputParams.iFlags = aInput.iFlags; |
|
231 iGbaInputParams.iAPID = aInput.iAPID; |
|
232 iGbaInputParams.iProtocolIdentifier.Copy(aInput.iProtocolIdentifier); |
|
233 iGbaInputParams.iUICCLabel.Copy(aInput.iUICCLabel); |
|
234 |
|
235 iGbaOutputParams = &aOutput; |
|
236 |
|
237 iBootstrapState = EBootstrapping; |
|
238 |
|
239 if ( !IsActive() ) |
|
240 { |
|
241 iSession->RequestBootstrap( iGbaInputParams, *iGbaOutputParams, iStatus); |
|
242 SetActive(); |
|
243 } |
|
244 return KErrNone; |
|
245 } |
|
246 |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CGbaClientRequestHandler::Bootstrap() |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 TInt CGbaClientRequestHandler::Bootstrap( const TGBABootstrapInputParams aInput, TGBABootstrapOutputParams& aOutput, TRequestStatus& aStatus ) |
|
253 { |
|
254 iGbaInputParams.iNAFName.Copy(aInput.iNAFName); |
|
255 iGbaInputParams.iFlags = aInput.iFlags; |
|
256 iGbaInputParams.iAPID = aInput.iAPID; |
|
257 iGbaInputParams.iProtocolIdentifier.Copy(aInput.iProtocolIdentifier); |
|
258 iGbaInputParams.iUICCLabel.Copy(aInput.iUICCLabel); |
|
259 |
|
260 iGbaOutputParams = &aOutput; |
|
261 |
|
262 iSession->RequestBootstrap(iGbaInputParams, *iGbaOutputParams, aStatus); |
|
263 return KErrNone; |
|
264 } |
|
265 |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CGbaClientRequestHandler::CancelBootstrap() |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 TInt CGbaClientRequestHandler::CancelBootstrap() |
|
272 { |
|
273 GBA_TRACE_DEBUG(("CGbaClientRequestHandler::CancelBootstrap")); |
|
274 if ( iObserver ) |
|
275 { |
|
276 iBootstrapState = EBootstrapCancelling; |
|
277 } |
|
278 return iSession->CancelBootstrap() ; |
|
279 } |
|
280 |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CGbaClientRequestHandler::SetBSFAddress() |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 TInt CGbaClientRequestHandler::SetBSFAddress(const TDesC8& aNewVal) |
|
287 { |
|
288 GBA_TRACE_DEBUG(("CGbaClientRequestHandler::SetBSFAddress")); |
|
289 TUid optionCode = KGbaBSFConfiguration; |
|
290 return iSession->WriteOption(optionCode,aNewVal); |
|
291 } |
|
292 |
|
293 //EOF |