|
1 /* |
|
2 * Copyright (c) 2001-2010 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 the License "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: scheduler of EAP-server. |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 30 % |
|
20 */ |
|
21 |
|
22 #include "EapServer.h" |
|
23 #include "EapTraceSymbian.h" |
|
24 #include <ecom.h> |
|
25 #include "eap_automatic_variable.h" |
|
26 |
|
27 /* |
|
28 class CEapServer |
|
29 */ |
|
30 |
|
31 //---------------------------------------------------------------------------- |
|
32 |
|
33 CEapServer::CEapServer() |
|
34 : CServer2(0, EGlobalSharableSessions) // //ESharableSessions |
|
35 { |
|
36 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapServer::CEapServer(): this=0x%08x"), |
|
37 this)); |
|
38 |
|
39 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapServer::CEapServer()")); |
|
40 } |
|
41 |
|
42 //---------------------------------------------------------------------------- |
|
43 |
|
44 void CEapServer::ConstructL() |
|
45 { |
|
46 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapServer::ConstructL(): start"))); |
|
47 |
|
48 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
49 |
|
50 iIsValid = EFalse; |
|
51 iTools = abs_eap_am_tools_c::new_abs_eap_am_tools_c(); |
|
52 |
|
53 // Check if creation went ok and the the iIsValid variable |
|
54 if (iTools == 0 |
|
55 || iTools->get_is_valid() == false) |
|
56 { |
|
57 if (iTools != 0) |
|
58 { |
|
59 iTools->am_cancel_all_timers(); |
|
60 } |
|
61 abs_eap_am_tools_c::delete_abs_eap_am_tools_c(iTools); |
|
62 User::Leave(KErrNoMemory); |
|
63 } |
|
64 else |
|
65 { |
|
66 iIsValid = iTools->get_is_valid(); |
|
67 } |
|
68 |
|
69 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::ConstructL()"); |
|
70 |
|
71 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
72 |
|
73 { |
|
74 const u8_t DEFAULT_PREFIX[] = "EAP-SERVER"; |
|
75 eap_variable_data_c tmp_prefix(iTools); |
|
76 |
|
77 if (tmp_prefix.get_is_valid() == false) |
|
78 { |
|
79 iTools->am_cancel_all_timers(); |
|
80 abs_eap_am_tools_c::delete_abs_eap_am_tools_c(iTools); |
|
81 User::Leave(KErrNoMemory); |
|
82 } |
|
83 |
|
84 eap_status_e status = tmp_prefix.set_copy_of_buffer(DEFAULT_PREFIX, sizeof(DEFAULT_PREFIX)-1ul);; |
|
85 if (status != eap_status_ok) |
|
86 { |
|
87 iTools->am_cancel_all_timers(); |
|
88 abs_eap_am_tools_c::delete_abs_eap_am_tools_c(iTools); |
|
89 User::Leave(KErrNoMemory); |
|
90 } |
|
91 |
|
92 status = tmp_prefix.add_end_null(); |
|
93 if (status != eap_status_ok) |
|
94 { |
|
95 iTools->am_cancel_all_timers(); |
|
96 abs_eap_am_tools_c::delete_abs_eap_am_tools_c(iTools); |
|
97 User::Leave(KErrNoMemory); |
|
98 } |
|
99 |
|
100 status = iTools->set_trace_prefix(&tmp_prefix); |
|
101 if (status != eap_status_ok) |
|
102 { |
|
103 iTools->am_cancel_all_timers(); |
|
104 abs_eap_am_tools_c::delete_abs_eap_am_tools_c(iTools); |
|
105 User::Leave(KErrNoMemory); |
|
106 } |
|
107 } |
|
108 |
|
109 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
110 |
|
111 { |
|
112 TInt error; |
|
113 RFs aFileServerSession; |
|
114 |
|
115 // Open file server session |
|
116 EAP_TRACE_DEBUG( |
|
117 iTools, |
|
118 TRACE_FLAGS_DEFAULT, |
|
119 (EAPL("CEapServer::ConstructL(): - calls aFileServerSession.Connect()\n"))); |
|
120 |
|
121 error = aFileServerSession.Connect(); |
|
122 |
|
123 EAP_TRACE_DEBUG( |
|
124 iTools, |
|
125 TRACE_FLAGS_DEFAULT, |
|
126 (EAPL("CEapServer::ConstructL(): - aFileServerSession.Connect(), error=%d\n"), |
|
127 error)); |
|
128 |
|
129 User::LeaveIfError(error); |
|
130 |
|
131 // Create the private path - it is not automatically created by Symbian OS. |
|
132 EAP_TRACE_DEBUG( |
|
133 iTools, |
|
134 TRACE_FLAGS_DEFAULT, |
|
135 (EAPL("CEapServer::ConstructL(): - calls aFileServerSession.CreatePrivatePath(%d)\n"), |
|
136 RFs::GetSystemDrive())); |
|
137 |
|
138 error = aFileServerSession.CreatePrivatePath(RFs::GetSystemDrive()); |
|
139 |
|
140 EAP_TRACE_DEBUG( |
|
141 iTools, |
|
142 TRACE_FLAGS_DEFAULT, |
|
143 (EAPL("CEapServer::ConstructL(): - aFileServerSession.CreatePrivatePath(%d), error=%d\n"), |
|
144 RFs::GetSystemDrive(), |
|
145 error)); |
|
146 |
|
147 User::LeaveIfError(error); |
|
148 |
|
149 // Set the session path to the private directory |
|
150 EAP_TRACE_DEBUG( |
|
151 iTools, |
|
152 TRACE_FLAGS_DEFAULT, |
|
153 (EAPL("CEapServer::ConstructL(): - calls aFileServerSession.SetSessionToPrivate(%d)\n"), |
|
154 RFs::GetSystemDrive())); |
|
155 |
|
156 error = aFileServerSession.SetSessionToPrivate(RFs::GetSystemDrive()); |
|
157 |
|
158 EAP_TRACE_DEBUG( |
|
159 iTools, |
|
160 TRACE_FLAGS_DEFAULT, |
|
161 (EAPL("CEapServer::ConstructL(): - aFileServerSession.SetSessionToPrivate(%d), error=%d\n"), |
|
162 RFs::GetSystemDrive(), |
|
163 error)); |
|
164 |
|
165 User::LeaveIfError(error); |
|
166 |
|
167 // Close the session with the file server. |
|
168 aFileServerSession.Close(); |
|
169 } |
|
170 |
|
171 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
172 |
|
173 { |
|
174 // construct shutdown timer |
|
175 iShutdown = new(ELeave) CEapDelayedShutdown(iTools, this); |
|
176 iShutdown->ConstructL(); |
|
177 // identify ourselves and open for service |
|
178 TBuf<KMaxServerExe> ServerName; |
|
179 TBuf<KMaxServerExe> ServerExe; |
|
180 |
|
181 GetServerNameAndExe(&ServerName, &ServerExe); |
|
182 |
|
183 StartL(ServerName); |
|
184 |
|
185 // Initiates shut down timer. Timer will close server unless we get client connections. |
|
186 iShutdown->Start(); |
|
187 } |
|
188 |
|
189 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
190 |
|
191 { |
|
192 // construct backup and restore observer |
|
193 iBackupRestore = new(ELeave) CEapserverBackup(this); |
|
194 iBackupRestore->ConstructL(); |
|
195 } |
|
196 |
|
197 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
198 |
|
199 } |
|
200 |
|
201 //---------------------------------------------------------------------------- |
|
202 |
|
203 CEapServer* CEapServer::NewL() |
|
204 { |
|
205 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapServer::NewL(): starts"))); |
|
206 |
|
207 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapServer::NewL()")); |
|
208 |
|
209 CEapServer* self = new(ELeave)CEapServer(); |
|
210 CleanupStack::PushL(self); |
|
211 |
|
212 self->ConstructL(); |
|
213 |
|
214 CleanupStack::Pop(self); |
|
215 |
|
216 return self; |
|
217 } |
|
218 |
|
219 //---------------------------------------------------------------------------- |
|
220 |
|
221 CEapServer::~CEapServer() |
|
222 { |
|
223 EAP_TRACE_DEBUG( |
|
224 iTools, |
|
225 TRACE_FLAGS_DEFAULT, |
|
226 (EAPL("CEapServer::~CEapServer(): this=0x%08x\n"), |
|
227 this)); |
|
228 |
|
229 // Do not use iTools, because it will be destroyed before return. |
|
230 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapServer::~CEapServer()")); |
|
231 |
|
232 delete iShutdown; |
|
233 delete iBackupRestore; |
|
234 |
|
235 if (iTools) |
|
236 { |
|
237 iTools->am_cancel_all_timers(); |
|
238 abs_eap_am_tools_c::delete_abs_eap_am_tools_c(iTools); |
|
239 } |
|
240 |
|
241 REComSession::FinalClose(); |
|
242 } |
|
243 |
|
244 //---------------------------------------------------------------------------- |
|
245 |
|
246 // from CServer |
|
247 |
|
248 CSession2* CEapServer::NewSessionL(const TVersion& /* aVersion */, const RMessage2 &aMessage) const |
|
249 { |
|
250 EAP_TRACE_DEBUG( |
|
251 iTools, |
|
252 TRACE_FLAGS_DEFAULT, |
|
253 (EAPL("CEapServer::NewSessionL(): starts\n"))); |
|
254 |
|
255 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::NewSessionL()"); |
|
256 |
|
257 CEapSession* session = new(ELeave) CEapSession(); |
|
258 CleanupStack::PushL(session); |
|
259 |
|
260 EAP_TRACE_DEBUG( |
|
261 iTools, |
|
262 TRACE_FLAGS_DEFAULT, |
|
263 (EAPL("CEapServer::NewSessionL(): session=0x%08x\n"), |
|
264 session)); |
|
265 |
|
266 EAP_TRACE_DEBUG( |
|
267 iTools, |
|
268 TRACE_FLAGS_DEFAULT, |
|
269 (EAPL("CEapServer::NewSessionL(): session->ConstructL() starts"))); |
|
270 |
|
271 session->ConstructL(*const_cast<CEapServer*>(this), iTools); |
|
272 |
|
273 EAP_TRACE_DEBUG( |
|
274 iTools, |
|
275 TRACE_FLAGS_DEFAULT, |
|
276 (EAPL("CEapServer::NewSessionL(): session->ConstructL() ends"))); |
|
277 |
|
278 CleanupStack::Pop(session); |
|
279 |
|
280 const_cast<CEapServer*>(this)->IncrementSessions(); |
|
281 |
|
282 return session; |
|
283 } |
|
284 |
|
285 //---------------------------------------------------------------------------- |
|
286 |
|
287 TInt CEapServer::RunError(TInt aErr) |
|
288 /** |
|
289 Handle leaves from ServiceL. |
|
290 |
|
291 Any leave from a ServiceL() will land up here. |
|
292 */ |
|
293 { |
|
294 EAP_TRACE_DEBUG( |
|
295 iTools, |
|
296 TRACE_FLAGS_DEFAULT, |
|
297 (EAPL("CEapServer::RunError(), aErr=%d\n"), |
|
298 aErr)); |
|
299 |
|
300 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::RunError()"); |
|
301 |
|
302 // if it's a bad descriptor, panic the client |
|
303 if (aErr==KErrBadDescriptor) // client had a bad descriptor |
|
304 { |
|
305 PanicClient(EBadDescriptor); |
|
306 } |
|
307 |
|
308 // anyway, complete the outstanding message |
|
309 Message().Complete(aErr); |
|
310 ReStart(); // really means just continue reading client requests |
|
311 return KErrNone; |
|
312 } |
|
313 |
|
314 //---------------------------------------------------------------------------- |
|
315 |
|
316 /** |
|
317 session count support |
|
318 */ |
|
319 void CEapServer::IncrementSessions() |
|
320 { |
|
321 iSessionCount++; |
|
322 |
|
323 EAP_TRACE_DEBUG( |
|
324 iTools, |
|
325 TRACE_FLAGS_DEFAULT, |
|
326 (EAPL("CEapServer::IncrementSessions(): iSessionCount=%d\n"), |
|
327 iSessionCount)); |
|
328 |
|
329 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::IncrementSessions()"); |
|
330 |
|
331 iShutdown->Cancel(); |
|
332 } |
|
333 |
|
334 //---------------------------------------------------------------------------- |
|
335 |
|
336 void CEapServer::DecrementSessions() |
|
337 { |
|
338 EAP_TRACE_DEBUG( |
|
339 iTools, |
|
340 TRACE_FLAGS_DEFAULT, |
|
341 (EAPL("CEapServer::DecrementSessions(): iSessionCount=%d\n"), |
|
342 iSessionCount)); |
|
343 |
|
344 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::DecrementSessions()"); |
|
345 |
|
346 iSessionCount--; |
|
347 if (iSessionCount>0) |
|
348 return; |
|
349 |
|
350 iShutdown->Start(); |
|
351 } |
|
352 |
|
353 //---------------------------------------------------------------------------- |
|
354 |
|
355 void CEapServer::PanicClient(TInt aPanic) const |
|
356 { |
|
357 EAP_TRACE_DEBUG( |
|
358 iTools, |
|
359 TRACE_FLAGS_DEFAULT, |
|
360 (EAPL("CEapServer::PanicClient(): aPanic=%d\n"), |
|
361 aPanic)); |
|
362 |
|
363 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::PanicClient()"); |
|
364 |
|
365 // let's have a look before we panic the client |
|
366 __DEBUGGER() |
|
367 // ok, go for it |
|
368 |
|
369 const TBufC<KMaxCategoryLength> aCategory; |
|
370 Message().Panic(aCategory, EBadRequest); |
|
371 } |
|
372 |
|
373 //---------------------------------------------------------------------------- |
|
374 |
|
375 void CEapServer::StopL() |
|
376 { |
|
377 EAP_TRACE_DEBUG( |
|
378 iTools, |
|
379 TRACE_FLAGS_DEFAULT, |
|
380 (EAPL("CEapServer::StopL()\n"))); |
|
381 |
|
382 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::StopL()"); |
|
383 |
|
384 for (iSessionIter.SetToFirst(); iSessionIter; iSessionIter++) |
|
385 { |
|
386 CSession2 * aSession = iSessionIter; |
|
387 |
|
388 EAP_TRACE_DEBUG( |
|
389 iTools, |
|
390 TRACE_FLAGS_DEFAULT, |
|
391 (EAPL("CEapServer::StopL(): aSession=0x%08x calls CancelReceive()\n"), |
|
392 aSession)); |
|
393 |
|
394 if (dynamic_cast<CEapSession *>(aSession) != NULL) |
|
395 { |
|
396 dynamic_cast<CEapSession *>(aSession)->CancelReceive(); |
|
397 } |
|
398 } |
|
399 } |
|
400 |
|
401 //---------------------------------------------------------------------------- |
|
402 |
|
403 void CEapServer::BackupOrRestoreCompleteL() |
|
404 { |
|
405 EAP_TRACE_DEBUG( |
|
406 iTools, |
|
407 TRACE_FLAGS_DEFAULT, |
|
408 (EAPL("ERROR: CEapServer::BackupOrRestoreCompleteL(): Do something\n"))); |
|
409 |
|
410 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::BackupOrRestoreCompleteL()"); |
|
411 } |
|
412 |
|
413 //---------------------------------------------------------------------------- |
|
414 |
|
415 void CEapServer::BackupOrRestoreStartingL() |
|
416 { |
|
417 EAP_TRACE_DEBUG( |
|
418 iTools, |
|
419 TRACE_FLAGS_DEFAULT, |
|
420 (EAPL("WARNING: CEapServer::BackupOrRestoreStartingL(): Terminates EAP-SERVER. All sessions are also closed. All files are unlocked for backup or restore.\n"))); |
|
421 |
|
422 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapServer::BackupOrRestoreStartingL()"); |
|
423 |
|
424 StopL(); |
|
425 } |
|
426 |
|
427 //---------------------------------------------------------------------------- |
|
428 |
|
429 /* |
|
430 class CEapDelayedShutdown |
|
431 */ |
|
432 |
|
433 CEapDelayedShutdown::CEapDelayedShutdown(abs_eap_am_tools_c * const tools, CEapServer * const aServer) |
|
434 : CActive(0) |
|
435 , iTools(tools) |
|
436 , iServer(aServer) |
|
437 { |
|
438 } |
|
439 |
|
440 //---------------------------------------------------------------------------- |
|
441 |
|
442 void CEapDelayedShutdown::ConstructL() |
|
443 { |
|
444 EAP_TRACE_DEBUG( |
|
445 iTools, |
|
446 TRACE_FLAGS_DEFAULT, |
|
447 (EAPL("CEapDelayedShutdown::ConstructL()\n"))); |
|
448 |
|
449 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapDelayedShutdown::ConstructL()"); |
|
450 |
|
451 CActiveScheduler::Add(this); |
|
452 User::LeaveIfError(iTimer.CreateLocal()); |
|
453 } |
|
454 |
|
455 //---------------------------------------------------------------------------- |
|
456 |
|
457 CEapDelayedShutdown::~CEapDelayedShutdown() |
|
458 { |
|
459 EAP_TRACE_DEBUG( |
|
460 iTools, |
|
461 TRACE_FLAGS_DEFAULT, |
|
462 (EAPL("CEapDelayedShutdown::~CEapDelayedShutdown()\n"))); |
|
463 |
|
464 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapDelayedShutdown::~CEapDelayedShutdown()"); |
|
465 |
|
466 Cancel(); |
|
467 iTimer.Close(); |
|
468 } |
|
469 |
|
470 //---------------------------------------------------------------------------- |
|
471 |
|
472 void CEapDelayedShutdown::Start() |
|
473 { |
|
474 EAP_TRACE_DEBUG( |
|
475 iTools, |
|
476 TRACE_FLAGS_DEFAULT, |
|
477 (EAPL("CEapDelayedShutdown::Start()\n"))); |
|
478 |
|
479 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapDelayedShutdown::Start()"); |
|
480 |
|
481 iTimer.After(iStatus, KEapShutdownInterval); |
|
482 SetActive(); |
|
483 } |
|
484 |
|
485 //---------------------------------------------------------------------------- |
|
486 |
|
487 void CEapDelayedShutdown::DoCancel() |
|
488 { |
|
489 EAP_TRACE_DEBUG( |
|
490 iTools, |
|
491 TRACE_FLAGS_DEFAULT, |
|
492 (EAPL("CEapDelayedShutdown::DoCancel()\n"))); |
|
493 |
|
494 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapDelayedShutdown::DoCancel()"); |
|
495 |
|
496 iTimer.Cancel(); |
|
497 } |
|
498 |
|
499 //---------------------------------------------------------------------------- |
|
500 |
|
501 TInt CEapDelayedShutdown::RunError(TInt aError) |
|
502 { |
|
503 EAP_TRACE_DEBUG( |
|
504 iTools, |
|
505 TRACE_FLAGS_DEFAULT, |
|
506 (EAPL("CEapDelayedShutdown::RunError(): aError=%d, this=0x%08x\n"), |
|
507 aError, |
|
508 this)); |
|
509 |
|
510 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapDelayedShutdown::RunError()"); |
|
511 |
|
512 iTimer.Cancel(); |
|
513 |
|
514 return aError; |
|
515 } |
|
516 |
|
517 //---------------------------------------------------------------------------- |
|
518 |
|
519 void CEapDelayedShutdown::RunL() |
|
520 { |
|
521 EAP_TRACE_DEBUG( |
|
522 iTools, |
|
523 TRACE_FLAGS_DEFAULT, |
|
524 (EAPL("CEapDelayedShutdown::RunL(), calls CActiveScheduler::Stop()\n"))); |
|
525 |
|
526 EAP_TRACE_RETURN_STRING(iTools, "returns: CEapDelayedShutdown::RunL()"); |
|
527 |
|
528 CActiveScheduler::Stop(); |
|
529 } |
|
530 |
|
531 //---------------------------------------------------------------------------- |
|
532 |
|
533 // end |