idlefw/src/framework/aistateprovider.cpp
branchRCL_3
changeset 18 bd874ee5e5e2
parent 9 d0529222e3f0
child 51 15e4dd19031c
--- a/idlefw/src/framework/aistateprovider.cpp	Fri Feb 19 23:07:29 2010 +0200
+++ b/idlefw/src/framework/aistateprovider.cpp	Fri Mar 12 15:43:54 2010 +0200
@@ -40,11 +40,10 @@
 // Two-phased constructor.
 // ----------------------------------------------------------------------------
 //
-CAiStateProvider* CAiStateProvider::NewL( 
-    MAiStateObserver& aObserver, CCoeEnv& aCoeEnv )
+CAiStateProvider* CAiStateProvider::NewL( MAiStateObserver& aObserver )     
     {
     CAiStateProvider* self = 
-        CAiStateProvider::NewLC( aObserver, aCoeEnv );
+        CAiStateProvider::NewLC( aObserver );
     
     CleanupStack::Pop( self );
     
@@ -56,11 +55,10 @@
 // Two-phased constructor.
 // ----------------------------------------------------------------------------
 //
-CAiStateProvider* CAiStateProvider::NewLC( 
-    MAiStateObserver& aObserver, CCoeEnv& aCoeEnv )
+CAiStateProvider* CAiStateProvider::NewLC( MAiStateObserver& aObserver )     
     {
     CAiStateProvider* self = 
-        new ( ELeave ) CAiStateProvider( aObserver, aCoeEnv );
+        new ( ELeave ) CAiStateProvider( aObserver );
     
     CleanupStack::PushL( self );
     self->ConstructL();
@@ -74,18 +72,8 @@
 // ----------------------------------------------------------------------------
 //
 CAiStateProvider::~CAiStateProvider()
-    {        
-    iObserver.NotifyStateChange( EAiFwUiShutdown );
-    
-    iCoeEnv.RemoveMessageMonitorObserver( *this );
-    
-    delete iEcomObserver;
-    
-    iSkinSrv.Close();
-           
-    Release( iBackupRestoreObserver );
-    
-    delete iLightObserver;       
+    {  
+    Stop();
     }
 
 // ----------------------------------------------------------------------------
@@ -93,11 +81,9 @@
 // C++ default constructor.
 // ----------------------------------------------------------------------------
 //
-CAiStateProvider::CAiStateProvider( MAiStateObserver& aObserver, 
-    CCoeEnv& aCoeEnv )     
-    : iObserver( aObserver ), iCoeEnv( aCoeEnv )
-    {  
-    iObserver.NotifyStateChange( EAiFwUiStartup );
+CAiStateProvider::CAiStateProvider( MAiStateObserver& aObserver )        
+    : iObserver( aObserver )
+    {      
     }
 
 // ----------------------------------------------------------------------------
@@ -107,18 +93,69 @@
 //
 void CAiStateProvider::ConstructL()
     {
-    iLightObserver = CHWRMLight::NewL( this );
-    
-    iBackupRestoreObserver = AiUtility::CreatePSPropertyObserverL(
-        TCallBack( BackupRestoreEvent, this ),
-        KUidSystemCategory, conn::KUidBackupRestoreKey );
-    
-    User::LeaveIfError( iSkinSrv.Connect( this ) );
-       
-    iEcomObserver = CAiEcomObserver::NewL();
-    iEcomObserver->AddObserverL( this );
-    
-    iCoeEnv.AddMessageMonitorObserverL( *this );
+    }
+
+// ----------------------------------------------------------------------------
+// CAiStateProvider::StartL()
+// 
+// ----------------------------------------------------------------------------
+//
+void CAiStateProvider::StartL( CCoeEnv& aCoeEnv )
+    {
+    if ( !iStarted )
+        {        
+        iStarted = ETrue;
+                        
+        iObserver.NotifyStateChange( EAiFwUiStartup );
+        
+        iLightObserver = CHWRMLight::NewL( this );
+        
+        iBackupRestoreObserver = AiUtility::CreatePSPropertyObserverL(
+            TCallBack( BackupRestoreEvent, this ),
+            KUidSystemCategory, conn::KUidBackupRestoreKey );
+        
+        User::LeaveIfError( iSkinSrv.Connect( this ) );
+           
+        iEcomObserver = CAiEcomObserver::NewL();
+        iEcomObserver->AddObserverL( this );
+        
+        iCoeEnv = &aCoeEnv;
+        
+        iCoeEnv->AddMessageMonitorObserverL( *this );
+        }
+    }
+
+// ----------------------------------------------------------------------------
+// CAiStateProvider::Stop()
+// 
+// ----------------------------------------------------------------------------
+//
+void CAiStateProvider::Stop()
+    {
+    if ( iStarted )
+        {
+        iStarted = EFalse;
+        
+        iObserver.NotifyStateChange( EAiFwUiShutdown );
+        
+        if ( iCoeEnv )
+            {
+            iCoeEnv->RemoveMessageMonitorObserver( *this );        
+            }
+                
+        iCoeEnv = NULL;
+        
+        delete iEcomObserver;
+        iEcomObserver = NULL;
+        
+        iSkinSrv.Close();
+               
+        Release( iBackupRestoreObserver );
+        iBackupRestoreObserver = NULL;
+        
+        delete iLightObserver;      
+        iLightObserver = NULL;
+        }           
     }
 
 // ----------------------------------------------------------------------------