resourcemgmt/hwresourcesmgr/server/src/HWRMFmTxService.cpp
changeset 78 3f0699f2e14c
parent 0 4e1aa6a622a0
equal deleted inserted replaced
77:8a984d260a2d 78:3f0699f2e14c
    39 CHWRMFmTxService::CHWRMFmTxService(CHWRMPluginHandler& aWatcherPluginHandler,
    39 CHWRMFmTxService::CHWRMFmTxService(CHWRMPluginHandler& aWatcherPluginHandler,
    40                                    CHWRMFmTxCommonData& aFmTxCommonData, 
    40                                    CHWRMFmTxCommonData& aFmTxCommonData, 
    41                                    CHWRMFmTxRdsTextConverter& aRdsTextConverter)
    41                                    CHWRMFmTxRdsTextConverter& aRdsTextConverter)
    42     : iWatcherPluginHandler(aWatcherPluginHandler),
    42     : iWatcherPluginHandler(aWatcherPluginHandler),
    43       iFmTxCommonData(aFmTxCommonData), 
    43       iFmTxCommonData(aFmTxCommonData), 
    44       iRdsTextConverter(aRdsTextConverter)
    44       iRdsTextConverter(aRdsTextConverter),
       
    45       iScanRequestType(EFmTxScanTypeNone)
    45     {
    46     {
    46     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::CHWRMFmTxService()" ));
    47     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::CHWRMFmTxService()" ));
    47     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::CHWRMFmTxService - return" ));
    48     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::CHWRMFmTxService - return" ));
    48     }
    49     }
    49 
    50 
   232 
   233 
   233         case EHWRMFmTxCancelGetNextClearFreq:
   234         case EHWRMFmTxCancelGetNextClearFreq:
   234             {
   235             {
   235             COMPONENT_TRACE1( _L("HWRM Server - CHWRMFmTxService::ExecuteMessageL - EHWRMFmTxCancelGetNextClearFreq") );
   236             COMPONENT_TRACE1( _L("HWRM Server - CHWRMFmTxService::ExecuteMessageL - EHWRMFmTxCancelGetNextClearFreq") );
   236 
   237 
       
   238             ResetScanRequest();
   237             CancelPluginCommandL( HWRMFmTxCommand::ETxScanRequestCmdId );
   239             CancelPluginCommandL( HWRMFmTxCommand::ETxScanRequestCmdId );
   238             completeMessage = ETrue; // no responses from plugin cancel commands
   240             completeMessage = ETrue; // no responses from plugin cancel commands
   239             }
   241             }
   240             break;
   242             break;
   241 
   243 
   250         
   252         
   251         case EHWRMFmTxCancelSetNextClearFreq:
   253         case EHWRMFmTxCancelSetNextClearFreq:
   252             {
   254             {
   253             COMPONENT_TRACE1( _L("HWRM Server - CHWRMFmTxService::ExecuteMessageL - EHWRMFmTxCancelSetNextClearFreq") );
   255             COMPONENT_TRACE1( _L("HWRM Server - CHWRMFmTxService::ExecuteMessageL - EHWRMFmTxCancelSetNextClearFreq") );
   254 
   256 
       
   257             ResetScanRequest();
   255             // no hope of cancelling the ESetTxFrequencyCmdId part, so try the ETxScanRequestCmdId
   258             // no hope of cancelling the ESetTxFrequencyCmdId part, so try the ETxScanRequestCmdId
   256             CancelPluginCommandL( HWRMFmTxCommand::ETxScanRequestCmdId );
   259             CancelPluginCommandL( HWRMFmTxCommand::ETxScanRequestCmdId );
   257             completeMessage = ETrue; // no responses from plugin cancel commands
   260             completeMessage = ETrue; // no responses from plugin cancel commands
   258             }
   261             }
   259             break;        
   262             break;        
   377 void CHWRMFmTxService::EnableL(const RMessage2& aMessage)
   380 void CHWRMFmTxService::EnableL(const RMessage2& aMessage)
   378     {
   381     {
   379     COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxService::EnableL(0x%x)" ), aMessage.Int0() );
   382     COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxService::EnableL(0x%x)" ), aMessage.Int0() );
   380 
   383 
   381     LeaveIfOtherReservationL();
   384     LeaveIfOtherReservationL();
       
   385     ResetScanRequest( iFmTxCommonData.IsFmTxHardwareOn() ); 
   382 
   386 
   383     // We cannot enable from "power save" state
   387     // We cannot enable from "power save" state
   384     if ( iFmTxCommonData.IsAccessoryPowerSaveOn() )
   388     if ( iFmTxCommonData.IsAccessoryPowerSaveOn() )
   385         {
   389         {
   386 		// We cannot enable during "power save" due to mutually exclusive accessory connection.			
   390 		// We cannot enable during "power save" due to mutually exclusive accessory connection.			
   412 TBool CHWRMFmTxService::DisableL(const RMessage2& aMessage)
   416 TBool CHWRMFmTxService::DisableL(const RMessage2& aMessage)
   413     {
   417     {
   414     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::DisableL" ) );
   418     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::DisableL" ) );
   415 
   419 
   416     LeaveIfOtherReservationL();
   420     LeaveIfOtherReservationL();
       
   421     ResetScanRequest(); 
   417 
   422 
   418     // We don't need to disable HW from some states
   423     // We don't need to disable HW from some states
   419 	if ( !iFmTxCommonData.IsFmTxHardwareOn() )
   424 	if ( !iFmTxCommonData.IsFmTxHardwareOn() )
   420         {
   425         {
   421         COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::DisableL - HW already off due to power-save mode" ) );
   426         COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::DisableL - HW already off due to power-save mode" ) );
   484     {
   489     {
   485     COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxService::GetNextClearFrequencyL(%d)" ), aClearFreqsRequired );
   490     COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxService::GetNextClearFrequencyL(%d)" ), aClearFreqsRequired );
   486 
   491 
   487     LeaveIfOtherReservationL();
   492     LeaveIfOtherReservationL();
   488 
   493 
   489     LeaveIfTransmitterOffL();
   494     if ( !iFmTxCommonData.IsFmTxHardwareOn() )
   490 
   495         {
   491     // package up the request
   496         EnsureTransmitterOnL( aMessage );
   492     HWRMFmTxCommand::TScanRequestPackage pckg(aClearFreqsRequired);
   497         iScanRequestType = EFmTxScanTypeGet;
   493 
   498         iClearFreqsRequired = aClearFreqsRequired;
   494     ExecutePluginCommandL(aMessage, HWRMFmTxCommand::ETxScanRequestCmdId, EFalse/*not split*/, pckg );
   499         }
       
   500     else
       
   501         {
       
   502         // package up the request
       
   503         HWRMFmTxCommand::TScanRequestPackage pckg( aClearFreqsRequired );
       
   504         ExecutePluginCommandL(aMessage, HWRMFmTxCommand::ETxScanRequestCmdId, EFalse/*not split*/, pckg );
       
   505         }
   495 
   506 
   496     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::GetClearFrequencyL - return" ) ); 
   507     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::GetClearFrequencyL - return" ) ); 
   497     }
   508     }
   498 
   509 
   499 // -----------------------------------------------------------------------------
   510 // -----------------------------------------------------------------------------
   506     {
   517     {
   507     COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxService::SetNextClearFrequencyL(%d)" ), aClearFreqsRequired );
   518     COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxService::SetNextClearFrequencyL(%d)" ), aClearFreqsRequired );
   508 
   519 
   509     LeaveIfOtherReservationL();
   520     LeaveIfOtherReservationL();
   510 
   521 
   511     LeaveIfTransmitterOffL();
   522     if ( !iFmTxCommonData.IsFmTxHardwareOn() )
   512 
   523         {
   513     // package up the request
   524         EnsureTransmitterOnL( aMessage );
   514     HWRMFmTxCommand::TScanRequestPackage pckg(aClearFreqsRequired);
   525         iScanRequestType = EFmTxScanTypeSet;
   515 
   526         iClearFreqsRequired = aClearFreqsRequired;
   516     ExecutePluginCommandL(aMessage, HWRMFmTxCommand::ETxScanRequestCmdId, ETrue/*split*/, pckg );
   527         }
   517     // wait until response before calling SetFrequencyL
   528     else
       
   529         {
       
   530         // package up the request
       
   531         HWRMFmTxCommand::TScanRequestPackage pckg( aClearFreqsRequired );
       
   532         ExecutePluginCommandL(aMessage, HWRMFmTxCommand::ETxScanRequestCmdId, ETrue/*split*/, pckg );
       
   533         // wait until response before calling SetFrequencyL
       
   534         }
   518 
   535 
   519     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::SetNextClearFrequencyL - return" ) ); 
   536     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::SetNextClearFrequencyL - return" ) ); 
   520     }
   537     }
   521 
   538 
   522 // -----------------------------------------------------------------------------
   539 // -----------------------------------------------------------------------------
   790                     THWRMPluginRequestData* data = static_cast<THWRMPluginRequestData*>( 
   807                     THWRMPluginRequestData* data = static_cast<THWRMPluginRequestData*>( 
   791                                            iWatcherTransactionList->FindTransaction( aTransId,
   808                                            iWatcherTransactionList->FindTransaction( aTransId,
   792                                                                                      EFalse ) );
   809                                                                                      EFalse ) );
   793                     if(data)
   810                     if(data)
   794                     	{
   811                     	{
       
   812                         COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxService::ProcessResponseL, EStartObservingCmdId scan type = %d" ), 
       
   813                             iScanRequestType );
       
   814 
       
   815                     	TBool split( ( iScanRequestType != EFmTxScanTypeNone ) ? ETrue : EFalse );
   795                     	TRAP( pluginErr, ExecutePluginCommandL( data->iRequestMessage,
   816                     	TRAP( pluginErr, ExecutePluginCommandL( data->iRequestMessage,
   796                     			HWRMFmTxCommand::ETxOnCmdId,
   817                     			HWRMFmTxCommand::ETxOnCmdId,
   797                     			EFalse/*not split*/,
   818                     			split,
   798                     			pckg ) );
   819                     			pckg ) );
       
   820                     	
       
   821                     	if( !pluginErr && iScanRequestType != EFmTxScanTypeNone )
       
   822                     	    {
       
   823                     	    // Temporarily prevent audio routing.
       
   824                     	    iFmTxCommonData.EnableAudioRouting( EFalse );
       
   825                     	    }
   799                     	}
   826                     	}
   800                     else
   827                     else
   801                     	{
   828                     	{
   802                     	pluginErr = KErrNotFound; // Data is null
   829                     	pluginErr = KErrNotFound; // Data is null
   803                     	}
   830                     	}
   811                 // Unpack the error code
   838                 // Unpack the error code
   812                 HWRMFmTxCommand::TErrorCodeResponsePackage errPckg;
   839                 HWRMFmTxCommand::TErrorCodeResponsePackage errPckg;
   813                 errPckg.Copy(aData);
   840                 errPckg.Copy(aData);
   814                 pluginErr = errPckg();
   841                 pluginErr = errPckg();
   815 
   842 
   816                 COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxService::ProcessResponseL, ETxOnCmdId pluginErr = %d" ), pluginErr );
   843                 COMPONENT_TRACE3( _L( "HWRM Server - CHWRMFmTxService::ProcessResponseL, ETxOnCmdId pluginErr = %d, scan type = %d" ), 
       
   844                     pluginErr, iScanRequestType );
   817 
   845 
   818                 if ( pluginErr == KErrNone || pluginErr == KErrInUse )
   846                 if ( pluginErr == KErrNone || pluginErr == KErrInUse )
   819                     {
   847                     {
   820                     pluginErr = KErrNone; // If already enabled, complete client request with KErrNone
   848                     pluginErr = KErrNone; // If already enabled, complete client request with KErrNone
       
   849 
   821                     // Update common data power save
   850                     // Update common data power save
   822                     iFmTxCommonData.UpdatePowerSaveState( 
   851                     iFmTxCommonData.UpdatePowerSaveState( 
   823                                         CHWRMFmTxCommonData::EHWRMFmTxPowerSaveOff );
   852                                         CHWRMFmTxCommonData::EHWRMFmTxPowerSaveOff );
   824                     // Store the new status
   853                     // Store the new status
   825                     iFmTxCommonData.UpdateStatus(CHWRMFmTxCommonData::EFmTxStateTransOn);
   854                     iFmTxCommonData.UpdateStatus(CHWRMFmTxCommonData::EFmTxStateTransOn);
       
   855 
       
   856                     // Proceed with scan command if needed.
       
   857                     if( iScanRequestType != EFmTxScanTypeNone )
       
   858                         {
       
   859                         THWRMPluginRequestData* data = static_cast<THWRMPluginRequestData*>(iTransactionList->FindTransaction(aTransId, EFalse));
       
   860                         if( data )
       
   861                             {
       
   862                             HWRMFmTxCommand::TScanRequestPackage pckg( iClearFreqsRequired );
       
   863                             TBool split( ( iScanRequestType == EFmTxScanTypeSet ) ? ETrue : EFalse );
       
   864                             ExecutePluginCommandL( data->iRequestMessage, HWRMFmTxCommand::ETxScanRequestCmdId, split, pckg );
       
   865                             }
       
   866                         }
   826                     }
   867                     }
   827                 }
   868                 }
   828                 break;              
   869                 break;              
   829 
   870 
   830             case HWRMFmTxCommand::ETxOffCmdId:
   871             case HWRMFmTxCommand::ETxOffCmdId:
   924                 // Unpack the scan response error code
   965                 // Unpack the scan response error code
   925                 HWRMFmTxCommand::TScanResponsePackage scanPckg;
   966                 HWRMFmTxCommand::TScanResponsePackage scanPckg;
   926                 scanPckg.Copy(aData);
   967                 scanPckg.Copy(aData);
   927                 HWRMFmTxCommand::TScanResponseData scanResp = scanPckg();               
   968                 HWRMFmTxCommand::TScanResponseData scanResp = scanPckg();               
   928                 COMPONENT_TRACE3( _L( "HWRM Server - CHWRMFmTxService::ProcessResponseL, ETxScanRequestCmdId error = %d, found = %d" ), scanResp.iErrorCode, scanResp.iFrequenciesFound );
   969                 COMPONENT_TRACE3( _L( "HWRM Server - CHWRMFmTxService::ProcessResponseL, ETxScanRequestCmdId error = %d, found = %d" ), scanResp.iErrorCode, scanResp.iFrequenciesFound );
   929                                 
   970                 
   930                 if ( scanResp.iErrorCode != KErrNone ||
   971                 if ( scanResp.iErrorCode != KErrNone ||
   931                      scanResp.iFrequenciesFound == 0 ||
   972                      scanResp.iFrequenciesFound == 0 ||
   932                      scanResp.iFrequenciesFound > KClearFrequencyArrayMax ) 
   973                      scanResp.iFrequenciesFound > KClearFrequencyArrayMax ) 
   933                     {
   974                     {
   934                     pluginErr = scanResp.iErrorCode;
   975                     pluginErr = scanResp.iErrorCode;
   955                         // return clear frequency to client
   996                         // return clear frequency to client
   956                         TPckg<TInt> clientClearFreqPckg( firstClearFreq );
   997                         TPckg<TInt> clientClearFreqPckg( firstClearFreq );
   957                         pluginErr = data->iRequestMessage.Write(0,clientClearFreqPckg);
   998                         pluginErr = data->iRequestMessage.Write(0,clientClearFreqPckg);
   958                         }
   999                         }
   959 
  1000 
   960                     if ( pluginErr == KErrNone &&
  1001                     // Disable transmitter if scan state is still get or set (i.e. transmitter not enabled 
       
  1002                     // or disabled explicitly during scan neither accessory connected during scan).
       
  1003                     // If scan state is set, we can still just disable transmitter because frequency is 
       
  1004                     // being set upon next transmitter enabling.
       
  1005                     if ( pluginErr == KErrNone && iScanRequestType != EFmTxScanTypeNone )
       
  1006                         {
       
  1007                         ExecutePluginCommand(HWRMFmTxCommand::ETxOffCmdId);
       
  1008                         if ( iScanRequestType == EFmTxScanTypeSet )
       
  1009                             {
       
  1010                             // Store the new frequency, which is used when next time enabling transmitter
       
  1011                             iFmTxCommonData.UpdateFrequency( firstClearFreq );
       
  1012                             }
       
  1013                         }
       
  1014                     else if ( pluginErr == KErrNone &&
   961                          data->iRequestMessage.Function() == EHWRMFmTxSetNextClearFreq )
  1015                          data->iRequestMessage.Function() == EHWRMFmTxSetNextClearFreq )
   962                         {
  1016                         {
   963                         // Continue split command
  1017                         // Continue split command
   964                         HWRMFmTxCommand::TSetFrequencyPackage pckg( firstClearFreq );
  1018                         HWRMFmTxCommand::TSetFrequencyPackage pckg( firstClearFreq );
   965                         TRAP(pluginErr, ExecutePluginCommandL(data->iRequestMessage, HWRMFmTxCommand::ESetTxFrequencyCmdId, ETrue/*split*/, pckg, firstClearFreq ));
  1019                         TRAP(pluginErr, ExecutePluginCommandL(data->iRequestMessage, HWRMFmTxCommand::ESetTxFrequencyCmdId, ETrue/*split*/, pckg, firstClearFreq ));
  1449             }
  1503             }
  1450         }
  1504         }
  1451 
  1505 
  1452     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::CancelPluginCommandL - return" ) );     
  1506     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::CancelPluginCommandL - return" ) );     
  1453     }
  1507     }
       
  1508 
       
  1509 // -----------------------------------------------------------------------------
       
  1510 // CHWRMFmTxService::EnsureTransmitterOnL
       
  1511 // Enables transmitter for being able to scan and set free frequencies.
       
  1512 // -----------------------------------------------------------------------------
       
  1513 //
       
  1514 void CHWRMFmTxService::EnsureTransmitterOnL( const RMessage2& aMessage )
       
  1515     {
       
  1516     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::EnsureTransmitterOnL" ) );
       
  1517 
       
  1518     // Enable transmitter if not in "power save" state
       
  1519     if ( iFmTxCommonData.IsAccessoryPowerSaveOn() )
       
  1520         {
       
  1521 		// We cannot enable during "power save" due to mutually exclusive accessory connection.			
       
  1522         COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::EnableL - not ready in \"power save\" state" ) );
       
  1523         User::Leave( KErrNotReady );
       
  1524         }
       
  1525     else
       
  1526         {
       
  1527         //start observing       
       
  1528         ExecutePluginCommandL( aMessage, HWRMFmTxCommand::EStartObservingCmdId, EFalse/*not split*/ );
       
  1529         }
       
  1530 
       
  1531     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::EnsureTransmitterOnL - return" ) );     
       
  1532     }
       
  1533 
       
  1534 // -----------------------------------------------------------------------------
       
  1535 // CHWRMFmTxService::ResetScanRequest
       
  1536 // Resets scan request and enables audio routing.
       
  1537 // -----------------------------------------------------------------------------
       
  1538 //
       
  1539 void CHWRMFmTxService::ResetScanRequest( TBool aNotifyAudioPolicy )
       
  1540     {
       
  1541     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxService::ResetScanRequest" ) );
       
  1542 
       
  1543     iFmTxCommonData.EnableAudioRouting( ETrue, aNotifyAudioPolicy );
       
  1544     iScanRequestType = EFmTxScanTypeNone;
       
  1545     }
  1454     
  1546     
  1455 // ========================== OTHER EXPORTED FUNCTIONS =========================
  1547 // ========================== OTHER EXPORTED FUNCTIONS =========================
  1456 
  1548 
  1457 //  End of File  
  1549 //  End of File