|
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: Implementation of class COMASUPLState |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include <utf.h> |
|
23 |
|
24 #include "epos_comasuplsessionid.h" |
|
25 |
|
26 #include "epos_comasuplstate.h" |
|
27 #include "epos_comasupltimeouttimer.h" |
|
28 #include "epos_comasupltrace.h" |
|
29 |
|
30 _LIT(KTraceFileName,"SUPL_OMA_SESSION::EPos_COMASuplState.cpp"); |
|
31 |
|
32 #if defined(_DEBUG) |
|
33 |
|
34 _LIT( KPanicMsg, "COMASUPLState"); |
|
35 |
|
36 enum TOMASuplStatePanicCode |
|
37 { |
|
38 EInvalidStateObserver = -1001, |
|
39 EInvalidMsgProcess = -1002 |
|
40 |
|
41 }; |
|
42 |
|
43 void Panic( TOMASuplStatePanicCode aReason ) |
|
44 { |
|
45 User::Panic( KPanicMsg, aReason ); |
|
46 } |
|
47 |
|
48 #endif |
|
49 |
|
50 |
|
51 // ============================ MEMBER FUNCTIONS =============================== |
|
52 //Default constructor |
|
53 COMASuplState::COMASuplState() |
|
54 { |
|
55 iMessageTimeOut = 0; |
|
56 iCurrentState = ESUPL_NONE; |
|
57 } |
|
58 |
|
59 //Destructor |
|
60 COMASuplState::~COMASuplState() |
|
61 { |
|
62 CancelOperation(); |
|
63 delete iTimer; |
|
64 delete iTrace; |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // COMASuplState::GenerateMessage |
|
69 // Generates message...which message to be generate will be depend on derived class implementation |
|
70 // (other items were commented in a header). |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 TInt COMASuplState::GenerateMessageL() |
|
74 { |
|
75 //Nothing to do here |
|
76 iTrace->Trace(_L("COMASuplState::GenerateMessage...No use"), KTraceFileName, __LINE__); |
|
77 return KErrNotSupported; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // COMASuplState::CancelOperation |
|
82 // Cancels Operation...which will be depend on derived class implementation |
|
83 // (other items were commented in a header). |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 void COMASuplState::CancelOperation() |
|
87 { |
|
88 StopTimer(); |
|
89 |
|
90 #ifdef PRINT_MESSAGE |
|
91 //Debug mode |
|
92 TBuf<64> msg(_L("COMASuplState::CancelOperation... ")); |
|
93 switch(iCurrentState) |
|
94 { |
|
95 case ESUPL_NONE: |
|
96 msg.Append(_L("ESUPL_NONE")); |
|
97 break; |
|
98 case ESUPL_START: |
|
99 msg.Append(_L("ESUPL_START")); |
|
100 break; |
|
101 case ESUPL_RESPONSE: |
|
102 msg.Append(_L("ESUPL_RESPONSE")); |
|
103 break; |
|
104 case ESUPL_POS: |
|
105 msg.Append(_L("ESUPL_POS")); |
|
106 break; |
|
107 case ESUPL_POS_INIT: |
|
108 msg.Append(_L("ESUPL_POS_INIT")); |
|
109 break; |
|
110 case ESUPL_INIT: |
|
111 msg.Append(_L("ESUPL_INIT")); |
|
112 break; |
|
113 case ESUPL_END: |
|
114 msg.Append(_L("ESUPL_END")); |
|
115 break; |
|
116 |
|
117 case ESUPL_TRIG_START: |
|
118 msg.Append(_L("ESUPL_TRIG_START")); |
|
119 break; |
|
120 case ESUPL_TRIG_RESPONSE: |
|
121 msg.Append(_L("ESUPL_TRIG_RESPONSE")); |
|
122 break; |
|
123 case ESUPL_TRIG_STOP: |
|
124 msg.Append(_L("ESUPL_TRIG_STOP")); |
|
125 break; |
|
126 case ESUPL_REPORT: |
|
127 msg.Append(_L("ESUPL_REPORT")); |
|
128 break; |
|
129 |
|
130 default: |
|
131 msg.Append(_L("WRONG MESSAGE")); |
|
132 } |
|
133 if(iTrace) |
|
134 iTrace->Trace(msg, KTraceFileName, __LINE__); |
|
135 #endif |
|
136 |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // COMASuplState::SetMsgStateObserver |
|
141 // Sets the message state observer |
|
142 // (other items were commented in a header). |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 void COMASuplState::SetMsgStateObserver(MOMASuplMsgStateObserver* aMsgStateObserver) |
|
146 { |
|
147 __ASSERT_DEBUG(aMsgStateObserver, Panic(EInvalidStateObserver) ); |
|
148 iMsgStateObserver = aMsgStateObserver; |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // COMASuplState::EncodeMessageL |
|
153 // Encodes message...which message to be encode will be depend on derived class implementation |
|
154 // (other items were commented in a header). |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 HBufC8* COMASuplState::EncodeMessageL(TOMASuplVersion& |
|
158 #if defined(PRINT_MESSAGE) |
|
159 aSuplVersion |
|
160 #endif |
|
161 , |
|
162 COMASuplSessionID* |
|
163 #if defined(PRINT_MESSAGE) |
|
164 aSessionId |
|
165 #endif |
|
166 , |
|
167 TInt &aError) |
|
168 { |
|
169 #ifdef PRINT_MESSAGE //This is only for logging purpose. |
|
170 TInt major,minor,ServInd; |
|
171 TBuf<128> msg(_L("SUPL Version is : Major :")); |
|
172 TBuf<4> ver; |
|
173 |
|
174 aSuplVersion.SuplVersion(major,minor,ServInd); |
|
175 |
|
176 ver.AppendNum(major); |
|
177 msg.Append(ver); |
|
178 |
|
179 msg.Append(_L(" Minor : ")); |
|
180 ver.Zero(); |
|
181 ver.AppendNum(minor); |
|
182 msg.Append(ver); |
|
183 |
|
184 msg.Append(_L(" ServInd : ")); |
|
185 ver.Zero(); |
|
186 ver.AppendNum(ServInd); |
|
187 msg.Append(ver); |
|
188 |
|
189 iTrace->Trace(msg,KTraceFileName, __LINE__); |
|
190 |
|
191 COMASuplSETSessionID* suplSETID = NULL; |
|
192 aSessionId->SETSessionID(suplSETID); |
|
193 |
|
194 COMASuplSLPSessionID* suplSLPID = NULL; |
|
195 aSessionId->SLPSessionID(suplSLPID); |
|
196 |
|
197 //SET Part |
|
198 if(suplSETID) |
|
199 { |
|
200 msg.Copy(_L("SET Session ID : ")); |
|
201 TBuf<4> id; |
|
202 TInt SETSessionID; |
|
203 TBuf8<64> IPvAddress8; |
|
204 TBuf<64> IPvAddress; |
|
205 |
|
206 suplSETID->SuplSETSessionID(SETSessionID,IPvAddress8); |
|
207 COMASuplSETSessionID::TSuplSETIDType setIDType = suplSETID->SuplSETIDType(); |
|
208 if(setIDType == COMASuplSETSessionID::EIMSI ) |
|
209 { |
|
210 iTrace->Trace(_L("SET ID is of type IMSI"),KTraceFileName, __LINE__); |
|
211 iTrace->Trace(_L("IMSI Value :"),KTraceFileName, __LINE__); |
|
212 msg.Copy(IPvAddress8); |
|
213 } |
|
214 else |
|
215 { |
|
216 TLex8 lex(IPvAddress8); |
|
217 |
|
218 TChar chr; |
|
219 |
|
220 chr = lex.Get(); |
|
221 TUint i = chr; |
|
222 IPvAddress.AppendNum(i); |
|
223 IPvAddress.Append(_L(".")); |
|
224 |
|
225 chr = lex.Get(); |
|
226 i = chr; |
|
227 IPvAddress.AppendNum(i); |
|
228 IPvAddress.Append(_L(".")); |
|
229 |
|
230 chr = lex.Get(); |
|
231 i = chr; |
|
232 IPvAddress.AppendNum(i); |
|
233 IPvAddress.Append(_L(".")); |
|
234 |
|
235 chr = lex.Get(); |
|
236 i = chr; |
|
237 IPvAddress.AppendNum(i); |
|
238 |
|
239 id.AppendNum(SETSessionID); |
|
240 msg.Append(id); |
|
241 msg.Append(_L(" IPAddress :")); |
|
242 msg.Append(IPvAddress); |
|
243 } |
|
244 } |
|
245 else |
|
246 { |
|
247 msg.Copy(_L("SET Session Id is not set.")); |
|
248 } |
|
249 |
|
250 |
|
251 //SLP Part |
|
252 if(suplSLPID) |
|
253 { |
|
254 msg.Copy(_L("SLP Session ID : ")); |
|
255 TBuf8<4> sessionId8; |
|
256 TBuf<32> sessionId; |
|
257 TBuf8<64> ipAddress8(_L8("No Address field in SLP Session ID")); |
|
258 TBuf<64> ipAddress; |
|
259 |
|
260 COMASuplSLPAddress* slpIPAddress = NULL; |
|
261 suplSLPID->SuplSLPSessionID(sessionId8,slpIPAddress); |
|
262 |
|
263 if(slpIPAddress) |
|
264 { |
|
265 COMASuplSLPAddress::TSuplSLPAddressType slpAddType = slpIPAddress->SLPAddressType(); |
|
266 if(slpAddType == COMASuplSLPAddress::EFqdn) |
|
267 { |
|
268 HBufC8* fqdn = NULL; |
|
269 slpIPAddress->Fqdn(fqdn); |
|
270 iTrace->Trace(_L("SLP Address is FQDN"),KTraceFileName, __LINE__); |
|
271 iTrace->Trace(_L("FQDN Value"),KTraceFileName, __LINE__); |
|
272 if(fqdn) |
|
273 { |
|
274 HBufC* fqdnBuffer = NULL; |
|
275 fqdnBuffer = HBufC::NewL(fqdn->Length()); |
|
276 fqdnBuffer->Des().Copy(fqdn->Des()); |
|
277 iTrace->Trace(fqdnBuffer->Des(),KTraceFileName, __LINE__); |
|
278 delete fqdnBuffer; |
|
279 fqdnBuffer = NULL; |
|
280 } |
|
281 |
|
282 aError = KErrNotSupported; |
|
283 return NULL; |
|
284 } |
|
285 else |
|
286 { |
|
287 TInt err = slpIPAddress->IPvAddress(ipAddress8); |
|
288 if(err != KErrNone) |
|
289 { |
|
290 msg.Copy(_L("SLP Address is not set.")); |
|
291 iTrace->Trace(msg,KTraceFileName, __LINE__); |
|
292 return NULL; |
|
293 } |
|
294 } |
|
295 } |
|
296 |
|
297 TLex8 lex(ipAddress8); |
|
298 TChar chr; |
|
299 |
|
300 chr = lex.Get(); |
|
301 TUint i = chr; |
|
302 ipAddress.AppendNum(i); |
|
303 ipAddress.Append(_L(".")); |
|
304 |
|
305 chr = lex.Get(); |
|
306 i = chr; |
|
307 ipAddress.AppendNum(i); |
|
308 ipAddress.Append(_L(".")); |
|
309 |
|
310 chr = lex.Get(); |
|
311 i = chr; |
|
312 ipAddress.AppendNum(i); |
|
313 ipAddress.Append(_L(".")); |
|
314 |
|
315 chr = lex.Get(); |
|
316 i = chr; |
|
317 ipAddress.AppendNum(i); |
|
318 |
|
319 TLex8 lex1(sessionId8); |
|
320 for(TInt i = 0; i < 4; i++) |
|
321 { |
|
322 chr = lex1.Get(); |
|
323 TUint num = chr; |
|
324 sessionId.AppendNum(num); |
|
325 } |
|
326 |
|
327 msg.Append(sessionId); |
|
328 msg.Append(_L(" IPAddress : ")); |
|
329 msg.Append(ipAddress); |
|
330 iTrace->Trace(msg,KTraceFileName, __LINE__); |
|
331 } |
|
332 else |
|
333 { |
|
334 msg.Copy(_L("SLP Session Id is not set.")); |
|
335 iTrace->Trace(msg,KTraceFileName, __LINE__); |
|
336 } |
|
337 #endif |
|
338 |
|
339 aError = KErrNotSupported; |
|
340 return NULL; |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // COMASuplState::EncodeMessageL |
|
345 // Encodes message...which message to be encode will be depend on derived class implementation |
|
346 // (other items were commented in a header). |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 TInt COMASuplState::ProcessMessageL(COMASuplAsnMessageBase* /*aDecodedMessage*/) |
|
350 { |
|
351 iTrace->Trace(_L("COMASuplState::ProcessMessage...No use"), KTraceFileName, __LINE__); |
|
352 return KErrNotSupported; |
|
353 } |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // COMASuplState::BaseConstructL |
|
357 // BaseConstructL.... initilization for some of the member var takes place |
|
358 // (other items were commented in a header). |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 void COMASuplState::BaseConstructL() |
|
362 { |
|
363 iTrace = COMASuplTrace::NewL(); |
|
364 iTrace->Trace(_L("COMASuplState::BaseConstructL..."), KTraceFileName, __LINE__); |
|
365 iTimer = COMASuplTimeoutTimer::NewL(*this); |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // COMASuplState::GetSuplState |
|
370 // GetSuplState.... returns type of message |
|
371 // (other items were commented in a header). |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 COMASuplState::TSuplMessageType COMASuplState::GetSuplState() |
|
375 { |
|
376 return iCurrentState; |
|
377 } |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // COMASuplState::StartTimer |
|
381 // StartTimer...starts the timer ... depending on type of message |
|
382 // (other items were commented in a header). |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 void COMASuplState::StartTimer() |
|
386 { |
|
387 iTrace->Trace(_L("COMASuplState::StartTimer..."), KTraceFileName, __LINE__); |
|
388 iTimer->StartTimer(iMessageTimeOut); |
|
389 } |
|
390 |
|
391 // ----------------------------------------------------------------------------- |
|
392 // COMASuplState::StopTimer |
|
393 // StopTimer...stops the timer . |
|
394 // (other items were commented in a header). |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 void COMASuplState::StopTimer() |
|
398 { |
|
399 iTimer->StopTimer(); |
|
400 iTrace->Trace(_L("COMASuplState::StopTimer..."), KTraceFileName, __LINE__); |
|
401 } |
|
402 |
|
403 // ----------------------------------------------------------------------------- |
|
404 // COMASuplState::TimerExpired |
|
405 // TimerExpired...Gets called when time out occurs . |
|
406 // (other items were commented in a header). |
|
407 // ----------------------------------------------------------------------------- |
|
408 // |
|
409 void COMASuplState::TimerExpiredL() |
|
410 { |
|
411 iTrace->Trace(_L("COMASuplState::TimerExpired..."), KTraceFileName, __LINE__); |
|
412 if(iMsgStateObserver) |
|
413 iMsgStateObserver->OperationCompleteL(KErrTimedOut); |
|
414 } |
|
415 |
|
416 void COMASuplState::SetVersion(TOMASuplVersion& aOMASuplVersion) |
|
417 { |
|
418 iOMASuplVersion = aOMASuplVersion; |
|
419 } |
|
420 |
|
421 |
|
422 |