radioengine/engine/src/cradioengineimp.cpp
changeset 54 a8ba0c289b44
parent 47 74b7c6e79031
child 57 21be958eb3ce
--- a/radioengine/engine/src/cradioengineimp.cpp	Mon Sep 20 18:04:48 2010 +0300
+++ b/radioengine/engine/src/cradioengineimp.cpp	Tue Oct 05 09:31:22 2010 +0300
@@ -88,6 +88,38 @@
     LEVEL3( LOG_METHOD_AUTO );
     }
 
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+CRadioEngineImp* CRadioEngineImp::NewL()
+    {
+    LEVEL3( LOG_METHOD_AUTO );
+    
+    // audiorouter is required for constructing engine so we need to create it and
+    // radio system event collector as observer of audiorouter before creating the
+    // actual engine.
+    CRadioSystemEventCollector *eventCollector = CRadioSystemEventCollector::NewL();
+    CleanupStack::PushL( eventCollector );
+    
+    MRadioAudioRoutingObserver* observer = 0;
+    eventCollector->AsObserver( observer );
+    User::LeaveIfNull( observer );
+    
+    CRadioAudioRouter* audioRouter = CRadioAudioRouter::NewL( *( observer ) );
+    CleanupStack::PushL( audioRouter );
+    
+    CRadioEngineImp* self = new (ELeave) CRadioEngineImp( audioRouter );
+    
+    CleanupStack::Pop( audioRouter );
+    CleanupStack::Pop( eventCollector );  
+    
+    self->iSystemEventCollector = eventCollector;
+    self->ConstructL();
+    return self;
+    }
+
 // ---------------------------------------------------------------------------
 //
 // ---------------------------------------------------------------------------
@@ -96,13 +128,16 @@
     {
     LOG_METHOD_AUTO;
 
-    if ( !iAudioRouter || !iSystemEventCollector || !iSettings )
+    if ( !iAudioRouter || !iSystemEventCollector )
         {
         User::Leave( KErrNotReady );
         }
 
     iSystemEventCollector->AddObserverL( this );
 
+    iSettings = CRadioSettings::NewL();
+    iSettings->RadioSetter().SetObserver( this );
+    
     // Initial default values to be over by init
     User::LeaveIfError( iSettings->RadioSetter().SetPowerOn( EFalse ) );
 
@@ -120,6 +155,9 @@
 
     // Create timer that is used when polling for radio restart.
     iRadioTimer = CPeriodic::NewL( CActive::EPriorityHigh );
+    
+    InitRadioL( DetermineRegion() );
+    EnableAudio( ETrue );
     }
 
 // ---------------------------------------------------------------------------
@@ -176,27 +214,6 @@
 //
 // ---------------------------------------------------------------------------
 //
-void CRadioEngineImp::SetSystemEventCollector( CRadioSystemEventCollector* aCollector )
-    {
-    LEVEL3( LOG_METHOD_AUTO );
-    iSystemEventCollector = aCollector;
-    }
-
-// ---------------------------------------------------------------------------
-//
-// ---------------------------------------------------------------------------
-//
-void CRadioEngineImp::SetRadioSettings( CRadioSettings* aSettings )
-    {
-    LEVEL3( LOG_METHOD_AUTO );
-    iSettings = aSettings;
-    iSettings->RadioSetter().SetObserver( this );
-    }
-
-// ---------------------------------------------------------------------------
-//
-// ---------------------------------------------------------------------------
-//
 CRadioAudioRouter& CRadioEngineImp::AudioRouter() const
     {
     LEVEL3( LOG_METHOD_AUTO );