photosgallery/viewframework/tvout/src/glxtvconnectionmonitor.cpp
changeset 0 4e91876724a2
child 3 9a9c174934f5
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008-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:    Monitors the Tv Out Connection
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21  * @internal reviewed 24/08/2007 by D Holland
       
    22  */
       
    23 
       
    24 //  CLASS HEADER
       
    25 #include "glxtvconnectionmonitor.h"
       
    26 
       
    27 //  EXTERNAL INCLUDES
       
    28 
       
    29 //  INTERNAL INCLUDES
       
    30 
       
    31 #include <glxlog.h>
       
    32 #include <glxpanic.h>
       
    33 #include "glxtv.h"
       
    34 
       
    35 
       
    36 //-----------------------------------------------------------------------------
       
    37 // Return new object
       
    38 //-----------------------------------------------------------------------------
       
    39 //
       
    40 CGlxTvConnectionMonitor* CGlxTvConnectionMonitor::NewL(
       
    41                                MGlxTvConnectionObserver& aConnectionObserver ) 
       
    42     {
       
    43     GLX_LOG_INFO("CGlxTvConnectionMonitor::NewL");
       
    44     CGlxTvConnectionMonitor* self = new (ELeave) 
       
    45                 CGlxTvConnectionMonitor( aConnectionObserver );
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51     
       
    52 
       
    53 //-----------------------------------------------------------------------------
       
    54 // Destructor
       
    55 //-----------------------------------------------------------------------------
       
    56 //
       
    57 CGlxTvConnectionMonitor::~CGlxTvConnectionMonitor()
       
    58     {
       
    59     GLX_LOG_INFO("~CGlxTvConnectionMonitor");
       
    60     Cancel();
       
    61     iTvAccServer.Disconnect();
       
    62     }
       
    63 
       
    64 
       
    65 //-----------------------------------------------------------------------------
       
    66 // Default C++ constructor
       
    67 //-----------------------------------------------------------------------------
       
    68 //
       
    69 CGlxTvConnectionMonitor::CGlxTvConnectionMonitor
       
    70                            ( MGlxTvConnectionObserver& aConnectionObserver ) 
       
    71                             :CActive(EPriorityStandard), 
       
    72                              iConnectionObserver ( aConnectionObserver )
       
    73     {
       
    74     GLX_LOG_INFO("CGlxTvConnectionMonitor");
       
    75     CActiveScheduler::Add( this );
       
    76     }
       
    77 
       
    78 
       
    79 //-----------------------------------------------------------------------------
       
    80 // Symbian second phase constructor
       
    81 //-----------------------------------------------------------------------------
       
    82 //
       
    83 void CGlxTvConnectionMonitor::ConstructL()
       
    84     {
       
    85     GLX_LOG_INFO("CGlxTvConnectionMonitor::ConstructL");
       
    86     User::LeaveIfError( iTvAccServer.Connect() );
       
    87     User::LeaveIfError( iTvAccMode.CreateSubSession( iTvAccServer ) );
       
    88     User::LeaveIfError( iTvAccMode.GetAccessoryMode( iCurrentAccMode ) );
       
    89     iConnectionState = ( iCurrentAccMode.iAccessoryMode == EAccModeTVOut );
       
    90 
       
    91     IssueRequest();  
       
    92     }
       
    93 
       
    94 //-----------------------------------------------------------------------------
       
    95 // From class CActive.
       
    96 // Receive notification of change in the connection state
       
    97 //-----------------------------------------------------------------------------
       
    98 //
       
    99 void CGlxTvConnectionMonitor::RunL()
       
   100     {
       
   101     GLX_LOG_INFO("CGlxTvConnectionMonitor::RunL");
       
   102     // Check for errors
       
   103     User::LeaveIfError( iStatus.Int() );
       
   104     // Notify observers
       
   105     IssueNotificationL();
       
   106     // Request the next event
       
   107     IssueRequest();  
       
   108     }
       
   109 
       
   110 
       
   111 //-----------------------------------------------------------------------------
       
   112 // From class CActive.
       
   113 // DoCancel
       
   114 //-----------------------------------------------------------------------------
       
   115 //
       
   116 void CGlxTvConnectionMonitor::DoCancel()
       
   117     {
       
   118     GLX_LOG_INFO("CGlxTvConnectionMonitor::DoCancel");
       
   119     iTvAccMode.CancelNotifyAccessoryModeChanged();
       
   120     }
       
   121 
       
   122 
       
   123 
       
   124 //-----------------------------------------------------------------------------
       
   125 // From class CActive.
       
   126 // RunError
       
   127 //-----------------------------------------------------------------------------
       
   128 //
       
   129 TInt CGlxTvConnectionMonitor::RunError(TInt aError)
       
   130     {
       
   131     GLX_LOG_INFO1("CGlxTvConnectionMonitor::RunError - %d", aError);
       
   132     return KErrNone;
       
   133     }
       
   134 
       
   135 //-----------------------------------------------------------------------------
       
   136 // Is the TV out cable connected
       
   137 // IsConnected
       
   138 //-----------------------------------------------------------------------------
       
   139 //
       
   140 TBool CGlxTvConnectionMonitor::IsConnected() const
       
   141     {
       
   142     GLX_LOG_INFO("CGlxTvConnectionMonitor::IsConnected");
       
   143     return iConnectionState;
       
   144     }
       
   145 
       
   146 
       
   147 //-----------------------------------------------------------------------------
       
   148 // Request accessory server events
       
   149 //-----------------------------------------------------------------------------
       
   150 //
       
   151 void CGlxTvConnectionMonitor::IssueRequest()
       
   152     {
       
   153     GLX_LOG_INFO("CGlxTvConnectionMonitor::IssueRequest");
       
   154     if (!IsActive()) // required for testing
       
   155         {
       
   156         iTvAccMode.NotifyAccessoryModeChanged( iStatus, iCurrentAccMode ); 
       
   157         SetActive(); 
       
   158         }
       
   159     }
       
   160 
       
   161 
       
   162 //-----------------------------------------------------------------------------
       
   163 // Sends notification to observers if TV Out is connected
       
   164 //-----------------------------------------------------------------------------
       
   165 //
       
   166 void CGlxTvConnectionMonitor::IssueNotificationL()
       
   167     {
       
   168     GLX_LOG_INFO("CGlxTvConnectionMonitor::IssueNotificationL");
       
   169     iConnectionState = ( iCurrentAccMode.iAccessoryMode == EAccModeTVOut );
       
   170     iConnectionObserver.HandleTvConnectionStatusChangedL();
       
   171     }
       
   172 
       
   173 
       
   174 
       
   175