convergedconnectionhandler/cchserver/src/cchserverbase.cpp
branchRCL_3
changeset 14 be41ab7b952f
parent 0 a4daefaec16c
--- a/convergedconnectionhandler/cchserver/src/cchserverbase.cpp	Tue Apr 27 16:28:03 2010 +0300
+++ b/convergedconnectionhandler/cchserver/src/cchserverbase.cpp	Tue May 11 16:04:22 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -29,8 +29,10 @@
 #include "cchwakeupeventnotifier.h"
 #include "cchstartupcounter.h"
 #include "cchactivescheduler.h"
+#include "cchconnmonhandlernotifier.h"
 
 #include <ecom/ecom.h>
+#include <rconnmon.h>
 
 // EXTERNAL DATA STRUCTURES
 // None
@@ -260,18 +262,8 @@
 
     if ( iServiceHandler->IsStartupFlagSet() )
         {
-        // Start monitoring startup flag registration, this may set startup 
-        // flag to OFF if crashes happens more than KCCHMaxStartupCount during 
-        // startup flag registration
-        TRAP_IGNORE( CreateStartupCounterL() );
-        // If CCH cannot load the Plug-ins, CCH can still 
-        // try to load them later 
-        TRAP_IGNORE( iServiceHandler->LoadPluginsL() );
-        RequestStorage().ScanNetworks();
-        // initialization is now done. update states and send notification to 
-        // all clients
-        iServerObjectsInit = ETrue;
-        iServiceHandler->UpdateL();
+        // is snap ready to proceed startup
+        ConnMonHandler().ScanNetworks( ETrue, this );
         }
     else
         {
@@ -282,7 +274,30 @@
         }
     CCHLOGSTRING( "CCCHServerBase::InitServerObjectsL: OUT" );
     }
-    
+
+// ---------------------------------------------------------------------------
+// CCCHServerBase::ServiceStartupL
+// (other items were commented in a header).
+// ---------------------------------------------------------------------------
+//
+void CCCHServerBase::ServiceStartupL()
+    {
+    CCHLOGSTRING( "CCCHServerBase::ServiceStartupL: IN" );
+    // Start monitoring startup flag registration, this may set startup
+    // flag to OFF if crashes happens more than KCCHMaxStartupCount during
+    // startup flag registration
+    TRAP_IGNORE( CreateStartupCounterL() );
+    // If CCH cannot load the Plug-ins, CCH can still
+    // try to load them later
+    TRAP_IGNORE( iServiceHandler->LoadPluginsL() );
+    RequestStorage().ScanNetworks();
+    // initialization is now done. update states and send notification to
+    // all clients
+    iServerObjectsInit = ETrue;
+    iServiceHandler->UpdateL();
+    CCHLOGSTRING( "CCCHServerBase::ServiceStartupL: OUT" );
+    }
+
 // ---------------------------------------------------------------------------
 // CCCHServerBase::StartMinimalServerL
 // Start server in settings monitoring mode
@@ -641,6 +656,57 @@
     return shutDownAllowed;
     }
 
+// ---------------------------------------------------------------------------
+// From MCCHConnMonHandlerNotifier
+// CCCHServerBase::NetworkScanningCompletedL
+// ---------------------------------------------------------------------------
+//
+void CCCHServerBase::NetworkScanningCompletedL(
+    const TConnMonSNAPInfo& aSNAPs, TInt aError )
+    {
+    CCHLOGSTRING2( "CCCHServerBase::NetworkScanningCompletedL error = %d", aError );
+
+    if ( KErrNone == aError && aSNAPs.iCount  )
+        {
+        ServiceStartupL();
+        }
+    else if ( KErrNone == aError || KErrNotReady == aError )
+        {
+        // No SNAPs available. Start listen to availability change
+        ConnMonHandler().SetSNAPsAvailabilityChangeListener( this );
+        }
+    else
+        {
+        // exceptional error occured
+        ResetStartupCounterL();
+        StartMinimalServerL();
+        }
+    }
+
+// ---------------------------------------------------------------------------
+// From MCCHConnMonHandlerNotifier
+// CCCHServerBase::SNAPsAvailabilityChanged
+// ---------------------------------------------------------------------------
+//
+void CCCHServerBase::SNAPsAvailabilityChanged( TInt aError )
+    {
+    CCHLOGSTRING2( "CCCHServerBase::SNAPsAvailabilityChanged error = %d", aError );
+    
+    // Stop event receiving
+    ConnMonHandler().SetSNAPsAvailabilityChangeListener( NULL );
+    
+    if ( KErrNone == aError || KErrTimedOut == aError )
+        {
+        ServiceStartupL();
+        }
+    else
+        {
+        // exceptional error occured
+        ResetStartupCounterL();
+        StartMinimalServerL();
+        }
+    }
+
 // ========================== OTHER EXPORTED FUNCTIONS =======================
 
 // ---------------------------------------------------------------------------