accessoryservices/pluggeddisplay/pluggeddisplayengine/src/hdmicablestateconnected.cpp
changeset 0 4e1aa6a622a0
child 27 4a5c47a50617
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Implementation of "Connected" state of HDMI Cable Status FSM.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <e32def.h>
       
    21 #include <e32cmn.h>
       
    22 
       
    23 
       
    24 #include "pdeconstants.h"
       
    25 #include "accessorycontrolif.h"
       
    26 #include "hdmicablestatusfsm.h"
       
    27 #include "hdmicablestateconnected.h"
       
    28 #include "tvoutconfigforhdmi.h"
       
    29 #include "edidhandler.h"
       
    30 #include "trace.h"
       
    31 
       
    32 
       
    33 
       
    34 
       
    35 // ======== LOCAL FUNCTIONS ========
       
    36 
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 //Symbian two-phased constructor
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CHDMICableStateConnected* CHDMICableStateConnected::NewL( 
       
    46         CTVOutConfigForHDMI& aTVOutConfigForCableConnect,
       
    47         CEDIDHandler& aEDIDHandler,
       
    48         CAccessoryControlIf& aAccessoryControlIf,
       
    49         CHDMICableStatusFSM&  aHDMICableStatusFSM )
       
    50     {
       
    51     FUNC_LOG;
       
    52     CHDMICableStateConnected* self = new ( ELeave ) CHDMICableStateConnected(            
       
    53             aTVOutConfigForCableConnect,
       
    54             aEDIDHandler, aAccessoryControlIf,
       
    55             aHDMICableStatusFSM );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // Destructor
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CHDMICableStateConnected::~CHDMICableStateConnected()
       
    68     {
       
    69     FUNC_LOG;
       
    70     if ( iTVOutConfigForCopyProtect )
       
    71         {
       
    72         iTVOutConfigForCopyProtect->Cancel();        
       
    73         delete iTVOutConfigForCopyProtect;
       
    74         }
       
    75     if ( iTVOutConfigForSettingChanges )
       
    76         {
       
    77         iTVOutConfigForSettingChanges->Cancel();
       
    78         delete iTVOutConfigForSettingChanges;
       
    79         }
       
    80     }
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // From MFSMState.
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 void CHDMICableStateConnected::Enter( )
       
    88     {
       
    89     FUNC_LOG;
       
    90     TInt retVal( KErrNone );
       
    91     iCopyProtectListenFailCounter.iCount = 0;
       
    92     iTVOutConfigForCopyProtect->ResetLatestRecordedCopyProtectionStatus();
       
    93     retVal = iEDIDHandler.FetchEDIDData();
       
    94     if ( KErrNone != retVal )
       
    95         {
       
    96         INFO( "Going to state <Rejected> since iEDIDHandler.FetchEDIDData() failed!" );        
       
    97         iHDMICableStatusFSM.Transit( EHDMICableStateRejected );         
       
    98         }
       
    99     else
       
   100         {
       
   101         iSubState = ESubStateFechEdidData;
       
   102         }
       
   103     }
       
   104 
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // From MFSMState.
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CHDMICableStateConnected::Input(
       
   111         TFSMInterfaceId aInterfaceId ,
       
   112         TFSMEventId aEvent )
       
   113     {
       
   114     FUNC_LOG;
       
   115     switch ( iSubState )
       
   116     {
       
   117     case ESubStateFechEdidData:
       
   118         {
       
   119         SubStateFetchEdidDataInput( aInterfaceId, aEvent );
       
   120         break;
       
   121         }
       
   122     case ESubStateStartListenSettingsChanges:
       
   123         {
       
   124         CHDMICableStateConnected::SubStateStartListenConfigChangesInput( aInterfaceId, aEvent );
       
   125         break;
       
   126         }
       
   127     case ESubStateEnable:
       
   128         {
       
   129         SubStateEnableInput( aInterfaceId, aEvent );
       
   130         break;
       
   131         }
       
   132     case ESubStateResettingEnable:
       
   133         {
       
   134         SubStateResettingEnableInput( aInterfaceId, aEvent );
       
   135         break;
       
   136         }
       
   137     case ESubStateIdlingDisable:
       
   138         {
       
   139         SubStateIdlingDisableInput( aInterfaceId, aEvent );
       
   140         break;
       
   141         }
       
   142     case ESubStateResettingDisable:
       
   143         {
       
   144         SubStateResettingDisableInput( aInterfaceId, aEvent );
       
   145         break;
       
   146         }
       
   147     case ESubStateRejectingDisable:
       
   148         {
       
   149         SubStateRejectingDisableInput( aInterfaceId, aEvent );
       
   150         break;
       
   151         }
       
   152     case ESubStateConnectAccessory:
       
   153         {
       
   154         SubStateConnectAccessoryInput( aInterfaceId, aEvent );
       
   155         break;
       
   156         }
       
   157     case ESubStateIdlingDisconnectAccessory:
       
   158         {
       
   159         SubStateIdlingDisconnectAccessoryInput( aInterfaceId, aEvent );
       
   160         break;
       
   161         }
       
   162     case ESubStateRejectingDisconnectAccessory:
       
   163         {
       
   164         SubStateRejectingDisconnectAccessoryInput( aInterfaceId, aEvent );
       
   165         break;
       
   166         }
       
   167     case ESubStateConnected:
       
   168         {
       
   169         SubStateConnectedInput( aInterfaceId, aEvent );
       
   170         break;
       
   171         }
       
   172     case ESubStateWaitForSettingsChanged:
       
   173         {
       
   174         SubStateWaitForSettingsChangedInput( aInterfaceId, aEvent );
       
   175         break;
       
   176         }
       
   177     default:
       
   178         {
       
   179         INFO_1( "Unexpected Event Id: %i", aEvent );        
       
   180         INFO_1( "From interface Id: %i", aInterfaceId );        
       
   181         break;
       
   182         }
       
   183     }
       
   184     }
       
   185 
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // From MFSMState.
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 TFSMState CHDMICableStateConnected::Id()
       
   192     {
       
   193     FUNC_LOG;
       
   194     TFSMState tempStateId( EHDMICableStateConnected );
       
   195     INFO_1( "State's id: %i", tempStateId );
       
   196     return tempStateId;
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // From MFSMState.
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 TPtrC CHDMICableStateConnected::Name()
       
   204     {
       
   205     FUNC_LOG;
       
   206     TPtrC temp( KHDMICableStateConnected );
       
   207     INFO_1( "State's name: %s", temp.Ptr() );
       
   208     return temp;
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // From MFSMState.
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 TFSMState CHDMICableStateConnected::SubId()
       
   216     {
       
   217     FUNC_LOG;
       
   218     TFSMState tempSubstateId( iSubState );
       
   219     INFO_1( "Substate's id: %i", tempSubstateId );
       
   220     return tempSubstateId;
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // ListenCopyProtectionStatusChanges.
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CHDMICableStateConnected::ListenCopyProtectionStatusChanges()
       
   228     {
       
   229     FUNC_LOG;
       
   230     TCopyProtctListenRetValues retStruct = iTVOutConfigForCopyProtect->ListenCopyProtectionIfNoMissedEvents();
       
   231     if ( EIfTVOutConfigEventSetCopyProtectStatusChanged == retStruct.iFSMEventId )
       
   232         {
       
   233         // Copy Protection status changed while not listening
       
   234         Input( EPDEIfTVOutConfig, EIfTVOutConfigEventSetCopyProtectStatusChanged );                       
       
   235         }
       
   236     else if ( EIfTVOutConfigEventCopyProtectionListenFailed == retStruct.iFSMEventId )
       
   237         {
       
   238         iHDMICableStatusFSM.CopyProtectionListenFailed( retStruct.iError );
       
   239         }
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // SubStateFetchEdidDataInput
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 void CHDMICableStateConnected::SubStateFetchEdidDataInput(
       
   247         TFSMInterfaceId aInterfaceId ,
       
   248         TFSMEventId aEvent )
       
   249     {
       
   250     FUNC_LOG;
       
   251     switch ( aInterfaceId )
       
   252     {
       
   253     case EPDEIfEDIDHandler:
       
   254         {
       
   255         INFO( "Interface: EPDEIfEDIDHandler" );
       
   256         if ( EPDEIfEDIDHandlerEventEdidDataFetched == aEvent )
       
   257             {
       
   258             INFO( "Event: EPDEIfEDIDHandlerEventEDdidDataFetched" );        
       
   259             if ( !iTVOutConfigForHDMI.GetTvOutConfig()->HdmiCableConnected() )
       
   260                 {
       
   261                 INFO( "Retreating back to <Idle> since cable was disconnected while not listening!" );        
       
   262                 iHDMICableStatusFSM.Transit( EHDMICableStateIdle );         
       
   263                 }
       
   264             else
       
   265                 {
       
   266                 TFSMEventId event = iTVOutConfigForHDMI.ListenHDMICableStatusIfNoMissedEvents();
       
   267                 if ( EIfTVOutConfigEventCableDisconnected == event )
       
   268                     {
       
   269                     INFO( "Retreating back to <Idle> since cable was disconnected while not listening!" );        
       
   270                     iHDMICableStatusFSM.Transit( EHDMICableStateIdle );         
       
   271                     }
       
   272                 else
       
   273                     {
       
   274                     iTVOutConfigForSettingChanges->ListenSettingsChanges();
       
   275                     iSubState = ESubStateStartListenSettingsChanges;
       
   276                     }
       
   277                 }
       
   278             }
       
   279         else if ( EPDEIfEDIDHandlerEventEdidDataFetchFailed == aEvent )
       
   280             {
       
   281             INFO( "Event: EPDEIfEDIDHandlerEventEDdidDataFetchFailed" );        
       
   282             INFO( "Going to state <Rejected>" );        
       
   283             iHDMICableStatusFSM.Transit( EHDMICableStateRejected );                     
       
   284              }
       
   285         else
       
   286             {
       
   287             INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   288             }
       
   289         break;
       
   290         }
       
   291     default:
       
   292         {
       
   293         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   294         break;
       
   295         }
       
   296     }
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // SubStateStartListenConfigChangesInput
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 void CHDMICableStateConnected::SubStateStartListenConfigChangesInput(
       
   304         TFSMInterfaceId aInterfaceId ,
       
   305         TFSMEventId aEvent )
       
   306     {
       
   307     FUNC_LOG;
       
   308     switch ( aInterfaceId )
       
   309     {
       
   310         case EPDEIfTVOutConfig:
       
   311             {       
       
   312             INFO( "Interface: TPDEIfTVOutConfig" );        
       
   313             if ( EIfTVOutConfigEventSettingsChangesListenStarted == aEvent )
       
   314                 {
       
   315                 INFO( "Event: EIfTVOutConfigEventSettingsChangesListenStarted" );        
       
   316                 if ( !iTVOutConfigForHDMI.GetTvOutConfig()->HdmiCableConnected() )
       
   317                     {
       
   318                     INFO( "Retreating back to <Idle> since cable was disconnected while not listening!" );        
       
   319                     iTVOutConfigForSettingChanges->Cancel();
       
   320                     iHDMICableStatusFSM.Transit( EHDMICableStateIdle );         
       
   321                     }
       
   322                 else
       
   323                     {
       
   324                     TInt retVal = iEDIDHandler.SetVideoParameters();
       
   325                     if ( KErrNone != retVal )
       
   326                         {
       
   327                         INFO( "Going to state <Rejected> since video parameter setting failed!" );        
       
   328                         iTVOutConfigForSettingChanges->Cancel();
       
   329                         iHDMICableStatusFSM.Transit( EHDMICableStateRejected );         
       
   330                         }
       
   331                     else
       
   332                         {
       
   333                         TFSMEventId event = iTVOutConfigForHDMI.ListenHDMICableStatusIfNoMissedEvents();
       
   334                         if ( EIfTVOutConfigEventCableDisconnected == event )
       
   335                             {
       
   336                             INFO( "Retreating back to <Idle> since cable was disconnected while not listening!" );        
       
   337                             iTVOutConfigForSettingChanges->Cancel();
       
   338                             iHDMICableStatusFSM.Transit( EHDMICableStateIdle );         
       
   339                             }
       
   340                         else
       
   341                             {
       
   342                             iSubState = ESubStateWaitForSettingsChanged;
       
   343                             }
       
   344                         }         
       
   345                     }
       
   346                 }
       
   347             else if ( EIfTVOutConfigEventSettingsChangesListenFailed == aEvent )
       
   348                 {
       
   349                 INFO( "Event: EIfTVOutConfigEventSettingsChangesListenFailed" );        
       
   350                 INFO( "Going to state <Rejected> since TV Out Settings Change listening failed!" );        
       
   351                 iHDMICableStatusFSM.Transit( EHDMICableStateRejected );         
       
   352                 }
       
   353             else
       
   354                 {
       
   355                 INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   356                 }
       
   357             break;
       
   358             }
       
   359     default:
       
   360         {
       
   361         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   362         break;
       
   363         }
       
   364     }
       
   365     }
       
   366 
       
   367 // ---------------------------------------------------------------------------
       
   368 // SubStateEnableInput
       
   369 // ---------------------------------------------------------------------------
       
   370 //
       
   371 void CHDMICableStateConnected::SubStateEnableInput(
       
   372         TFSMInterfaceId aInterfaceId ,
       
   373         TFSMEventId aEvent )
       
   374     {
       
   375     FUNC_LOG;
       
   376     switch ( aInterfaceId )
       
   377     {
       
   378     case EPDEIfTVOutConfig:
       
   379         {       
       
   380         INFO( "Interface: TPDEIfTVOutConfig" );        
       
   381         if ( EIfTVOutConfigEventEnabled == aEvent )
       
   382             {
       
   383             INFO( "Event: EIfTVOutConfigEventEnabled" );        
       
   384             if ( !iTVOutConfigForHDMI.GetTvOutConfig()->HdmiCableConnected() )
       
   385                 {
       
   386                 INFO( "Disabling since cable was disconnected while not listening!" );        
       
   387                 iSubState = ESubStateIdlingDisable;
       
   388                 iTVOutConfigForHDMI.Disable();            
       
   389                 }
       
   390             else
       
   391                 {
       
   392                 TInt retVal( KErrNone );
       
   393                 TBool copyProtectStatus = iTVOutConfigForCopyProtect->GetTvOutConfig()->CopyProtectionStatus();
       
   394                 TRAP( retVal, iAccessoryControlIf.ConnectAccessoryL( copyProtectStatus ) );
       
   395                 if ( KErrNone != retVal )
       
   396                     {
       
   397                     INFO_1( "Rejecting since CAccessoryControlIf::ConnectAccessoryL() failed, error code %i", retVal );        
       
   398                     iSubState = ESubStateRejectingDisable;
       
   399                      iTVOutConfigForHDMI.Disable();            
       
   400                     }
       
   401                 else
       
   402                     {
       
   403                     iSubState = ESubStateConnectAccessory;
       
   404                     }
       
   405                 }
       
   406             }
       
   407         else if ( EIfTVOutConfigEventEnableFailed == aEvent )
       
   408             {
       
   409             INFO( "Event: EIfTVOutConfigEventEnableFailed" );        
       
   410             INFO( "Going to state <Rejected> since TV Out Enabling failed!" );        
       
   411             iHDMICableStatusFSM.Transit( EHDMICableStateRejected );         
       
   412             }
       
   413         else
       
   414             {
       
   415             INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   416             }
       
   417         break;
       
   418         }
       
   419     default:
       
   420         {
       
   421         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   422         break;
       
   423         }
       
   424     }    
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------------------------
       
   428 // SubStateResettingEnableInput
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 void CHDMICableStateConnected::SubStateResettingEnableInput(
       
   432         TFSMInterfaceId aInterfaceId ,
       
   433         TFSMEventId aEvent )
       
   434     {
       
   435     FUNC_LOG;
       
   436     switch ( aInterfaceId )
       
   437     {
       
   438     case EPDEIfTVOutConfig:
       
   439         {       
       
   440         INFO( "Interface: TPDEIfTVOutConfig" );        
       
   441         if ( EIfTVOutConfigEventEnabled == aEvent )
       
   442             {
       
   443             INFO( "Event: EIfTVOutConfigEventEnabled" );        
       
   444             TFSMEventId event = iTVOutConfigForHDMI.ListenHDMICableStatusIfNoMissedEvents();
       
   445             if ( EIfTVOutConfigEventCableDisconnected == event )
       
   446                 {
       
   447                 INFO( "Disabling since cable was disconnected while not listening!" );        
       
   448                 iSubState = ESubStateIdlingDisable;
       
   449                 iTVOutConfigForHDMI.Disable();            
       
   450                 }
       
   451             else
       
   452                 {
       
   453                 iSubState = ESubStateConnected;
       
   454                 TRAPD( err, iHDMICableStatusFSM.SettingsChangedL() );
       
   455                 if ( KErrNone != err )
       
   456                     {
       
   457                     INFO_1( "iHDMICableStatusFSM.SettingsChangedL() failed, error code %i", err ); 
       
   458                     }
       
   459                 ListenCopyProtectionStatusChanges();
       
   460                 iTVOutConfigForSettingChanges->ListenSettingsChanges();
       
   461                 }
       
   462             }
       
   463         else if ( EIfTVOutConfigEventEnableFailed == aEvent )
       
   464             {
       
   465             INFO( "Event: EIfTVOutConfigEventEnableFailed" );        
       
   466             INFO( "Going to state <Rejected> since TV Out Enabling failed!" );        
       
   467             iSubState = ESubStateRejectingDisconnectAccessory;
       
   468             iAccessoryControlIf.DisconnectAccessory();
       
   469             }
       
   470         else
       
   471             {
       
   472             INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   473             }
       
   474         break;
       
   475         }
       
   476     default:
       
   477         {
       
   478         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   479         break;
       
   480         }
       
   481     }    
       
   482     }
       
   483 
       
   484 // ---------------------------------------------------------------------------
       
   485 // SubStateIdlingDisableInput
       
   486 // ---------------------------------------------------------------------------
       
   487 //
       
   488 void CHDMICableStateConnected::SubStateIdlingDisableInput(
       
   489         TFSMInterfaceId aInterfaceId ,
       
   490         TFSMEventId aEvent )
       
   491     {
       
   492     FUNC_LOG;
       
   493     switch ( aInterfaceId )
       
   494     {
       
   495     case EPDEIfTVOutConfig:
       
   496         {       
       
   497         INFO( "Interface: TPDEIfTVOutConfig" );        
       
   498         if ( EIfTVOutConfigEventDisabled == aEvent )
       
   499             {
       
   500             INFO( "Event: EIfTVOutConfigEventDisabled" );
       
   501             iSubState = ESubStateIdlingDisconnectAccessory;
       
   502             iAccessoryControlIf.DisconnectAccessory();                    
       
   503             }
       
   504         else if ( EIfTVOutConfigEventDisableFailed == aEvent )
       
   505             {
       
   506             INFO( "Event: EIfTVOutConfigEventDisableFailed" );        
       
   507             iSubState = ESubStateIdlingDisconnectAccessory;
       
   508             iAccessoryControlIf.DisconnectAccessory();                    
       
   509             }
       
   510         else
       
   511             {
       
   512             INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   513             }
       
   514         break;
       
   515         }
       
   516     default:
       
   517         {
       
   518         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   519         break;
       
   520         }
       
   521     }    
       
   522     }
       
   523 
       
   524 // ---------------------------------------------------------------------------
       
   525 // SubStateResettingDisableInput
       
   526 // ---------------------------------------------------------------------------
       
   527 //
       
   528 void CHDMICableStateConnected::SubStateResettingDisableInput(
       
   529         TFSMInterfaceId aInterfaceId ,
       
   530         TFSMEventId aEvent )
       
   531     {
       
   532     FUNC_LOG;
       
   533     switch ( aInterfaceId )
       
   534     {
       
   535     case EPDEIfTVOutConfig:
       
   536         {       
       
   537         INFO( "Interface: TPDEIfTVOutConfig" );        
       
   538         if ( EIfTVOutConfigEventDisabled == aEvent )
       
   539             {
       
   540             INFO( "Event: EIfTVOutConfigEventDisabled" );
       
   541             iSubState = ESubStateResettingEnable;
       
   542             iTVOutConfigForHDMI.Enable();                
       
   543             }
       
   544         else if ( EIfTVOutConfigEventDisableFailed == aEvent )
       
   545             {
       
   546             INFO( "Event: EIfTVOutConfigEventDisableFailed" );        
       
   547             iSubState = ESubStateRejectingDisconnectAccessory;
       
   548             iAccessoryControlIf.DisconnectAccessory();                    
       
   549             }
       
   550         else
       
   551             {
       
   552             INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   553             }
       
   554         break;
       
   555         }
       
   556     default:
       
   557         {
       
   558         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   559         break;
       
   560         }
       
   561     }    
       
   562     }
       
   563 
       
   564 
       
   565 // ---------------------------------------------------------------------------
       
   566 // SubStateRejectingDisableInput
       
   567 // ---------------------------------------------------------------------------
       
   568 //
       
   569 void CHDMICableStateConnected::SubStateRejectingDisableInput(
       
   570         TFSMInterfaceId aInterfaceId ,
       
   571         TFSMEventId aEvent )
       
   572     {
       
   573     FUNC_LOG;
       
   574     switch ( aInterfaceId )
       
   575     {
       
   576     case EPDEIfTVOutConfig:
       
   577         {       
       
   578         INFO( "Interface: TPDEIfTVOutConfig" );        
       
   579         if ( EIfTVOutConfigEventDisabled == aEvent )
       
   580             {
       
   581             INFO( "Event: EIfTVOutConfigEventDisabled" );
       
   582             iSubState = ESubStateRejectingDisconnectAccessory;
       
   583             iAccessoryControlIf.DisconnectAccessory();                    
       
   584             }
       
   585         else if ( EIfTVOutConfigEventDisableFailed == aEvent )
       
   586             {
       
   587             INFO( "Event: EIfTVOutConfigEventDisableFailed" );        
       
   588             iSubState = ESubStateRejectingDisconnectAccessory;
       
   589             iAccessoryControlIf.DisconnectAccessory();                    
       
   590             }
       
   591         else
       
   592             {
       
   593             INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   594             }
       
   595         break;
       
   596         }
       
   597     default:
       
   598         {
       
   599         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   600         break;
       
   601         }
       
   602     }    
       
   603     }
       
   604 
       
   605 
       
   606 // ---------------------------------------------------------------------------
       
   607 // SubStateConnectAccessoryInput
       
   608 // ---------------------------------------------------------------------------
       
   609 //
       
   610 void CHDMICableStateConnected::SubStateConnectAccessoryInput(
       
   611         TFSMInterfaceId aInterfaceId ,
       
   612         TFSMEventId aEvent )
       
   613     {
       
   614     FUNC_LOG;
       
   615     switch ( aInterfaceId )
       
   616     {
       
   617     case EPDEIfAccessoryControl:
       
   618         {
       
   619         INFO( "Interface: EPDEIfAccessoryControl" );
       
   620         if ( EPDEIfAccessoryControlEventConnected == aEvent )
       
   621             {
       
   622             INFO( "Event: EPDEIfAccessoryControlEventConnected" );
       
   623             TFSMEventId event = iTVOutConfigForHDMI.ListenHDMICableStatusIfNoMissedEvents();
       
   624             if ( EIfTVOutConfigEventCableDisconnected == event )
       
   625                 {
       
   626                 INFO( "Event: EIfTVOutConfigEventCableDisconnected occurred while connecting" );
       
   627                 iSubState = ESubStateIdlingDisable;
       
   628                 iTVOutConfigForHDMI.Disable();            
       
   629                 }
       
   630             else
       
   631                 {
       
   632                 iSubState = ESubStateConnected;
       
   633                 ListenCopyProtectionStatusChanges();
       
   634                 iTVOutConfigForSettingChanges->ListenSettingsChanges();
       
   635                 }
       
   636             }
       
   637         else if ( EPDEIfAccessoryControlEventConnectFailed == aEvent )
       
   638             {
       
   639             INFO( "Event: EPDEIfAccessoryControlEventConnectFailed" ); 
       
   640             iSubState = ESubStateRejectingDisable;
       
   641             iTVOutConfigForHDMI.Disable();        
       
   642             }
       
   643         else
       
   644             {
       
   645             INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   646             }
       
   647         break;
       
   648         }
       
   649     default:
       
   650         {
       
   651         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   652         break;
       
   653         }
       
   654     }    
       
   655     }
       
   656 
       
   657 // ---------------------------------------------------------------------------
       
   658 // SubStateIdlingDisconnectAccessoryInput
       
   659 // ---------------------------------------------------------------------------
       
   660 //
       
   661 void CHDMICableStateConnected::SubStateIdlingDisconnectAccessoryInput(
       
   662         TFSMInterfaceId aInterfaceId ,
       
   663         TFSMEventId aEvent )
       
   664     {
       
   665     FUNC_LOG;
       
   666     switch ( aInterfaceId )
       
   667     {
       
   668     case EPDEIfAccessoryControl:
       
   669         {
       
   670         INFO( "Interface: EPDEIfAccessoryControl" );
       
   671         if ( EPDEIfAccessoryControlEventDisconnected == aEvent )
       
   672             {
       
   673             INFO( "Event: EPDEIfAccessoryControlEventDisconnected" );        
       
   674             iHDMICableStatusFSM.Transit( EHDMICableStateIdle );                     
       
   675             }
       
   676         else if ( EPDEIfAccessoryControlEventDisconnectFailed == aEvent )
       
   677             {
       
   678             INFO( "Event: EPDEIfAccessoryControlEventDisconnectFailed" );        
       
   679             iHDMICableStatusFSM.Transit( EHDMICableStateIdle );                     
       
   680             }
       
   681         else
       
   682             {
       
   683             INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   684             }
       
   685         break;
       
   686         }
       
   687     default:
       
   688         {
       
   689         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   690         break;
       
   691         }
       
   692     }    
       
   693     }
       
   694 
       
   695 // ---------------------------------------------------------------------------
       
   696 // SubStateRejectingDisconnectAccessoryInput
       
   697 // ---------------------------------------------------------------------------
       
   698 //
       
   699 void CHDMICableStateConnected::SubStateRejectingDisconnectAccessoryInput(
       
   700         TFSMInterfaceId aInterfaceId ,
       
   701         TFSMEventId aEvent )
       
   702     {
       
   703     FUNC_LOG;
       
   704     switch ( aInterfaceId )
       
   705     {
       
   706     case EPDEIfAccessoryControl:
       
   707         {
       
   708         INFO( "Interface: EPDEIfAccessoryControl" );
       
   709         if ( EPDEIfAccessoryControlEventDisconnected == aEvent )
       
   710             {
       
   711             INFO( "Event: EPDEIfAccessoryControlEventDisconnected" );        
       
   712             iHDMICableStatusFSM.Transit( EHDMICableStateRejected );                     
       
   713             }
       
   714         else if ( EPDEIfAccessoryControlEventDisconnectFailed == aEvent )
       
   715             {
       
   716             INFO( "Event: EPDEIfAccessoryControlEventDisconnectFailed" );        
       
   717             iHDMICableStatusFSM.Transit( EHDMICableStateRejected );                     
       
   718             }
       
   719         else
       
   720             {
       
   721             INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   722             }
       
   723         break;
       
   724         }
       
   725     default:
       
   726         {
       
   727         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   728         break;
       
   729         }
       
   730     }    
       
   731     }
       
   732 
       
   733 // ---------------------------------------------------------------------------
       
   734 // SubStateConnectedInput
       
   735 // ---------------------------------------------------------------------------
       
   736 //
       
   737 void CHDMICableStateConnected::SubStateConnectedInput(
       
   738         TFSMInterfaceId aInterfaceId ,
       
   739         TFSMEventId aEvent )
       
   740     {
       
   741     FUNC_LOG;
       
   742     switch ( aInterfaceId )
       
   743     {
       
   744     case EPDEIfAsyCommandHandler:
       
   745         {
       
   746         INFO( "Interface: EPDEIfAsyCommandHandler" );        
       
   747         if ( EIfAsyCommandHandlerEventSetCopyProtectionOn == aEvent )
       
   748             {
       
   749             INFO( "Event: EIfAsyCommandHandlerEventSetCopyProtectionOn" );
       
   750             TInt retVal = iTVOutConfigForCopyProtect->GetTvOutConfig()->CopyProtection( ETrue );
       
   751             iHDMICableStatusFSM.CopyProtectionSettingDone( retVal );
       
   752             }
       
   753         else if ( EIfAsyCommandHandlerEventSetCopyProtectionOff == aEvent )
       
   754             {
       
   755             INFO( "Event: EIfAsyCommandHandlerEventSetCopyProtectionOff" );
       
   756             TInt retVal = iTVOutConfigForCopyProtect->GetTvOutConfig()->CopyProtection( EFalse );
       
   757             iHDMICableStatusFSM.CopyProtectionSettingDone( retVal );
       
   758             }
       
   759         else if ( EIfAsyCommandHandlerEventGetCopyProtectStatus == aEvent )
       
   760             {
       
   761             INFO( "Event: EIfAsyCommandHandlerEventGetCopyProtectStatus" );
       
   762             TBool copyProtectStatus = iTVOutConfigForCopyProtect->GetTvOutConfig()->CopyProtectionStatus();
       
   763             iHDMICableStatusFSM.CopyProtectionStatusGot( copyProtectStatus );
       
   764             }
       
   765         break;
       
   766         }
       
   767     case EPDEIfTVOutConfig:
       
   768         {       
       
   769         INFO( "Interface: TPDEIfTVOutConfig" );        
       
   770         if ( EIfTVOutConfigEventCableConnected == aEvent )
       
   771             {
       
   772             INFO( "Event: EIfTVOutConfigEventCableConnected" );        
       
   773             // Re-issue request for connection notification
       
   774             TFSMEventId event = iTVOutConfigForHDMI.ListenHDMICableStatusIfNoMissedEvents();
       
   775             
       
   776             if ( EIfTVOutConfigEventCableDisconnected == event )
       
   777                 {
       
   778                 INFO( "Event: EIfTVOutConfigEventCableDisconnected occurred while not listening" );
       
   779                 // Stop listening Copy Protection status
       
   780                 iTVOutConfigForCopyProtect->Cancel();
       
   781                 // Stop listen setting changes
       
   782                 iTVOutConfigForSettingChanges->Cancel();
       
   783                 iSubState = ESubStateIdlingDisable;
       
   784                 iTVOutConfigForHDMI.Disable();            
       
   785                 }
       
   786              }
       
   787         else if ( EIfTVOutConfigEventCableDisconnected == aEvent )
       
   788             {
       
   789             INFO( "Event: EIfTVOutConfigEventCableDisconnected" );
       
   790             iSubState = ESubStateIdlingDisable;
       
   791             // Stop listening Copy Protection status
       
   792             iTVOutConfigForCopyProtect->Cancel();
       
   793             // Stop listen setting changes
       
   794             iTVOutConfigForSettingChanges->Cancel();
       
   795             // Disable tv out
       
   796             iTVOutConfigForHDMI.Disable();            
       
   797             }
       
   798         else if ( EIfTVOutConfigEventCableStatusListenFailed == aEvent )
       
   799             {
       
   800             INFO( "Event: EIfTVOutConfigEventCableStatusListenFailed" );
       
   801             ++iCableStatusListenFailCounter.iCounter;
       
   802             if ( SCableStatusListenFailCounter::EMaxCounterValue <= iCableStatusListenFailCounter.iCounter )
       
   803                 {
       
   804                 INFO( "Max number of Cable Status listen failures reached. Retiring to <Rejected>" );
       
   805                 iSubState = ESubStateRejectingDisable;
       
   806                 iCableStatusListenFailCounter.iCounter = 0;
       
   807                 // Stop listening Copy Protection status
       
   808                 iTVOutConfigForCopyProtect->Cancel();
       
   809                 // Stop listen setting changes
       
   810                 iTVOutConfigForSettingChanges->Cancel();
       
   811                 iTVOutConfigForHDMI.Disable();                       
       
   812                 }
       
   813             else
       
   814                 {
       
   815                 // Try once again
       
   816                 TFSMEventId event = iTVOutConfigForHDMI.ListenHDMICableStatusIfNoMissedEvents();
       
   817                 if ( EIfTVOutConfigEventCableDisconnected == event )
       
   818                     {
       
   819                     INFO( "Event: EIfTVOutConfigEventCableDisconnected occurred while not listening" );
       
   820                     // Stop listening Copy Protection status
       
   821                     iTVOutConfigForCopyProtect->Cancel();
       
   822                     // Stop listen setting changes
       
   823                     iTVOutConfigForSettingChanges->Cancel();
       
   824                     iSubState = ESubStateIdlingDisable;
       
   825                     iTVOutConfigForHDMI.Disable();            
       
   826                     }
       
   827                 }
       
   828             }
       
   829         else if ( EIfTVOutConfigEventSetCopyProtectStatusChanged == aEvent )
       
   830             {
       
   831             INFO( "Event: EIfTVOutConfigEventSetCopyProtectStatusChanged" );        
       
   832             TBool latestStatus = iTVOutConfigForCopyProtect->GetLatestRecordedCopyProtectionStatus();
       
   833             iHDMICableStatusFSM.CopyProtectionStatusChanged( latestStatus );
       
   834             ListenCopyProtectionStatusChanges();
       
   835             }
       
   836         else if ( EIfTVOutConfigEventCopyProtectionListenFailed == aEvent )
       
   837             {
       
   838             INFO( "Event: EIfTVOutConfigEventCopyProtectionListenFailed" );
       
   839             ++iCopyProtectListenFailCounter.iCount; 
       
   840             if ( SCopyProtectListenFailCounter::ECounterMaxValue < iCopyProtectListenFailCounter.iCount )
       
   841                 {
       
   842                 iHDMICableStatusFSM.CopyProtectionListenFailed( iTVOutConfigForCopyProtect->iStatus.Int() );
       
   843                 // Try again
       
   844                 ListenCopyProtectionStatusChanges();
       
   845                 }
       
   846             else
       
   847                 {
       
   848                 INFO( "Max number of Copy Protection Status listen failures reached. Retiring to <Rejected>" );
       
   849                 iCopyProtectListenFailCounter.iCount = 0;
       
   850                 // Stop listening cable status changes while disabling.
       
   851                 iTVOutConfigForHDMI.Cancel();
       
   852                 // Stop listening Copy Protection status
       
   853                 iTVOutConfigForCopyProtect->Cancel();
       
   854                 iSubState = ESubStateRejectingDisable;
       
   855                 iTVOutConfigForHDMI.Disable();            
       
   856                 }
       
   857             }
       
   858         else if ( EIfTVOutConfigEventSettingsChanged == aEvent )
       
   859             {
       
   860             INFO( "Event: EIfTVOutConfigEventSettingsChanged" );
       
   861             // Stop listening cable connection status
       
   862             iTVOutConfigForHDMI.Cancel();
       
   863             // Stop listening Copy Protection status
       
   864             iTVOutConfigForCopyProtect->Cancel();
       
   865             if ( iTVOutConfigForHDMI.GetTvOutConfig()->Enabled() )
       
   866                 {
       
   867                 iSubState = ESubStateResettingDisable;
       
   868                 iTVOutConfigForHDMI.Disable();
       
   869                 }
       
   870             else
       
   871                 {
       
   872                 iSubState = ESubStateResettingEnable;
       
   873                 iTVOutConfigForHDMI.Enable();                
       
   874                 }
       
   875             }
       
   876         else if ( EIfTVOutConfigEventSettingsChangesListenStarted )
       
   877             {
       
   878             INFO( "Event: EIfTVOutConfigEventSettingsChangesListenStarted" );
       
   879             // Everything is OK. Stay in the same state.
       
   880             }
       
   881         else if ( EIfTVOutConfigEventSettingsChangesListenFailed == aEvent )
       
   882             {
       
   883             INFO( "Event: EIfTVOutConfigEventSettingsChangesListenFailed" );
       
   884             INFO( "Going to state <Rejected> since setting changes listening failed!" );        
       
   885             iSubState = ESubStateRejectingDisable;
       
   886             // Stop listening cable connection status
       
   887             iTVOutConfigForHDMI.Cancel();
       
   888             // Stop listening Copy Protection status
       
   889             iTVOutConfigForCopyProtect->Cancel();
       
   890             iTVOutConfigForHDMI.Disable();            
       
   891             }
       
   892         else
       
   893             {
       
   894             INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   895             }
       
   896         break;
       
   897         }
       
   898     default:
       
   899         {
       
   900         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   901         break;
       
   902         }
       
   903     }
       
   904     }
       
   905 
       
   906 // ---------------------------------------------------------------------------
       
   907 // SubStateWaitForSettingsChangedInput
       
   908 // ---------------------------------------------------------------------------
       
   909 //
       
   910 void CHDMICableStateConnected::SubStateWaitForSettingsChangedInput(
       
   911         TFSMInterfaceId aInterfaceId ,
       
   912         TFSMEventId aEvent )
       
   913     {
       
   914     FUNC_LOG;
       
   915     switch ( aInterfaceId )
       
   916     {
       
   917     case EPDEIfTVOutConfig:
       
   918         {       
       
   919         INFO( "Interface: TPDEIfTVOutConfig" );        
       
   920         if ( EIfTVOutConfigEventCableConnected == aEvent )
       
   921             {
       
   922             INFO( "Event: EIfTVOutConfigEventCableConnected" );        
       
   923             TFSMEventId event = iTVOutConfigForHDMI.ListenHDMICableStatusIfNoMissedEvents();
       
   924             if ( EIfTVOutConfigEventCableDisconnected == event )
       
   925                 {
       
   926                 INFO( "Retreating back to <Idle> since cable was disconnected while WF setting changes!" );        
       
   927                 iTVOutConfigForSettingChanges->Cancel();
       
   928                 iHDMICableStatusFSM.Transit( EHDMICableStateIdle );         
       
   929                 }            
       
   930              }
       
   931         else if ( EIfTVOutConfigEventCableDisconnected == aEvent )
       
   932             {
       
   933             INFO( "Event: EIfTVOutConfigEventCableDisconnected" );
       
   934             INFO( "Retreating back to <Idle> since cable was disconnected while WF setting changes!" );
       
   935             iTVOutConfigForSettingChanges->Cancel();
       
   936             iHDMICableStatusFSM.Transit( EHDMICableStateIdle );         
       
   937             }
       
   938         else if ( EIfTVOutConfigEventSettingsChanged == aEvent )
       
   939             {
       
   940             INFO( "Event: EIfTVOutConfigEventSettingsChanged" );
       
   941             iSubState = ESubStateEnable;
       
   942             iTVOutConfigForHDMI.Enable();
       
   943             }
       
   944         else if ( EIfTVOutConfigEventSettingsChangesListenFailed == aEvent )
       
   945             {
       
   946             INFO( "Event: EIfTVOutConfigEventSettingsChangesListenFailed" );
       
   947             INFO( "Going to state <Rejected> since setting changes listening failed!" );        
       
   948             iHDMICableStatusFSM.Transit( EHDMICableStateRejected );         
       
   949             }
       
   950         else
       
   951             {
       
   952             INFO_1( "Unknown/unexpected Event Id: %i", aEvent );        
       
   953             }
       
   954         break;
       
   955         }
       
   956     default:
       
   957         {
       
   958         INFO_1( "Event received from unknown/unexpected interface Id: %i", aInterfaceId );        
       
   959         break;
       
   960         }
       
   961     }
       
   962     }
       
   963 
       
   964 // ---------------------------------------------------------------------------
       
   965 // ConstructL
       
   966 // ---------------------------------------------------------------------------
       
   967 //
       
   968 void CHDMICableStateConnected::ConstructL()
       
   969     {
       
   970     FUNC_LOG;
       
   971     iTVOutConfigForCopyProtect = CTVOutConfigForHDMI::NewL( iHDMICableStatusFSM );
       
   972     iTVOutConfigForSettingChanges = CTVOutConfigForHDMI::NewL( iHDMICableStatusFSM );
       
   973     }
       
   974 
       
   975 
       
   976 // ---------------------------------------------------------------------------
       
   977 //  C++ constructor
       
   978 // ---------------------------------------------------------------------------
       
   979 //
       
   980 CHDMICableStateConnected::CHDMICableStateConnected(
       
   981         CTVOutConfigForHDMI& aTVOutConfigForCableConnect,
       
   982         CEDIDHandler& aEDIDHandler,
       
   983         CAccessoryControlIf& aAccessoryControlIf,
       
   984         CHDMICableStatusFSM&  aHDMICableStatusFSM ):
       
   985     iTVOutConfigForHDMI( aTVOutConfigForCableConnect ),
       
   986     iEDIDHandler( aEDIDHandler ),
       
   987     iAccessoryControlIf( aAccessoryControlIf ),
       
   988     iHDMICableStatusFSM( aHDMICableStatusFSM )   
       
   989     {
       
   990     FUNC_LOG;
       
   991     }
       
   992 
       
   993 
       
   994 // ======== GLOBAL FUNCTIONS ========
       
   995