accessoryservices/pluggeddisplay/pluggeddisplayengine/src/hdmicablestateconnected.cpp
branchGCC_SURGE
changeset 49 00076e39386f
parent 45 c6215323ad55
child 60 ccb4f6b3db21
--- a/accessoryservices/pluggeddisplay/pluggeddisplayengine/src/hdmicablestateconnected.cpp	Wed Jun 23 22:58:50 2010 +0100
+++ b/accessoryservices/pluggeddisplay/pluggeddisplayengine/src/hdmicablestateconnected.cpp	Thu Jul 22 16:45:41 2010 +0100
@@ -28,6 +28,9 @@
 #include "tvoutconfigforhdmi.h"
 #include "edidhandler.h"
 #include "trace.h"
+#include <centralrepository.h>
+#include <accessoriescrkeys.h>
+#include <tvoutconfig.h>
 
 
 
@@ -77,8 +80,73 @@
         iTVOutConfigForSettingChanges->Cancel();
         delete iTVOutConfigForSettingChanges;
         }
+    if ( iCRWatchForVOverScan )
+        {
+        iCRWatchForVOverScan->Cancel();
+        delete iCRWatchForVOverScan;        
+        }
     }
 
+// ---------------------------------------------------------------------------
+// From MCentralRepositoryObserver.
+// ---------------------------------------------------------------------------
+//
+void CHDMICableStateConnected::CentRepKeyChanged(
+        TUid    aRepositoryId,
+        TUint32 aId )
+    {
+    FUNC_LOG;
+    if ( KCRUidTvoutSettings == aRepositoryId )
+        {
+        if ( KSettingsTvoutVerticalOverscan == aId  )
+            {            
+			INFO("Cenrep Value Changed");
+			if( iEDIDHandler.UpdateOverscanValues() )
+				{
+				INFO( "There is a real change" );
+            	Input( EPDEIfCentralRepositoryWatch, EPDEIfCentralRepositoryWatchEventKeyChanged );
+				}
+            }
+        else
+            {
+            INFO_1("Unexpected CR key ID, aId 0x%x", aId );            
+            }       
+        }
+    else
+        {
+        INFO_1("Unexpected Central Repository ID, aRepositoryId 0x%x", aRepositoryId);
+        }
+
+    }
+
+// ---------------------------------------------------------------------------
+// From MCentralRepositoryObserver.
+// ---------------------------------------------------------------------------
+//
+void CHDMICableStateConnected::CentRepGetKeyValueFailed(
+        TUid    aRepositoryId,
+        TUint32 aId,
+        TInt    aError )
+    {
+    FUNC_LOG;
+    // Make use of aError argument top get rid of compiler warning.
+    TInt error( aError );
+    if ( ( KCRUidTvoutSettings == aRepositoryId ) && ( KErrNone != error ) )
+        {
+        if ( KSettingsTvoutVerticalOverscan == aId  )
+            {
+            INFO_1(" Getting KSettingsTvoutVerticalOverscan from CR failed, aError %d", error );                                    
+            }
+        else
+            {
+            INFO_1("Unexpected CR key ID, aId 0x%x", aId );            
+            }       
+        }
+    else
+        {
+        INFO_1("Unexpected Central Repository ID, aRepositoryId 0x%x", aRepositoryId);
+        }    
+    }
 
 // ---------------------------------------------------------------------------
 // From MFSMState.
