phoneapp/phonemediatorcenter/src/cphonemediatorcommandlistener.cpp
changeset 37 ba76fc04e6c2
child 51 f39ed5e045e0
child 65 2a5d4ab426d3
equal deleted inserted replaced
36:2eacb6118286 37:ba76fc04e6c2
       
     1 /*
       
     2 * Copyright (c) 2008 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 CPhoneMediatorCommandListener class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <MediatorDomainUIDs.h>
       
    21 #include "mphonemenuandcbaevents.h"
       
    22 #include "mphonekeyeventhandler.h"
       
    23 #include "mphoneviewcommandhandle.h"
       
    24 #include "cphonemediatorcommandlistener.h"
       
    25 #include "phonelogger.h"
       
    26 #include "phonemediatorpackagetypes.h"
       
    27 #include "cphonestatehandle.h"
       
    28 #include "tphonecmdparamboolean.h"
       
    29 #include "videoteltophonecommandsapi.h"
       
    30 #include "mediatoraudiocommandstotelephonyapi.h"
       
    31 #include "phoneui.pan"
       
    32 #include "phoneui.hrh"
       
    33 #include "pevirtualengine.h"
       
    34 #include "mpeengineinfo.h"
       
    35 #include "mediatorcommandstotelephonyapi.h"
       
    36 #include "cphonereconnectquery.h"
       
    37 
       
    38 // ================= MEMBER FUNCTIONS =======================
       
    39 
       
    40 // ---------------------------------------------------------
       
    41 // CPhoneMediatorCommandListener::Instance
       
    42 // Initializes the singleton object
       
    43 // (other items were commented in a header).
       
    44 // ---------------------------------------------------------
       
    45 //
       
    46 CPhoneMediatorCommandListener* CPhoneMediatorCommandListener::Instance()
       
    47     {
       
    48     CPhoneMediatorCommandListener* instance = static_cast<CPhoneMediatorCommandListener*> 
       
    49         ( CCoeEnv::Static ( KUidMediatorCommandListenerSingleton ) );
       
    50     
       
    51     if ( !instance )
       
    52         {
       
    53         TRAPD( err, instance = CPhoneMediatorCommandListener::NewL() );
       
    54         if ( err )
       
    55             {
       
    56             Panic( EPhoneUtilsCouldNotCreateSingleton );    
       
    57             }
       
    58         }
       
    59     return instance;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CPhoneMediatorCommandListener::CPhoneMediatorCommandListener
       
    64 // C++ default constructor can NOT contain any code, that
       
    65 // might leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CPhoneMediatorCommandListener::CPhoneMediatorCommandListener() :
       
    69     CCoeStatic( KUidMediatorCommandListenerSingleton )
       
    70     {
       
    71     }
       
    72 
       
    73 // Destructor
       
    74 CPhoneMediatorCommandListener::~CPhoneMediatorCommandListener()
       
    75     {
       
    76     if ( iCommandResponder )
       
    77         {
       
    78         iCommandResponder->UnregisterCommand( KMediatorTelephonyDomain, 
       
    79                                               KCatVideoTelToPhoneCommands, 
       
    80                                               iVideoTelCommands );
       
    81 
       
    82         iCommandResponder->UnregisterCommand( KMediatorTelephonyDomain, 
       
    83                                               KCatAudioCommandsToTelephony, 
       
    84                                               iAudioCommands );
       
    85 
       
    86         iCommandResponder->UnregisterCommand( KMediatorTelephonyDomain, 
       
    87                                               KCatCommandsToTelephony, 
       
    88                                               iGenericCommands );
       
    89 
       
    90         delete iCommandResponder;
       
    91         iCommandResponder = NULL;
       
    92         }
       
    93     iVideoTelCommands.Close();
       
    94     iAudioCommands.Close();
       
    95     iGenericCommands.Close();
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CPhoneMediatorCommandListener::ConstructL
       
   100 // Symbian 2nd phase constructor can leave.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CPhoneMediatorCommandListener::ConstructL()
       
   104     {
       
   105     __LOGMETHODSTARTEND(EPhoneMediatorCenter, "CPhoneMediatorCommandListener::ConstructL( ) ");
       
   106 
       
   107     RegisterMediatorCommandsL();
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------
       
   111 // CPhoneMediatorCommandListener::NewL()
       
   112 // Constructor
       
   113 // (other items were commented in a header).
       
   114 // -----------------------------------------------------------
       
   115 //
       
   116 CPhoneMediatorCommandListener* CPhoneMediatorCommandListener::NewL()
       
   117     {
       
   118     __LOGMETHODSTARTEND(EPhoneMediatorCenter, "CPhoneMediatorCommandListener::NewL( ) ");
       
   119     CPhoneMediatorCommandListener* self = new( ELeave ) CPhoneMediatorCommandListener();
       
   120     
       
   121     CleanupStack::PushL( self );
       
   122     self->ConstructL();
       
   123     CleanupStack::Pop( self );
       
   124     
       
   125     return self;
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CPhoneMediatorCommandListener::Initialize
       
   130 // -----------------------------------------------------------------------------
       
   131 //    
       
   132 void CPhoneMediatorCommandListener::Initialize( 
       
   133     MPhoneMenuAndCbaEvents* aMenuAndCbaEventHandler,
       
   134     MPhoneEngineMessageSender* aMessageSender,
       
   135     MPEEngineInfo* aEngineInfo )
       
   136     {
       
   137     __LOGMETHODSTARTEND(EPhoneMediatorCenter, "CPhoneMediatorCommandListener::Initialize( ) ");
       
   138     iMenuAndCbaHandler = aMenuAndCbaEventHandler;
       
   139     iMessageSender = aMessageSender;
       
   140     iEngineInfo = aEngineInfo;
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CPhoneMediatorCommandListener::RegisterMediatorCommandsL
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CPhoneMediatorCommandListener::RegisterMediatorCommandsL()
       
   148     {
       
   149     __LOGMETHODSTARTEND(EPhoneMediatorCenter, 
       
   150         "CPhoneMediatorCommandListener::RegisterMediatorCommandsL( ) ");
       
   151     iCommandResponder = CMediatorCommandResponder::NewL( this );
       
   152 
       
   153     RegisterVideoTelephonyMediatorCommands();
       
   154     RegisterAudioMediatorCommands();
       
   155     RegisterGenericMediatorCommands();                                                
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CPhoneMediatorCommandListener::RegisterVideoTelephonyMediatorCommands
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CPhoneMediatorCommandListener::RegisterVideoTelephonyMediatorCommands()
       
   163     {
       
   164     __LOGMETHODSTARTEND(EPhoneMediatorCenter, 
       
   165         "CPhoneMediatorCommandListener::RegisterVideoTelephonyMediatorCommands( ) ");
       
   166     TCapabilitySet caps;
       
   167     caps.SetEmpty();
       
   168 
       
   169     // Video Telephony Commands
       
   170     MediatorService::TCommand newCommand;
       
   171     newCommand.iCommandId = EVtCmdFallback;
       
   172     newCommand.iVersion = TVersion( KVideoTelToPhoneCmdVersionMajor, 
       
   173         KVideoTelToPhoneCmdVersionMinor, KVideoTelToPhoneCmdVersionBuild );
       
   174     caps.Set( ECapabilityNetworkControl );
       
   175     newCommand.iCaps = caps;
       
   176     newCommand.iTimeout = KPhoneUiMediatorIfTimeout;    
       
   177     iVideoTelCommands.Append( newCommand );
       
   178 
       
   179     newCommand.iCommandId = EVtCmdSwitchToVoice;
       
   180     iVideoTelCommands.Append( newCommand );
       
   181     
       
   182     newCommand.iCommandId = EVtCmdLowMemory;
       
   183     iVideoTelCommands.Append( newCommand );
       
   184 
       
   185     // Register Video Telephony Commands
       
   186     TInt error = iCommandResponder->RegisterCommand( KMediatorTelephonyDomain, 
       
   187                                                      KCatVideoTelToPhoneCommands, 
       
   188                                                      iVideoTelCommands );
       
   189     __ASSERT_DEBUG( error == KErrNone, Panic( EPhoneMediatorCenterRegistrationFailed ) );
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CPhoneMediatorCommandListener::RegisterAudioMediatorCommands
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 void CPhoneMediatorCommandListener::RegisterAudioMediatorCommands()
       
   197     {
       
   198     __LOGMETHODSTARTEND(EPhoneMediatorCenter, 
       
   199         "CPhoneMediatorCommandListener::RegisterAudioMediatorCommands( ) ");
       
   200     TCapabilitySet caps;
       
   201     caps.SetEmpty();
       
   202 
       
   203     // Audio Commands
       
   204     MediatorService::TCommand newCommand;
       
   205     newCommand.iCommandId = EAudioCmdUnmute;
       
   206     newCommand.iVersion = TVersion( KAudioCmdToTelephonyVersionMajor, 
       
   207         KAudioCmdToTelephonyVersionMinor, KAudioCmdToTelephonyVersionBuild );
       
   208     caps.Set( ECapabilityNetworkControl );
       
   209     newCommand.iCaps = caps;
       
   210     newCommand.iTimeout = KPhoneUiMediatorIfTimeout;    
       
   211     iAudioCommands.Append( newCommand );
       
   212 
       
   213     newCommand.iCommandId = EAudioCmdMute;
       
   214     iAudioCommands.Append( newCommand );
       
   215 
       
   216     // Register Audio Commands
       
   217     TInt error = iCommandResponder->RegisterCommand( KMediatorTelephonyDomain, 
       
   218                                                      KCatAudioCommandsToTelephony, 
       
   219                                                      iAudioCommands );
       
   220     __ASSERT_DEBUG( error == KErrNone, Panic( EPhoneMediatorCenterRegistrationFailed ) );
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CPhoneMediatorCommandListener::RegisterGenericMediatorCommands
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CPhoneMediatorCommandListener::RegisterGenericMediatorCommands()
       
   228     {
       
   229     __LOGMETHODSTARTEND(EPhoneMediatorCenter, 
       
   230         "CPhoneMediatorCommandListener::RegisterGenericMediatorCommands( ) ");
       
   231     TCapabilitySet caps;
       
   232     caps.SetEmpty();
       
   233 
       
   234     // Generic Commands
       
   235     MediatorService::TCommand newCommand;
       
   236     newCommand.iCommandId = EPhoneCmdEndActiveCall;
       
   237     newCommand.iVersion = TVersion( KTelephonyCommandsVersionMajor, 
       
   238         KTelephonyCommandsVersionMinor, KTelephonyCommandsVersionBuild );
       
   239     caps.Set( ECapabilityNetworkControl );
       
   240     newCommand.iCaps = caps;
       
   241     newCommand.iTimeout = KPhoneUiMediatorIfTimeout;    
       
   242     iGenericCommands.Append( newCommand );
       
   243 
       
   244     // Register Generic Commands
       
   245     TInt error = iCommandResponder->RegisterCommand( KMediatorTelephonyDomain, 
       
   246                                                      KCatCommandsToTelephony, 
       
   247                                                      iGenericCommands );
       
   248     __ASSERT_DEBUG( error == KErrNone, Panic( EPhoneMediatorCenterRegistrationFailed ) );
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CPhoneMediatorCommandListener::MediatorCommandL
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CPhoneMediatorCommandListener::MediatorCommandL( 
       
   256     TUid aDomain, 
       
   257     TUid aCategory, 
       
   258     TInt aCommandId, 
       
   259     TVersion aVersion, 
       
   260     const TDesC8& /*aData*/ )
       
   261     {
       
   262     __LOGMETHODSTARTEND(EPhoneMediatorCenter, "CPhoneMediatorCommandListener::MediatorCommandL( ) ");
       
   263     if( aDomain == KMediatorTelephonyDomain &&
       
   264         aCategory == KCatVideoTelToPhoneCommands )
       
   265         {
       
   266         VideoTelephonyCommandL( aCommandId, aVersion );
       
   267         SendResponse( aDomain, aCategory, aCommandId );
       
   268         return;         
       
   269         }
       
   270     else if( aDomain == KMediatorTelephonyDomain &&
       
   271              aCategory == KCatAudioCommandsToTelephony )
       
   272         {
       
   273         AudioCommandL( aCommandId, aVersion );
       
   274         SendResponse( aDomain, aCategory, aCommandId );
       
   275         return;
       
   276         }
       
   277     else if( aDomain == KMediatorTelephonyDomain &&
       
   278              aCategory == KCatCommandsToTelephony )
       
   279         {
       
   280         GenericCommandL( aCommandId, aVersion );
       
   281         SendResponse( aDomain, aCategory, aCommandId );
       
   282         return;         
       
   283         }
       
   284     
       
   285     TInt error = iCommandResponder->IssueResponse( aDomain, 
       
   286                                                  aCategory, 
       
   287                                                  aCommandId,
       
   288                                                  KErrNotFound, 
       
   289                                                  KNullDesC8 );                              
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CPhoneMediatorCommandListener::CancelMediatorCommand
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 void CPhoneMediatorCommandListener::CancelMediatorCommand( 
       
   297     TUid /*aDomain*/,
       
   298     TUid /*aCategory*/, 
       
   299     TInt /*aCommandId*/ )
       
   300     {
       
   301     __LOGMETHODSTARTEND(EPhoneMediatorCenter, 
       
   302         "CPhoneMediatorCommandListener::CancelMediatorCommand( ) ");
       
   303     }
       
   304 
       
   305 // -----------------------------------------------------------------------------
       
   306 // CPhoneMediatorCommandListener::SendResponse
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 void CPhoneMediatorCommandListener::SendResponse( 
       
   310     TUid aDomain, 
       
   311     TUid aCategory, 
       
   312     TInt aCommandId )
       
   313     {
       
   314     __LOGMETHODSTARTEND(EPhoneMediatorCenter, 
       
   315         "CPhoneMediatorCommandListener::SendResponse( ) ");
       
   316     iCommandResponder->IssueResponse( aDomain, 
       
   317                                       aCategory, 
       
   318                                       aCommandId,
       
   319                                       KErrNone, 
       
   320                                       KNullDesC8 );     
       
   321     }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CPhoneMediatorCommandListener::VideoTelephonyCommandL
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 void CPhoneMediatorCommandListener::VideoTelephonyCommandL( TInt aCommandId, TVersion /*aVersion*/ )
       
   328     {
       
   329     __LOGMETHODSTARTEND(EPhoneMediatorCenter, 
       
   330         "CPhoneMediatorCommandListener::VideoTelephonyCommandL( ) ");
       
   331         
       
   332     __ASSERT_DEBUG( iMenuAndCbaHandler, Panic( EPhoneMediatorCenterSingletonNotInitialized ) );
       
   333     __ASSERT_DEBUG( iMessageSender, Panic( EPhoneMediatorCenterSingletonNotInitialized ) );
       
   334     
       
   335     switch( aCommandId )
       
   336         {
       
   337         case EVtCmdFallback:
       
   338             iMenuAndCbaHandler->HandleCommandL( EPhoneInCallCmdEndThisActiveCall );
       
   339             CPhoneReconnectQuery::InstanceL()->ShowReconnectQueryL( ETrue );
       
   340             break;
       
   341             
       
   342         case EVtCmdSwitchToVoice:
       
   343             iMenuAndCbaHandler->HandleCommandL( EPhoneCmdYesSwitchToVoice );
       
   344             break;
       
   345             
       
   346         case EVtCmdLowMemory:
       
   347             iMenuAndCbaHandler->HandleCommandL( EPhoneCmdVideoCallOutOfMemory );
       
   348             break;
       
   349             
       
   350         default:
       
   351             __ASSERT_DEBUG( false, Panic( EPhoneMediatorCenterInvalidCommand ) );
       
   352             break;
       
   353         }       
       
   354     }
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CPhoneMediatorCommandListener::AudioCommandL
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 void CPhoneMediatorCommandListener::AudioCommandL( TInt aCommandId, TVersion /*aVersion*/ )
       
   361     {
       
   362     __LOGMETHODSTARTEND(EPhoneMediatorCenter, 
       
   363         "CPhoneMediatorCommandListener::AudioCommandL( ) ");
       
   364 
       
   365     __ASSERT_DEBUG( iMessageSender, Panic( EPhoneMediatorCenterSingletonNotInitialized ) );
       
   366     __ASSERT_DEBUG( iEngineInfo, Panic( EPhoneMediatorCenterSingletonNotInitialized ) );
       
   367         
       
   368     switch( aCommandId )
       
   369         {
       
   370         case EAudioCmdUnmute:
       
   371             iEngineInfo->SetAudioMuteCommand( false );
       
   372             iMessageSender->SendPhoneEngineMessage( MPEPhoneModel::EPEMessageSetAudioMute );
       
   373             break;
       
   374             
       
   375         case EAudioCmdMute:
       
   376             iEngineInfo->SetAudioMuteCommand( true );
       
   377             iMessageSender->SendPhoneEngineMessage( MPEPhoneModel::EPEMessageSetAudioMute );
       
   378             break;
       
   379             
       
   380         default:
       
   381             __ASSERT_DEBUG( false, Panic( EPhoneMediatorCenterInvalidCommand ) );
       
   382             break;
       
   383         }
       
   384     }
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // CPhoneMediatorCommandListener::GenericCommandL
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 void CPhoneMediatorCommandListener::GenericCommandL( TInt aCommandId, TVersion /*aVersion*/ )
       
   391     {
       
   392     __LOGMETHODSTARTEND(EPhoneMediatorCenter, 
       
   393         "CPhoneMediatorCommandListener::GenericCommandL( ) ");
       
   394     __ASSERT_DEBUG( iMenuAndCbaHandler, Panic( EPhoneMediatorCenterSingletonNotInitialized ) );
       
   395 
       
   396     switch( aCommandId )
       
   397         {
       
   398         case EPhoneCmdEndActiveCall:
       
   399             iMenuAndCbaHandler->HandleCommandL( EPhoneInCallCmdEndThisActiveCall );
       
   400             break;
       
   401             
       
   402         default:
       
   403             __ASSERT_DEBUG( false, Panic( EPhoneMediatorCenterInvalidCommand ) );
       
   404             break;
       
   405         }
       
   406     }
       
   407 
       
   408 // End of File