1 /* |
|
2 * Copyright (c) 2006-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 "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: CCCHServerBase implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cchlogger.h" |
|
21 #include "cchserverbase.h" |
|
22 #include "cchsession.h" |
|
23 #include "cchrequeststorage.h" |
|
24 #include "cchconnmonhandler.h" |
|
25 #include "cchspshandler.h" |
|
26 #include "cchservicehandler.h" |
|
27 #include "cchpluginhandler.h" |
|
28 #include "cchfeaturemanager.h" |
|
29 #include "cchwakeupeventnotifier.h" |
|
30 #include "cchstartupcounter.h" |
|
31 #include "cchactivescheduler.h" |
|
32 #include "cchconnmonhandlernotifier.h" |
|
33 |
|
34 #include <ecom/ecom.h> |
|
35 #include <rconnmon.h> |
|
36 |
|
37 // EXTERNAL DATA STRUCTURES |
|
38 // None |
|
39 |
|
40 // EXTERNAL FUNCTION PROTOTYPES |
|
41 // None |
|
42 |
|
43 // CONSTANTS |
|
44 // None |
|
45 |
|
46 // MACROS |
|
47 // None |
|
48 |
|
49 // LOCAL CONSTANTS AND MACROS |
|
50 // None |
|
51 |
|
52 // MODULE DATA STRUCTURES |
|
53 // None |
|
54 |
|
55 // LOCAL FUNCTION PROTOTYPES |
|
56 GLDEF_C TInt E32Main(); |
|
57 #ifdef _DEBUG |
|
58 GLDEF_C void MemUsage(); |
|
59 #endif |
|
60 // FORWARD DECLARATIONS |
|
61 // None |
|
62 |
|
63 // ============================= LOCAL FUNCTIONS ============================= |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // InitServerL Creates CCHServer. |
|
67 // Returns: None. |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 static void InitServerL() |
|
71 { |
|
72 CCHLOGSTRING("CCCHServerBase::InitServerL"); |
|
73 |
|
74 // This is only for startup situation, because starter does not use |
|
75 // connect metod, which in normal situation reserves the mutex |
|
76 RMutex serverStartMutex; |
|
77 CleanupClosePushL( serverStartMutex ); |
|
78 TInt createError( serverStartMutex.CreateGlobal( KCCHServerStartMutex ) ); |
|
79 if ( KErrNone != createError ) |
|
80 { |
|
81 User::LeaveIfError( serverStartMutex.OpenGlobal( KCCHServerStartMutex ) ); |
|
82 } |
|
83 |
|
84 serverStartMutex.Wait(); |
|
85 CCHLOGSTRING( "CCCHServerBase::InitServerL: mutex available" ); |
|
86 |
|
87 TFullName name; |
|
88 TFindServer findServer( KCCHServerName ); |
|
89 // Check that the server does not exists. |
|
90 if( findServer.Next( name ) == KErrNotFound ) |
|
91 { |
|
92 User::LeaveIfError( User::RenameThread( KCCHServerName ) ); |
|
93 |
|
94 // create and install the active scheduler we need |
|
95 CCchActiveScheduler* scheduler = new (ELeave) CCchActiveScheduler; |
|
96 CleanupStack::PushL( scheduler ); |
|
97 CActiveScheduler::Install( scheduler ); |
|
98 |
|
99 // create the server (leave it on the cleanup stack) |
|
100 CCCHServerBase* server = NULL; |
|
101 TRAPD( err, server = CCCHServerBase::NewL() ); |
|
102 |
|
103 if ( KErrNone != err ) |
|
104 { |
|
105 CCHLOGSTRING2 |
|
106 ("InitServerL: Server creation failed, error = %d", err ); |
|
107 |
|
108 server->PanicServer( ECCHErrCreateServer ); |
|
109 } |
|
110 |
|
111 // Scheduler needs server, because server might needs to be restarted |
|
112 scheduler->SetServer( server ); |
|
113 // Initialisation complete, now signal the client |
|
114 RProcess::Rendezvous( KErrNone ); |
|
115 |
|
116 // Release and close mutex |
|
117 CCHLOGSTRING( "CCCHServerBase::InitServerL: Release the mutex" ); |
|
118 serverStartMutex.Signal(); |
|
119 serverStartMutex.Close(); |
|
120 |
|
121 // Ready to run |
|
122 CCHLOGSTRING( "CCCHServerBase::InitServerL: Server Running..." ); |
|
123 CActiveScheduler::Start(); |
|
124 |
|
125 // Cleanup the mutex, scheduler and server |
|
126 delete server; |
|
127 server = NULL; |
|
128 |
|
129 CleanupStack::PopAndDestroy( scheduler ); |
|
130 } |
|
131 else |
|
132 { |
|
133 CCHLOGSTRING( "CCCHServerBase::InitServerL: cch server already exists" ); |
|
134 RProcess::Rendezvous( KErrAlreadyExists ); |
|
135 // Release and close mutex |
|
136 CCHLOGSTRING( "CCCHServerBase::InitServerL: Release the mutex" ); |
|
137 serverStartMutex.Signal(); |
|
138 serverStartMutex.Close(); |
|
139 } |
|
140 CleanupStack::PopAndDestroy( &serverStartMutex ); |
|
141 } |
|
142 |
|
143 // ============================ MEMBER FUNCTIONS ============================= |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // CCCHServerBase::CCCHServerBase |
|
147 // C++ default constructor can NOT contain any code, that might leave. |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 CCCHServerBase::CCCHServerBase() : |
|
151 CPolicyServer( EPriorityHigh, KCCHPolicy ), |
|
152 iSessionCounter( 0 ) |
|
153 { |
|
154 CCHLOGSTRING( "CCCHServerBase::CCCHServerBase" ); |
|
155 iVoIPEmergencyNoteShown = EFalse; |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CCCHServerBase::ConstructL |
|
160 // Symbian 2nd phase constructor can leave. |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 void CCCHServerBase::ConstructL() |
|
164 { |
|
165 CCHLOGSTRING( "CCCHServerBase::ConstructL" ); |
|
166 iWakeUpEventNotifier = CCchWakeUpEventNotifier::NewL( *this ); |
|
167 |
|
168 InitServerObjectsL(); |
|
169 //Start server |
|
170 StartL( KCCHServerName ); |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CCCHServerBase::NewL |
|
175 // Two-phased constructor. |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 CCCHServerBase* CCCHServerBase::NewL() |
|
179 { |
|
180 CCCHServerBase* self = CCCHServerBase::NewLC(); |
|
181 CleanupStack::Pop( self ); |
|
182 return self; |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // CCCHServerBase::NewLC |
|
187 // Two-phased constructor. |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 CCCHServerBase* CCCHServerBase::NewLC() |
|
191 { |
|
192 CCCHServerBase* self = new (ELeave)CCCHServerBase(); |
|
193 CleanupStack::PushL( self ); |
|
194 self->ConstructL(); |
|
195 return self; |
|
196 } |
|
197 |
|
198 // Destructor |
|
199 CCCHServerBase::~CCCHServerBase() |
|
200 { |
|
201 delete iStartupCounter; |
|
202 delete iWakeUpEventNotifier; |
|
203 |
|
204 ReleaseAllResources(); |
|
205 REComSession::FinalClose(); |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // CCCHServerBase::NewSessionL |
|
210 // This is called by RSessionBase (base class for client interface). |
|
211 // Two-phased constructor. |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 CSession2* CCCHServerBase::NewSessionL( const TVersion& aVersion, |
|
215 const RMessage2& /* aMessage */ ) const |
|
216 { |
|
217 CCHLOGSTRING( "CCCHServerBase::NewSessionL" ); |
|
218 |
|
219 TVersion version( KCCHServMajorVersionNumber, |
|
220 KCCHServMinorVersionNumber, |
|
221 KCCHServBuildVersionNumber ); |
|
222 |
|
223 if ( !User::QueryVersionSupported( version , aVersion ) ) |
|
224 { |
|
225 User::Leave( KErrNotSupported ); |
|
226 } |
|
227 CCCHSession* session = |
|
228 CCCHSession::NewL( const_cast<CCCHServerBase&>( *this ) ); |
|
229 return session; |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------------------------- |
|
233 // CCCHServerBase::ShutdownServerL |
|
234 // (other items were commented in a header). |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 void CCCHServerBase::ShutDownServerL() |
|
238 { |
|
239 CCHLOGSTRING( "CCCHServerBase::ShutDownServerL - IN" ); |
|
240 |
|
241 if ( !iSessionCounter && IsServerShutdownAllowedL() ) |
|
242 { |
|
243 CCHLOGSTRING( "CCCHServerBase::ShutDownServerL - Allowed" ); |
|
244 // if session counter is zero -> close server |
|
245 // MSI: Shouldn't we continue in minimal mode? |
|
246 // CActiveScheduler::Current()->Stop(); |
|
247 TRAP_IGNORE( StartMinimalServerL() ); |
|
248 } |
|
249 CCHLOGSTRING( "CCCHServerBase::ShutDownServerL - OUT" ); |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // CCCHServerBase::InitServerL |
|
254 // (other items were commented in a header). |
|
255 // --------------------------------------------------------------------------- |
|
256 // |
|
257 void CCCHServerBase::InitServerObjectsL() |
|
258 { |
|
259 CCHLOGSTRING( "CCCHServerBase::InitServerObjectsL: IN" ); |
|
260 |
|
261 ServiceHandler().InitServiceHandlerL(); |
|
262 |
|
263 if ( iServiceHandler->IsStartupFlagSet() ) |
|
264 { |
|
265 // is snap ready to proceed startup |
|
266 ConnMonHandler().ScanNetworks( ETrue, this ); |
|
267 } |
|
268 else |
|
269 { |
|
270 // Startup flag is not ON, we have to be sure that startup counter |
|
271 // is truly zero for the next time when startup flag is ON |
|
272 ResetStartupCounterL(); |
|
273 StartMinimalServerL(); |
|
274 } |
|
275 CCHLOGSTRING( "CCCHServerBase::InitServerObjectsL: OUT" ); |
|
276 } |
|
277 |
|
278 // --------------------------------------------------------------------------- |
|
279 // CCCHServerBase::ServiceStartupL |
|
280 // (other items were commented in a header). |
|
281 // --------------------------------------------------------------------------- |
|
282 // |
|
283 void CCCHServerBase::ServiceStartupL() |
|
284 { |
|
285 CCHLOGSTRING( "CCCHServerBase::ServiceStartupL: IN" ); |
|
286 // Start monitoring startup flag registration, this may set startup |
|
287 // flag to OFF if crashes happens more than KCCHMaxStartupCount during |
|
288 // startup flag registration |
|
289 TRAP_IGNORE( CreateStartupCounterL() ); |
|
290 // If CCH cannot load the Plug-ins, CCH can still |
|
291 // try to load them later |
|
292 TRAP_IGNORE( iServiceHandler->LoadPluginsL() ); |
|
293 RequestStorage().ScanNetworks(); |
|
294 // initialization is now done. update states and send notification to |
|
295 // all clients |
|
296 iServerObjectsInit = ETrue; |
|
297 iServiceHandler->UpdateL(); |
|
298 CCHLOGSTRING( "CCCHServerBase::ServiceStartupL: OUT" ); |
|
299 } |
|
300 |
|
301 // --------------------------------------------------------------------------- |
|
302 // CCCHServerBase::StartMinimalServerL |
|
303 // Start server in settings monitoring mode |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 void CCCHServerBase::StartMinimalServerL() |
|
307 { |
|
308 CCHLOGSTRING( "CCCHServerBase::StartMinimalServerL IN" ); |
|
309 |
|
310 iWakeUpEventNotifier->StartL(); |
|
311 ReleaseAllResources(); |
|
312 CCHLOGSTRING( "CCCHServerBase::StartMinimalServerL OUT" ); |
|
313 } |
|
314 |
|
315 // --------------------------------------------------------------------------- |
|
316 // CCCHServerBase::ReleaseAllResources |
|
317 // Start server in settings monitoring mode |
|
318 // --------------------------------------------------------------------------- |
|
319 // |
|
320 void CCCHServerBase::ReleaseAllResources() |
|
321 { |
|
322 CCHLOGSTRING( "CCCHServerBase::ReleaseAllResources" ); |
|
323 |
|
324 delete iServiceHandler; |
|
325 iServiceHandler = NULL; |
|
326 delete iSPSHandler; |
|
327 iSPSHandler = NULL; |
|
328 delete iConnMonHandler; |
|
329 iConnMonHandler = NULL; |
|
330 delete iRequestStorage; |
|
331 iRequestStorage = NULL; |
|
332 delete iPluginHandler; |
|
333 iPluginHandler = NULL; |
|
334 delete iFeatureManager; |
|
335 iFeatureManager = NULL; |
|
336 delete iObjectConIx; |
|
337 iObjectConIx = NULL; |
|
338 } |
|
339 |
|
340 |
|
341 // --------------------------------------------------------------------------- |
|
342 // CCCHServerBase::NotifySessionCreatedL |
|
343 // Increase session counter |
|
344 // (other items were commented in a header). |
|
345 // --------------------------------------------------------------------------- |
|
346 // |
|
347 void CCCHServerBase::NotifySessionCreatedL() |
|
348 { |
|
349 CCHLOGSTRING( "CCCHServerBase::NotifySessionCreatedL" ); |
|
350 |
|
351 iWakeUpEventNotifier->Stop(); |
|
352 |
|
353 if ( iSessionCounter == 0 && IsServerShutdownAllowedL() ) |
|
354 { |
|
355 ServiceHandler().InitServiceHandlerL(); |
|
356 } |
|
357 iSessionCounter++; |
|
358 } |
|
359 |
|
360 // --------------------------------------------------------------------------- |
|
361 // CCCHServerBase::NotifySessionClosed |
|
362 // Decrease session counter |
|
363 // (other items were commented in a header). |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 void CCCHServerBase::NotifySessionClosed() |
|
367 { |
|
368 CCHLOGSTRING( "CCCHServerBase::NotifySessionClosed" ); |
|
369 if ( 0 < iSessionCounter ) |
|
370 { |
|
371 iSessionCounter--; |
|
372 } |
|
373 if ( 0 >= iSessionCounter ) |
|
374 { |
|
375 iSessionCounter = 0; |
|
376 TRAP_IGNORE( ShutDownServerL() ); |
|
377 } |
|
378 } |
|
379 |
|
380 // --------------------------------------------------------------------------- |
|
381 // CCCHServerBase::PanicClient |
|
382 // Panic client with given error code. |
|
383 // (other items were commented in a header). |
|
384 // --------------------------------------------------------------------------- |
|
385 // |
|
386 void CCCHServerBase::PanicClient( |
|
387 const RMessage2& aMessage, |
|
388 TInt aPanic ) |
|
389 { |
|
390 CCHLOGSTRING2("CCCHServerBase::PanicClient: Panic = %d", aPanic ); |
|
391 _LIT( KTxtServer, "CCH Server Client" ); |
|
392 aMessage.Panic( KTxtServer, aPanic ); |
|
393 CCHLOGSTRING("CCCHServerBase::PanicClient exiting" ); |
|
394 } |
|
395 |
|
396 // --------------------------------------------------------------------------- |
|
397 // PanicServer implements server panic handler. |
|
398 // Panic server with given error code. |
|
399 // Returns: None. |
|
400 // --------------------------------------------------------------------------- |
|
401 // |
|
402 void CCCHServerBase::PanicServer( |
|
403 TInt aPanic ) |
|
404 { |
|
405 CCHLOGSTRING2("CCCHServerBase::PanicServer: Panic = %d", aPanic ); |
|
406 _LIT( KTxtServerPanic, "CCH Server" ); |
|
407 User::Panic( KTxtServerPanic, aPanic ); |
|
408 CCHLOGSTRING("CCCHServerBase::PanicServer exit" ); |
|
409 } |
|
410 |
|
411 // --------------------------------------------------------------------------- |
|
412 // CCCHServerBase::ConstructObject |
|
413 // Create requested object and/or return reference to it. |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 template <class T>T& CCCHServerBase::ConstructObject( |
|
417 CCCHServerBase* aThis, |
|
418 T*& aObject ) |
|
419 { |
|
420 TInt error = KErrNone; |
|
421 if ( !aObject ) |
|
422 { |
|
423 TRAP( error, aObject = T::NewL( *aThis ) ); |
|
424 } |
|
425 |
|
426 if ( KErrNone != error ) |
|
427 { |
|
428 // Failed to create object, have to Panic! |
|
429 PanicServer( ECCHErrCreateServer ); |
|
430 } |
|
431 return *aObject; |
|
432 } |
|
433 |
|
434 // --------------------------------------------------------------------------- |
|
435 // CCCHServerBase::ConstructObject |
|
436 // Create requested object and/or return reference to it. |
|
437 // --------------------------------------------------------------------------- |
|
438 // |
|
439 template <class T>T& CCCHServerBase::ConstructObject( |
|
440 T*& aObject ) |
|
441 { |
|
442 TInt error = KErrNone; |
|
443 if ( !aObject ) |
|
444 { |
|
445 TRAP( error, aObject = T::NewL() ); |
|
446 } |
|
447 |
|
448 if ( KErrNone != error ) |
|
449 { |
|
450 // Failed to create object, have to Panic! |
|
451 PanicServer( ECCHErrCreateServer ); |
|
452 } |
|
453 return *aObject; |
|
454 } |
|
455 |
|
456 TBool CCCHServerBase::VoIPEmergencyNoteShown() |
|
457 { |
|
458 return iVoIPEmergencyNoteShown; |
|
459 } |
|
460 |
|
461 void CCCHServerBase::SetVoIPEmergencyNoteShown( TBool aShown ) |
|
462 { |
|
463 iVoIPEmergencyNoteShown = aShown; |
|
464 } |
|
465 |
|
466 // --------------------------------------------------------------------------- |
|
467 // CCCHServerBase::ObjectContainerIx |
|
468 // Return object container index. |
|
469 // (other items were commented in a header). |
|
470 // --------------------------------------------------------------------------- |
|
471 // |
|
472 CObjectConIx& CCCHServerBase::ObjectContainerIx() |
|
473 { |
|
474 return ConstructObject<CObjectConIx>( iObjectConIx ); |
|
475 } |
|
476 |
|
477 // --------------------------------------------------------------------------- |
|
478 // CCCHServerBase::RequestStorage |
|
479 // Return instance of request storage. |
|
480 // (other items were commented in a header). |
|
481 // --------------------------------------------------------------------------- |
|
482 // |
|
483 CCCHRequestStorage& CCCHServerBase::RequestStorage() |
|
484 { |
|
485 return ConstructObject<CCCHRequestStorage>( this, iRequestStorage ); |
|
486 } |
|
487 |
|
488 // --------------------------------------------------------------------------- |
|
489 // CCCHServerBase::ConnMonHandler |
|
490 // Return instance of ConnMonHandler. |
|
491 // (other items were commented in a header). |
|
492 // --------------------------------------------------------------------------- |
|
493 // |
|
494 CCCHConnMonHandler& CCCHServerBase::ConnMonHandler() |
|
495 { |
|
496 return ConstructObject<CCCHConnMonHandler>( this, iConnMonHandler ); |
|
497 } |
|
498 |
|
499 // ----------------------------------------------------------------------------- |
|
500 // CCCHServerBase::PluginHandler |
|
501 // Return instance of plug-in handler. |
|
502 // (other items were commented in a header). |
|
503 // ----------------------------------------------------------------------------- |
|
504 // |
|
505 CCCHPluginHandler& CCCHServerBase::PluginHandler() |
|
506 { |
|
507 return ConstructObject<CCCHPluginHandler>( this, iPluginHandler ); |
|
508 } |
|
509 |
|
510 // --------------------------------------------------------------------------- |
|
511 // CCCHServerBase::SPSHandler |
|
512 // Return instance of SPSHandler. |
|
513 // (other items were commented in a header). |
|
514 // --------------------------------------------------------------------------- |
|
515 // |
|
516 CCCHSPSHandler& CCCHServerBase::SPSHandler() |
|
517 { |
|
518 return ConstructObject<CCCHSPSHandler>( this, iSPSHandler ); |
|
519 } |
|
520 |
|
521 // --------------------------------------------------------------------------- |
|
522 // CCCHServerBase::ServiceHandler |
|
523 // Return instance of ServiceHandler. |
|
524 // (other items were commented in a header). |
|
525 // --------------------------------------------------------------------------- |
|
526 // |
|
527 CCCHServiceHandler& CCCHServerBase::ServiceHandler() |
|
528 { |
|
529 return ConstructObject<CCCHServiceHandler>( this, iServiceHandler ); |
|
530 } |
|
531 |
|
532 // --------------------------------------------------------------------------- |
|
533 // CCCHServerBase::FeatureManager |
|
534 // Return instance of FeatureManager. |
|
535 // (other items were commented in a header). |
|
536 // --------------------------------------------------------------------------- |
|
537 // |
|
538 CCchFeatureManager& CCCHServerBase::FeatureManager() |
|
539 { |
|
540 return ConstructObject<CCchFeatureManager>( iFeatureManager ); |
|
541 } |
|
542 |
|
543 // --------------------------------------------------------------------------- |
|
544 // CCCHServerBase::WakeUp |
|
545 // Creates all required objects needed by full server mode. |
|
546 // --------------------------------------------------------------------------- |
|
547 // |
|
548 void CCCHServerBase::WakeUp() |
|
549 { |
|
550 CCHLOGSTRING( "CCCHServerBase::WakeUp IN" ); |
|
551 if ( iSessionCounter == 0 && !iServerObjectsInit ) |
|
552 { |
|
553 TRAPD( err, InitServerObjectsL() ); |
|
554 if ( KErrNone != err ) |
|
555 { |
|
556 // Failed to create required objects, have to Panic! |
|
557 PanicServer( ECCHErrCreateServer ); |
|
558 } |
|
559 } |
|
560 CCHLOGSTRING( "CCCHServerBase::WakeUp OUT" ); |
|
561 } |
|
562 |
|
563 // --------------------------------------------------------------------------- |
|
564 // CCCHServerBase::CreateStartupCounterL |
|
565 // |
|
566 // (other items were commented in a header). |
|
567 // --------------------------------------------------------------------------- |
|
568 // |
|
569 void CCCHServerBase::CreateStartupCounterL() |
|
570 { |
|
571 if ( !iStartupCounter ) |
|
572 { |
|
573 iStartupCounter = CCchStartupCounter::NewL( *this ); |
|
574 } |
|
575 iStartupCounter->StartupOccuredL(); |
|
576 } |
|
577 |
|
578 // --------------------------------------------------------------------------- |
|
579 // CCCHServerBase::ResetStartupCounterL |
|
580 // |
|
581 // (other items were commented in a header). |
|
582 // --------------------------------------------------------------------------- |
|
583 // |
|
584 void CCCHServerBase::ResetStartupCounterL() |
|
585 { |
|
586 if ( !iStartupCounter ) |
|
587 { |
|
588 iStartupCounter = CCchStartupCounter::NewL( *this ); |
|
589 } |
|
590 iStartupCounter->ResetStartupCounter(); |
|
591 delete iStartupCounter; |
|
592 iStartupCounter = NULL; |
|
593 } |
|
594 |
|
595 // --------------------------------------------------------------------------- |
|
596 // CCCHServerBase::Restart |
|
597 // |
|
598 // (other items were commented in a header). |
|
599 // --------------------------------------------------------------------------- |
|
600 // |
|
601 void CCCHServerBase::Restart() |
|
602 { |
|
603 CCHLOGSTRING( "CCCHServerBase::Restart IN" ); |
|
604 |
|
605 // Send notify to our client |
|
606 TRAP_IGNORE( iServiceHandler->HandleRestartL() ); |
|
607 |
|
608 // Do we have to make reregistration |
|
609 if ( iServiceHandler->IsStartupFlagSet() ) |
|
610 { |
|
611 delete iServiceHandler; |
|
612 iServiceHandler = NULL; |
|
613 delete iPluginHandler; |
|
614 iPluginHandler = NULL; |
|
615 TRAP_IGNORE( InitServerObjectsL() ); |
|
616 } |
|
617 |
|
618 CCHLOGSTRING( "CCCHServerBase::Restart OUT" ); |
|
619 } |
|
620 |
|
621 // --------------------------------------------------------------------------- |
|
622 // CCCHServerBase::IsServerShutdownAllowedL |
|
623 // (other items were commented in a header). |
|
624 // --------------------------------------------------------------------------- |
|
625 // |
|
626 TBool CCCHServerBase::IsServerShutdownAllowedL() |
|
627 { |
|
628 CCHLOGSTRING( "CCCHServerBase::IsServerShutdownAllowedL" ); |
|
629 |
|
630 TBool shutDownAllowed( ETrue ); |
|
631 |
|
632 if ( iSPSHandler && iServiceHandler ) |
|
633 { |
|
634 // Get service IDs |
|
635 RArray<TUint> serviceIds; |
|
636 CleanupClosePushL( serviceIds ); |
|
637 |
|
638 iSPSHandler->GetServiceIdsL( serviceIds ); |
|
639 |
|
640 TCCHSubserviceState state( ECCHUninitialized ); |
|
641 |
|
642 for ( TInt i( 0 ); i < serviceIds.Count(); i++ ) |
|
643 { |
|
644 state = iServiceHandler->ServiceState( serviceIds[i] ); |
|
645 |
|
646 if ( ECCHDisabled != state && ECCHUninitialized != state ) |
|
647 { |
|
648 shutDownAllowed = EFalse; |
|
649 } |
|
650 } |
|
651 |
|
652 CleanupStack::PopAndDestroy( &serviceIds ); |
|
653 } |
|
654 |
|
655 CCHLOGSTRING2("CCCHServerBase::IsServerShutdownAllowedL: shutDownAllowed = %d", shutDownAllowed ); |
|
656 return shutDownAllowed; |
|
657 } |
|
658 |
|
659 // --------------------------------------------------------------------------- |
|
660 // From MCCHConnMonHandlerNotifier |
|
661 // CCCHServerBase::NetworkScanningCompletedL |
|
662 // --------------------------------------------------------------------------- |
|
663 // |
|
664 void CCCHServerBase::NetworkScanningCompletedL( |
|
665 const TConnMonSNAPInfo& aSNAPs, TInt aError ) |
|
666 { |
|
667 CCHLOGSTRING2( "CCCHServerBase::NetworkScanningCompletedL error = %d", aError ); |
|
668 |
|
669 if ( KErrNone == aError && aSNAPs.iCount ) |
|
670 { |
|
671 ServiceStartupL(); |
|
672 } |
|
673 else if ( KErrNone == aError || KErrNotReady == aError ) |
|
674 { |
|
675 // No SNAPs available. Start listen to availability change |
|
676 ConnMonHandler().SetSNAPsAvailabilityChangeListener( this ); |
|
677 } |
|
678 else |
|
679 { |
|
680 // exceptional error occured |
|
681 ResetStartupCounterL(); |
|
682 StartMinimalServerL(); |
|
683 } |
|
684 } |
|
685 |
|
686 // --------------------------------------------------------------------------- |
|
687 // From MCCHConnMonHandlerNotifier |
|
688 // CCCHServerBase::SNAPsAvailabilityChanged |
|
689 // --------------------------------------------------------------------------- |
|
690 // |
|
691 void CCCHServerBase::SNAPsAvailabilityChanged( TInt aError ) |
|
692 { |
|
693 CCHLOGSTRING2( "CCCHServerBase::SNAPsAvailabilityChanged error = %d", aError ); |
|
694 |
|
695 // Stop event receiving |
|
696 ConnMonHandler().SetSNAPsAvailabilityChangeListener( NULL ); |
|
697 |
|
698 if ( KErrNone == aError || KErrTimedOut == aError ) |
|
699 { |
|
700 ServiceStartupL(); |
|
701 } |
|
702 else |
|
703 { |
|
704 // exceptional error occured |
|
705 ResetStartupCounterL(); |
|
706 StartMinimalServerL(); |
|
707 } |
|
708 } |
|
709 |
|
710 // ========================== OTHER EXPORTED FUNCTIONS ======================= |
|
711 |
|
712 // --------------------------------------------------------------------------- |
|
713 // E32Main implements the executable entry function. |
|
714 // Note that because the target type of the CCHServer module |
|
715 // is EXEDLL, the entry point has different signature depending |
|
716 // on the build platform. |
|
717 // Creates a cleanup stack and runs the server. |
|
718 // Returns: Zero |
|
719 // --------------------------------------------------------------------------- |
|
720 // |
|
721 GLDEF_C TInt E32Main() |
|
722 { |
|
723 TInt error( KErrNoMemory ); |
|
724 __UHEAP_MARK; |
|
725 CCHLOGSTRING( "CCCHServerBase E32Main" ); |
|
726 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
727 |
|
728 |
|
729 if ( cleanup ) |
|
730 { |
|
731 TRAP( error, InitServerL() ); |
|
732 delete cleanup; |
|
733 } |
|
734 |
|
735 __UHEAP_MARKEND; |
|
736 |
|
737 return error; |
|
738 } |
|
739 |
|
740 // End of File |
|