@@ -88,6 +156,11 @@
     {
     FUNC_LOG;
     TInt retVal( KErrNone );
+	
+	// Get the current overscan value
+	iEDIDHandler.UpdateOverscanValues();
+	iEDIDHandler.GetCurrentOverscanValue( iHOverscanValue, iVOverscanValue );
+	
     iCopyProtectListenFailCounter.iCount = 0;
     iTVOutConfigForCopyProtect->ResetLatestRecordedCopyProtectionStatus();
     retVal = iEDIDHandler.FetchEDIDData();
@@ -330,6 +403,9 @@
                         }
                     else
                         {
+						// Update the current overscan value
+						iEDIDHandler.GetCurrentOverscanValue( iHOverscanValue, iVOverscanValue );
+						
                         TFSMEventId event = iTVOutConfigForHDMI.ListenHDMICableStatusIfNoMissedEvents();
                         if ( EIfTVOutConfigEventCableDisconnected == event )
                             {
@@ -451,6 +527,7 @@
             else
                 {
                 iSubState = ESubStateConnected;
+
                 TRAPD( err, iHDMICableStatusFSM.SettingsChangedL() );
                 if ( KErrNone != err )
                     {
@@ -458,6 +535,7 @@
                     }
                 ListenCopyProtectionStatusChanges();
                 iTVOutConfigForSettingChanges->ListenSettingsChanges();
+				iCRWatchForVOverScan->Watch();
                 }
             }
         else if ( EIfTVOutConfigEventEnableFailed == aEvent )
@@ -500,12 +578,14 @@
             INFO( "Event: EIfTVOutConfigEventDisabled" );
             iSubState = ESubStateIdlingDisconnectAccessory;
             iAccessoryControlIf.DisconnectAccessory();                    
+			ClearAvailableTvOutConfig();
             }
         else if ( EIfTVOutConfigEventDisableFailed == aEvent )
             {
             INFO( "Event: EIfTVOutConfigEventDisableFailed" );        
             iSubState = ESubStateIdlingDisconnectAccessory;
             iAccessoryControlIf.DisconnectAccessory();                    
+			ClearAvailableTvOutConfig();
             }
         else
             {
@@ -632,6 +712,7 @@
                 iSubState = ESubStateConnected;
                 ListenCopyProtectionStatusChanges();
                 iTVOutConfigForSettingChanges->ListenSettingsChanges();
+				iCRWatchForVOverScan->Watch();				
                 }
             }
         else if ( EPDEIfAccessoryControlEventConnectFailed == aEvent )
@@ -780,6 +861,7 @@
                 iTVOutConfigForCopyProtect->Cancel();
                 // Stop listen setting changes
                 iTVOutConfigForSettingChanges->Cancel();
+				iCRWatchForVOverScan->Cancel();
                 iSubState = ESubStateIdlingDisable;
                 iTVOutConfigForHDMI.Disable();            
                 }
@@ -792,6 +874,7 @@
             iTVOutConfigForCopyProtect->Cancel();
             // Stop listen setting changes
             iTVOutConfigForSettingChanges->Cancel();
+			iCRWatchForVOverScan->Cancel();
             // Disable tv out
             iTVOutConfigForHDMI.Disable();            
             }
@@ -808,6 +891,7 @@
                 iTVOutConfigForCopyProtect->Cancel();
                 // Stop listen setting changes
                 iTVOutConfigForSettingChanges->Cancel();
+				iCRWatchForVOverScan->Cancel();
                 iTVOutConfigForHDMI.Disable();                       
                 }
             else
@@ -821,6 +905,7 @@
                     iTVOutConfigForCopyProtect->Cancel();
                     // Stop listen setting changes
                     iTVOutConfigForSettingChanges->Cancel();
+					iCRWatchForVOverScan->Cancel();
                     iSubState = ESubStateIdlingDisable;
                     iTVOutConfigForHDMI.Disable();            
                     }
@@ -851,6 +936,7 @@
                 iTVOutConfigForHDMI.Cancel();
                 // Stop listening Copy Protection status
                 iTVOutConfigForCopyProtect->Cancel();
+				iCRWatchForVOverScan->Cancel();
                 iSubState = ESubStateRejectingDisable;
                 iTVOutConfigForHDMI.Disable();            
                 }
@@ -862,6 +948,7 @@
             iTVOutConfigForHDMI.Cancel();
             // Stop listening Copy Protection status
             iTVOutConfigForCopyProtect->Cancel();
