fmradio/fmradio/src/fmradiobacksteppingservicewrapper.cpp
branchRCL_3
changeset 20 93c594350b9a
parent 0 f3d95d9c00ab
equal deleted inserted replaced
19:cce62ebc198e 20:93c594350b9a
       
     1 /*
       
     2 * Copyright (c) 2005 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 for the Back Stepping Service wrapper
       
    15 *
       
    16 */
       
    17 
       
    18 #include <liwcommon.h>
       
    19 #include <liwservicehandler.h>
       
    20 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    21 
       
    22 #include "fmradiobacksteppingservicewrapper.h"
       
    23 
       
    24 _LIT8( KFMRadioBackSteppingPrefix, "FMRADIOBS" );
       
    25 
       
    26 // BS Service implementation UID
       
    27 //const TInt KBSServiceImplUid( 0x2000F840 );
       
    28 
       
    29 // BS Service and Interface ID
       
    30 _LIT8( KFMRadioBSServiceID, "Service.BackStepping" );
       
    31 _LIT8( KFMRadioBSInterface, "IBackStepping" );
       
    32 
       
    33 // BS commands
       
    34 _LIT8( KFMRadioBSCmdInitialize, "Initialize" );
       
    35 _LIT8( KFMRadioBSCmdForwardActivationEvent, "ForwardActivationEvent" );
       
    36 _LIT8( KFMRadioBSCmdHandleBackCommand, "HandleBackCommand" );
       
    37 
       
    38 // BS in param names
       
    39 _LIT8( KFMRadioBSInParamAppUid, "AppUid" );
       
    40 _LIT8( KFMRadioBSInParamState, "State" );
       
    41 _LIT8( KFMRadioBSInParamEnter, "Enter" );
       
    42 
       
    43 // BS out param names
       
    44 _LIT8( KFMRadioBSOutParamStatusInfo, "StatusInfo" );
       
    45 
       
    46 // ======== MEMBER FUNCTIONS =================================================
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CFMRadioBackSteppingServiceWrapper::NewL
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CFMRadioBackSteppingServiceWrapper* CFMRadioBackSteppingServiceWrapper::NewL( TUid aUid )
       
    53     {
       
    54     CFMRadioBackSteppingServiceWrapper* self = new( ELeave ) CFMRadioBackSteppingServiceWrapper;
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL( aUid );
       
    57     CleanupStack::Pop( self );
       
    58     return self;
       
    59     }
       
    60 
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CFMRadioBackSteppingServiceWrapper::CFMRadioBackSteppingServiceWrapper
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CFMRadioBackSteppingServiceWrapper::CFMRadioBackSteppingServiceWrapper()
       
    67     {
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CFMRadioBackSteppingServiceWrapper::ConstructL
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 void CFMRadioBackSteppingServiceWrapper::ConstructL( TUid aUid )
       
    75     {
       
    76     // Create Service Handler and keep as long as access to BS Service needed.
       
    77     iServiceHandler = CLiwServiceHandler::NewL();
       
    78     // For convenience keep pointers to Service Handler param lists.
       
    79     iInParamList = &iServiceHandler->InParamListL();
       
    80     iOutParamList = &iServiceHandler->OutParamListL();
       
    81 
       
    82     // Create AIW criteria.
       
    83     RCriteriaArray criteriaArray;
       
    84     CleanupResetAndDestroyPushL( criteriaArray );
       
    85     CLiwCriteriaItem* criterion = CLiwCriteriaItem::NewLC(
       
    86         KLiwCmdAsStr,
       
    87         KFMRadioBSInterface,
       
    88         KFMRadioBSServiceID );
       
    89     criterion->SetServiceClass( TUid::Uid( KLiwClassBase ) );
       
    90     criteriaArray.AppendL( criterion );
       
    91     CleanupStack::Pop( criterion );
       
    92 
       
    93     // Attach AIW criteria.
       
    94     iServiceHandler->AttachL( criteriaArray );
       
    95     // Get BS Service interface.
       
    96     iServiceHandler->ExecuteServiceCmdL( *criterion, *iInParamList, *iOutParamList );
       
    97     CleanupStack::PopAndDestroy( &criteriaArray );
       
    98 
       
    99     // Check if BS interface can be found from output params.
       
   100     TInt pos( 0 );
       
   101     iOutParamList->FindFirst( pos, KFMRadioBSInterface );
       
   102     if( KErrNotFound != pos )
       
   103         {
       
   104         // Extract BS interface from output params.
       
   105         iBsInterface = ( *iOutParamList )[pos].Value().AsInterface();   
       
   106         }
       
   107 
       
   108     // Initialize BS Service.
       
   109     InitializeL( aUid );
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // CFMRadioBackSteppingServiceWrapper::~CFMRadioBackSteppingServiceWrapper
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 CFMRadioBackSteppingServiceWrapper::~CFMRadioBackSteppingServiceWrapper()
       
   117     {
       
   118     if ( iBsInterface )
       
   119         {
       
   120         iBsInterface->Close();
       
   121         }
       
   122     if ( iServiceHandler )
       
   123         {
       
   124         delete iServiceHandler;
       
   125         }
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CFMRadioBackSteppingServiceWrapper::HandleViewActivationEventL
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CFMRadioBackSteppingServiceWrapper::HandleViewActivationEventL( const TVwsViewId aViewId,
       
   133                                                                      TBool aEnter )
       
   134     {
       
   135     if ( iBsInterface )
       
   136         {
       
   137         // Make Service Handler param lists.
       
   138         iInParamList->Reset();
       
   139         iOutParamList->Reset();
       
   140         
       
   141         RBuf8 buffer;
       
   142         CleanupClosePushL( buffer );
       
   143         buffer.CreateL( KFMRadioBackSteppingPrefix().Length() + KDefaultRealWidth );
       
   144         buffer.Copy( KFMRadioBackSteppingPrefix );
       
   145         // Convert 32-bit signed integer (TInt32) view uid to TInt.
       
   146         TInt64 viewUid = static_cast< TInt64 >( aViewId.iViewUid.iUid );
       
   147         buffer.AppendNum( viewUid );
       
   148             
       
   149         TLiwGenericParam state( KFMRadioBSInParamState, TLiwVariant( buffer ) );
       
   150         iInParamList->AppendL( state );
       
   151         TLiwGenericParam enter( KFMRadioBSInParamEnter, TLiwVariant( aEnter ) );
       
   152         iInParamList->AppendL( enter );
       
   153 
       
   154         // Execute view activation event.
       
   155         iBsInterface->ExecuteCmdL( KFMRadioBSCmdForwardActivationEvent, *iInParamList, *iOutParamList );
       
   156         CleanupStack::PopAndDestroy();
       
   157 
       
   158         // Check if BS Service consumed the event.
       
   159         HandleResultL();
       
   160 
       
   161         iInParamList->Reset();
       
   162         iOutParamList->Reset();
       
   163         }
       
   164     }
       
   165 
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // CFMRadioBackSteppingServiceWrapper::HandleBackCommandL
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 TBool CFMRadioBackSteppingServiceWrapper::HandleBackCommandL( const TVwsViewId aViewId )
       
   172     {
       
   173     TBool retVal = EFalse;
       
   174     if ( iBsInterface )
       
   175         {
       
   176         // Make Service Handler param lists.
       
   177         iInParamList->Reset();
       
   178     	iOutParamList->Reset();
       
   179     	
       
   180         // Create message for back stepping wrapper to handle back command event.
       
   181         RBuf8 buffer;
       
   182         CleanupClosePushL( buffer );
       
   183         buffer.CreateL( KFMRadioBackSteppingPrefix().Length() + KDefaultRealWidth );
       
   184         buffer.Copy( KFMRadioBackSteppingPrefix );
       
   185         // Convert 32-bit signed integer (TInt32) view uid to TInt64.
       
   186         TInt64 viewUid = static_cast< TInt64 >( aViewId.iViewUid.iUid );
       
   187         buffer.AppendNum( viewUid );
       
   188         
       
   189     	TLiwGenericParam state( KFMRadioBSInParamState, TLiwVariant( buffer ) );
       
   190     	iInParamList->AppendL( state );
       
   191     
       
   192         // Execute back event.
       
   193     	iBsInterface->ExecuteCmdL( KFMRadioBSCmdHandleBackCommand, *iInParamList, *iOutParamList );
       
   194         CleanupStack::PopAndDestroy();
       
   195     
       
   196         // Check if BS Service consumes the event.
       
   197         retVal = HandleResultL();
       
   198     
       
   199     	iInParamList->Reset();
       
   200     	iOutParamList->Reset();
       
   201         }
       
   202     
       
   203 	return retVal;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CFMRadioBackSteppingServiceWrapper::InitializeL
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 void CFMRadioBackSteppingServiceWrapper::InitializeL( const TUid aUid )
       
   211     {
       
   212     if ( iBsInterface )
       
   213         {
       
   214         // Initialize BS Service.
       
   215         iInParamList->Reset();
       
   216     	iOutParamList->Reset();
       
   217     
       
   218     	TLiwGenericParam appUid( KFMRadioBSInParamAppUid, TLiwVariant( aUid.iUid ) );
       
   219     	iInParamList->AppendL( appUid );
       
   220     	
       
   221     	iBsInterface->ExecuteCmdL( KFMRadioBSCmdInitialize, *iInParamList, *iOutParamList );
       
   222     
       
   223         if ( !HandleResultL() )
       
   224             {
       
   225             // Initialize command was not consumed.
       
   226             User::Leave( KErrArgument );
       
   227             }
       
   228     
       
   229     	iInParamList->Reset();
       
   230     	iOutParamList->Reset();
       
   231         }
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // CFMRadioBackSteppingServiceWrapper::HandleResultL
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 TInt CFMRadioBackSteppingServiceWrapper::HandleResultL()
       
   239     {
       
   240     TBool retVal( EFalse );
       
   241     // Check if error can be found from outparams.
       
   242     TInt posErr( 0 );
       
   243 	iOutParamList->FindFirst( posErr, LIW::EGenericParamError );
       
   244 	if( KErrNotFound != posErr )
       
   245 		{
       
   246 		// Error code found - extract and handle
       
   247 		TInt errorCode( KErrNone );
       
   248 		( *iOutParamList )[posErr].Value().Get( errorCode );
       
   249 		User::LeaveIfError( errorCode );
       
   250 		}
       
   251     // No errors found. Check if status info can be found from outparams.
       
   252     TInt posStat( 0 );
       
   253     iOutParamList->FindFirst( posStat, KFMRadioBSOutParamStatusInfo );
       
   254     if( KErrNotFound != posStat )
       
   255 		{
       
   256 		// Status info present - extract.
       
   257 		( *iOutParamList )[posStat].Value().Get( retVal );
       
   258 		}
       
   259 	else
       
   260 	    {
       
   261 	    // No status info found.
       
   262 	    User::Leave( KErrNotFound );
       
   263 	    }
       
   264     return retVal;
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // CFMRadioBackSteppingServiceWrapper::HandleViewActivation
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 void CFMRadioBackSteppingServiceWrapper::HandleViewActivation( const TVwsViewId& aNewlyActivatedViewId, 
       
   272                                                                const TVwsViewId& /*aViewIdToBeDeactivated*/ )
       
   273     {
       
   274     TRAP_IGNORE( HandleViewActivationEventL( aNewlyActivatedViewId, ETrue ) )
       
   275     }