phoneapp/phoneuicontrol/src/cphoneremotecontrolhandler.cpp
changeset 0 5f000ab63145
child 23 40a3f856b14d
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2002 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: CPhoneRemoteControlHandler implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <PhoneHandler.h>
       
    21 #include <remconcoreapitarget.h>
       
    22 #include <remconinterfaceselector.h>
       
    23 #include "cphoneremotecontrolhandler.h"
       
    24 #include "phoneconstants.h"
       
    25 #include "phonelogger.h"
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 CPhoneRemoteControlHandler::CPhoneRemoteControlHandler( 
       
    30     MPhoneStateMachine* aStateMachine ) :
       
    31     iStateMachine( aStateMachine ) 
       
    32     {
       
    33     }
       
    34 
       
    35 // -----------------------------------------------------------
       
    36 // CPhoneRemoteControlHandler::ConstructL()
       
    37 // Constructor
       
    38 // (other items were commented in a header).
       
    39 // -----------------------------------------------------------
       
    40 //
       
    41 void CPhoneRemoteControlHandler::ConstructL()
       
    42     {
       
    43     iInterfaceSelector = CRemConInterfaceSelector::NewL();
       
    44     
       
    45     iCoreTarget = CRemConCoreApiTarget::NewL( *iInterfaceSelector, *this );
       
    46     
       
    47     iPhoneHandler = CPhoneHandler::NewL( *iInterfaceSelector );
       
    48     
       
    49     iInterfaceSelector->OpenTargetL();
       
    50 
       
    51     iButtonRepeatTimer = CPeriodic::NewL( CActive::EPriorityHigh );
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------
       
    55 // CPhoneRemoteControlHandler::NewL()
       
    56 // Constructor
       
    57 // (other items were commented in a header).
       
    58 // -----------------------------------------------------------
       
    59 //
       
    60 CPhoneRemoteControlHandler* CPhoneRemoteControlHandler::NewL(
       
    61     MPhoneStateMachine* aStateMachine )
       
    62     {
       
    63     CPhoneRemoteControlHandler* self = 
       
    64         new (ELeave) CPhoneRemoteControlHandler( aStateMachine );
       
    65     
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL();
       
    68     CleanupStack::Pop( self );
       
    69     
       
    70     return self;
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CPhoneRemoteControlHandler::~CPhoneRemoteControlHandler
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CPhoneRemoteControlHandler::~CPhoneRemoteControlHandler()
       
    78     {
       
    79     delete iInterfaceSelector; // it intern deletes iCoreTarget 
       
    80     
       
    81     if(iButtonRepeatTimer)
       
    82         {
       
    83         if( iButtonRepeatTimer->IsActive() ) 
       
    84             {
       
    85             iButtonRepeatTimer->Cancel(); 
       
    86             }
       
    87         delete iButtonRepeatTimer;
       
    88         }
       
    89     
       
    90     delete iPhoneHandler;
       
    91     }
       
    92     
       
    93 // -----------------------------------------------------------------------------
       
    94 // CPhoneRemoteControlHandler::MrccatoCommand
       
    95 //
       
    96 // A command has been received. 
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CPhoneRemoteControlHandler::MrccatoCommand(
       
   100     TRemConCoreApiOperationId aOperationId, 
       
   101     TRemConCoreApiButtonAction aButtonAct )
       
   102     {
       
   103     __PHONELOG2( EBasic, EPhoneControl, "CPhoneRemoteControlHandler::MrccatoCommand - aOperationId(%d) aButtonAct(%d)",
       
   104         aOperationId, aButtonAct );
       
   105     // Save the current command parameters
       
   106     iOperationId = aOperationId;
       
   107     iButtonAct = aButtonAct;
       
   108     
       
   109     TBool handled = EFalse;
       
   110 
       
   111     // Act on the button
       
   112     switch ( aButtonAct )
       
   113         {
       
   114         case ERemConCoreApiButtonClick:
       
   115             {
       
   116             // Pass the remote control operation to the current state
       
   117             TRAP_IGNORE( handled = 
       
   118                 iStateMachine->State()->
       
   119                     HandleRemConCommandL( aOperationId, aButtonAct ) );
       
   120             break;            
       
   121             }
       
   122         case ERemConCoreApiButtonPress:
       
   123             {
       
   124             // Pass the remote control operation to the current state
       
   125             TRAP_IGNORE( handled = 
       
   126                 iStateMachine->State()->
       
   127                     HandleRemConCommandL( aOperationId, aButtonAct ) );
       
   128             // Start the button repeat timer
       
   129             if( iButtonRepeatTimer->IsActive() ) 
       
   130                 {
       
   131                 iButtonRepeatTimer->Cancel();
       
   132                 }
       
   133             iButtonRepeatTimer->Start(
       
   134                 KPhoneButtonRepeatDelay,
       
   135                 KPhoneButtonRepeatDelay,
       
   136                 TCallBack( DoHandleButtonRepeat, this )  );
       
   137             break;
       
   138             }
       
   139         case ERemConCoreApiButtonRelease:
       
   140             {
       
   141             // Cancel the button repeat timer
       
   142             if( iButtonRepeatTimer->IsActive() ) 
       
   143                 {
       
   144                 iButtonRepeatTimer->Cancel();
       
   145                 }
       
   146             break;
       
   147             }
       
   148         default:
       
   149             break;
       
   150         }
       
   151         
       
   152     // send a response if the operation was handled
       
   153     if ( handled )
       
   154         {        
       
   155         TRequestStatus status;
       
   156         
       
   157         switch ( aOperationId )
       
   158             {
       
   159             case ERemConCoreApiVolumeUp:
       
   160                 iCoreTarget->VolumeDownResponse( status, KErrNone );
       
   161                 User::WaitForRequest( status );
       
   162                 break;
       
   163                 
       
   164             case ERemConCoreApiVolumeDown:
       
   165                 iCoreTarget->VolumeUpResponse( status, KErrNone );
       
   166                 User::WaitForRequest( status );
       
   167                 break;
       
   168 
       
   169             default:
       
   170                 break;
       
   171             }
       
   172         }
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CPhoneRemoteControlHandler::DoHandleButtonRepeat
       
   177 // -----------------------------------------------------------------------------    
       
   178 //
       
   179 TInt CPhoneRemoteControlHandler::DoHandleButtonRepeat( TAny* aAny )
       
   180     {
       
   181     CPhoneRemoteControlHandler* self = 
       
   182         reinterpret_cast<CPhoneRemoteControlHandler*>( aAny );
       
   183 
       
   184     __PHONELOG2( EBasic, EPhoneControl, "CPhoneRemoteControlHandler::DoHandleButtonRepeat iOperationId(%d) iButtonAct(%d)",
       
   185         self->iOperationId, self->iButtonAct );
       
   186     // Pass the remote control operation to the current state
       
   187     TRAP_IGNORE( self->iStateMachine->State()->
       
   188                     HandleRemConCommandL( self->iOperationId, 
       
   189                                           self->iButtonAct ) );
       
   190 
       
   191     return KErrNone;
       
   192     }
       
   193 
       
   194 //  End of File