+			iCRWatchForVOverScan->Cancel();
             if ( iTVOutConfigForHDMI.GetTvOutConfig()->Enabled() )
                 {
                 iSubState = ESubStateResettingDisable;
@@ -873,10 +960,17 @@
                 iTVOutConfigForHDMI.Enable();                
                 }
             }
-        else if ( EIfTVOutConfigEventSettingsChangesListenStarted )
+        else if ( EIfTVOutConfigEventSettingsChangesListenStarted == aEvent )
             {
             INFO( "Event: EIfTVOutConfigEventSettingsChangesListenStarted" );
             // Everything is OK. Stay in the same state.
+			// Should not miss the cenrep value change
+			TInt newOverScanValue = 0;
+			iCRWatchForVOverScan->GetCurrentValue(newOverScanValue);
+			if( iVOverscanValue != newOverScanValue )
+				{
+				Input( EPDEIfCentralRepositoryWatch, EPDEIfCentralRepositoryWatchEventKeyChanged );
+				}
             }
         else if ( EIfTVOutConfigEventSettingsChangesListenFailed == aEvent )
             {
@@ -887,6 +981,7 @@
             iTVOutConfigForHDMI.Cancel();
             // Stop listening Copy Protection status
             iTVOutConfigForCopyProtect->Cancel();
+			iCRWatchForVOverScan->Cancel();
             iTVOutConfigForHDMI.Disable();            
             }
         else
@@ -895,6 +990,53 @@
             }
         break;
         }
+    case EPDEIfCentralRepositoryWatch:
+        {       
+        INFO( "Interface: EPDEIfCentralRepositoryWatch" );
+        if ( EPDEIfCentralRepositoryWatchEventKeyChanged == aEvent )
+            {
+            INFO( "Event: EPDEIfCentralRepositoryWatchEventKeyChanged" );
+			
+			// Get the available config
+			THdmiDviTimings curConfig;
+			
+			iTVOutConfigForHDMI.GetTvOutConfig()->GetConfig( curConfig );
+
+			if( (TTvSettings::EHDMI == curConfig.iConnector) && (!curConfig.iUnderscanEnabled) )
+				{									
+				
+				TInt retVal = iEDIDHandler.SetVideoParameters();
+				if ( KErrNone != retVal )
+					{
+					INFO( "Going to state <Rejected> since video parameter setting failed!" );		  
+					iTVOutConfigForSettingChanges->Cancel();
+					iCRWatchForVOverScan->Cancel();
+					iSubState = ESubStateIdlingDisable;
+					iTVOutConfigForHDMI.Disable();			  
+					}
+				else
+					{
+					// Update the current overscan value
+					iEDIDHandler.GetCurrentOverscanValue( iHOverscanValue, iVOverscanValue );
+					
+					TFSMEventId event = iTVOutConfigForHDMI.ListenHDMICableStatusIfNoMissedEvents();
+					if ( EIfTVOutConfigEventCableDisconnected == event )
+						{
+						INFO( "Retreating back to <Idle> since cable was disconnected while not listening!" );		  
+						iTVOutConfigForSettingChanges->Cancel();
+						iCRWatchForVOverScan->Cancel();
+						iSubState = ESubStateIdlingDisable;
+						iTVOutConfigForHDMI.Disable();			  
+						}
+					}				
+				}			
+            }
+        else
+            {
+            INFO_1( "Unknown Event Id: %i", aEvent );        
+            }
+        break;
+        }       
     default:
         {
         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
@@ -924,16 +1066,43 @@
             if ( EIfTVOutConfigEventCableDisconnected == event )
                 {
                 INFO( "Retreating back to <Idle> since cable was disconnected while WF setting changes!" );        
+				
+                // Stop listening Copy Protection status
+                iTVOutConfigForCopyProtect->Cancel();
+                // Stop listen setting changes
                 iTVOutConfigForSettingChanges->Cancel();
-                iHDMICableStatusFSM.Transit( EHDMICableStateIdle );         
+				iCRWatchForVOverScan->Cancel();
+
+				if( iTVOutConfigForHDMI.GetTvOutConfig()->Enabled() )
+					{
+					iSubState = ESubStateIdlingDisable;
+					iTVOutConfigForHDMI.Disable();			  
+					}
+				else
+					{
+					iHDMICableStatusFSM.Transit( EHDMICableStateIdle ); 		
+					}
                 }            
              }
         else if ( EIfTVOutConfigEventCableDisconnected == aEvent )
             {
             INFO( "Event: EIfTVOutConfigEventCableDisconnected" );
             INFO( "Retreating back to <Idle> since cable was disconnected while WF setting changes!" );
-            iTVOutConfigForSettingChanges->Cancel();
-            iHDMICableStatusFSM.Transit( EHDMICableStateIdle );         
+			// Stop listening Copy Protection status
+			iTVOutConfigForCopyProtect->Cancel();
+			// Stop listen setting changes
+			iTVOutConfigForSettingChanges->Cancel();
+			iCRWatchForVOverScan->Cancel();
+			
+			if( iTVOutConfigForHDMI.GetTvOutConfig()->Enabled() )
+				{
+				iSubState = ESubStateIdlingDisable;
+				iTVOutConfigForHDMI.Disable();			  
+				}
+			else
+				{
+				iHDMICableStatusFSM.Transit( EHDMICableStateIdle ); 		
+				}
             }
         else if ( EIfTVOutConfigEventSettingsChanged == aEvent )
             {
@@ -945,7 +1114,20 @@
             {
             INFO( "Event: EIfTVOutConfigEventSettingsChangesListenFailed" );
             INFO( "Going to state <Rejected> since setting changes listening failed!" );        
-            iHDMICableStatusFSM.Transit( EHDMICableStateRejected );         
+			// Stop listening Copy Protection status
+			iTVOutConfigForCopyProtect->Cancel();
+			// Stop listen setting changes
+			iCRWatchForVOverScan->Cancel();
+			
+			if( iTVOutConfigForHDMI.GetTvOutConfig()->Enabled() )
+				{
+				iSubState = ESubStateIdlingDisable;
+				iTVOutConfigForHDMI.Disable();			  
+				}
+			else
+				{
+				iHDMICableStatusFSM.Transit( EHDMICableStateRejected ); 		
+				}
             }
         else
             {
@@ -962,14 +1144,38 @@
     }
 
 // ---------------------------------------------------------------------------
+// ClearAvailableConfig
+// ---------------------------------------------------------------------------
+//
+void CHDMICableStateConnected::ClearAvailableTvOutConfig()
+    {
+    FUNC_LOG;
+    
+    if( iTVOutConfigForHDMI.GetTvOutConfig() )
+        {
+        RArray<THdmiDviTimings> HdmiSettingsArray;        
+    	RArray<TTvSettings> TvSettingsArray;       
+    
+        TInt err = iTVOutConfigForHDMI.GetTvOutConfig()->SetAvailableTvConfigList( TvSettingsArray, HdmiSettingsArray );
+        
+        HdmiSettingsArray.Close();
+    	TvSettingsArray.Close();
+        }              
+    }
+
+
+// ---------------------------------------------------------------------------
 // ConstructL
 // ---------------------------------------------------------------------------
 //
 void CHDMICableStateConnected::ConstructL()
     {
     FUNC_LOG;
+    // Create Central Repository Watchers
+    iCRWatchForVOverScan = CCentralRepositoryWatch::NewL(*this, KCRUidTvoutSettings, KSettingsTvoutVerticalOverscan );
+	
     iTVOutConfigForCopyProtect = CTVOutConfigForHDMI::NewL( iHDMICableStatusFSM );
-    iTVOutConfigForSettingChanges = CTVOutConfigForHDMI::NewL( iHDMICableStatusFSM );
+    iTVOutConfigForSettingChanges = CTVOutConfigForHDMI::NewL( iHDMICableStatusFSM );	
     }