resourceinterfaces/fmtransmittercontrol/src/HWRMFmTxImpl.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32svr.h>
       
    20 #include <centralrepository.h>
       
    21 #include <hwrm/hwrmfmtx.h>
       
    22 #include "HWRMFmTxImpl.h"
       
    23 #include "HWRMFmTxClientServer.h"
       
    24 #include "HWRMtrace.h"
       
    25 #include "HWRMFmTxStatusObserver.h"
       
    26 #include "HWRMFmTxFrequencyObserver.h"
       
    27 #include "HWRMFmTxInternalPSKeys.h"
       
    28 #include "hwrmuipluginhandler.h"
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CHWRMFmTxImpl::CHWRMFmTxImpl
       
    34 // C++ constructor
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CHWRMFmTxImpl::CHWRMFmTxImpl() :
       
    38     iClearFrequencyPckg(NULL, 0, 0),
       
    39     iClearFrequencyCountPckg(NULL, 0, 0)
       
    40     {
       
    41     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::CHWRMFmTxImpl()" ) );
       
    42     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::CHWRMFmTxImpl - return" ));
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CHWRMFmTxImpl::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CHWRMFmTxImpl::ConstructL(MHWRMFmTxObserver* aCallback)
       
    51     {
       
    52     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ConstructL()" ) );
       
    53     
       
    54     // NULL is acceptable value for aCallback, just means that 
       
    55     // client is not interested in callbacks.
       
    56     iCallback = aCallback;
       
    57 
       
    58     // Connect the session and order notifications
       
    59     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ConstructL()" ));
       
    60 
       
    61     User::LeaveIfError(iClient.Connect(HWRMResourceTypeFmTx));
       
    62 
       
    63     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ConstructL - Ordering notifications" ) );
       
    64     
       
    65     iStatusObserver    = CHWRMFmTxStatusObserver::NewL(iCallback);
       
    66     iFrequencyObserver = CHWRMFmTxFrequencyObserver::NewL(iCallback);
       
    67     
       
    68     TInt err(KErrNone);    
       
    69 	TRAP(err, iUiPluginHandler = CHwrmUiPluginHandler::NewL( ));
       
    70 	if ( err != KErrNone )
       
    71     	{    	
       
    72     	COMPONENT_TRACE2(_L( "HWRM FM Tx Client - CHWRMFmTxImpl::ConstructL() - No Cone Plugin Handler" ), err );
       
    73     	iUiPluginHandler = NULL;
       
    74     	}
       
    75 	if(iUiPluginHandler)
       
    76 		{
       
    77 			iUiPluginHandler->AddForegroundObserverL(this);    	
       
    78 		}
       
    79 
       
    80 	COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ConstructL - return" ) );    
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // Destructor
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 CHWRMFmTxImpl::~CHWRMFmTxImpl()
       
    89     {
       
    90     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::~CHWRMFmTxImpl()" ) );
       
    91 
       
    92     // close HWRM client, also deletes status observers
       
    93     Close();
       
    94 
       
    95     delete iUiPluginHandler;
       
    96     
       
    97     // iCallback is not owned so it is not cleaned, just set to NULL 
       
    98     iCallback = NULL;
       
    99     
       
   100     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::~CHWRMFmTxImpl - return" ) );
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CHWRMFmTxImpl::Close
       
   105 // Closes session.
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CHWRMFmTxImpl::Close()
       
   109     {
       
   110     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::Close()" ));
       
   111         
       
   112     // Inform session that we are cleaning up now.
       
   113     // Ignore errors, just trace them
       
   114     TInt err(KErrNone);
       
   115     if (iClient.Handle())
       
   116         {
       
   117         err =iClient.ExecuteOperation(EHWRMFmTxCleanup, TIpcArgs());
       
   118         }
       
   119     
       
   120     if ( err != KErrNone )
       
   121         {
       
   122         COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::Close - Error in cleanup: %d" ), err );
       
   123         }
       
   124     
       
   125     // Abort status/frequency notifications
       
   126     if ( iStatusObserver )
       
   127         {
       
   128         COMPONENT_TRACE1( _L( "HWRM FM Tx - CHWRMFmTxImpl::Close - canceling FM Tx Status notifications" ) );
       
   129         iStatusObserver->Cancel();
       
   130         delete iStatusObserver;
       
   131         iStatusObserver = NULL;
       
   132         }
       
   133 
       
   134     delete iFrequencyObserver;
       
   135     iFrequencyObserver = NULL;
       
   136 
       
   137     iClient.Close();
       
   138     
       
   139     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::Close - return" ) );
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CHWRMFmTxImpl::ReserveL
       
   144 // Handles client request to reserve FM Tx
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CHWRMFmTxImpl::ReserveL(TBool aForceNoCCoeEnv)
       
   148     {
       
   149     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ReserveL(0x%x)" ), aForceNoCCoeEnv);
       
   150     
       
   151     if ( !aForceNoCCoeEnv )
       
   152         {        
       
   153         if ( iUiPluginHandler )
       
   154             {
       
   155             // Check that we are on foreground (i.e. we have keyboard focus.)
       
   156             // Note: There can be windows on top of our application that have explicitly disabled keyboard focus,
       
   157             // but then again the foreground/background observer will not kick in in those cases either.
       
   158             // -> We can use focus to determine foreground status here.
       
   159             if ( iUiPluginHandler->InForeground() == EFalse )        
       
   160                 {
       
   161                 COMPONENT_TRACE1( ( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ReserveL - Application does not have focus, Reserve denied." ) ) );
       
   162                 User::Leave(KErrNotReady);
       
   163                 }
       
   164             }
       
   165         else
       
   166             {
       
   167             COMPONENT_TRACE1(_L( "HWRM VibraClient - CHWRMFmTxImpl::::ReserveL - No iUiPluginHandler available" ) );
       
   168             User::Leave(KErrBadHandle);
       
   169             }
       
   170         }
       
   171     
       
   172     // Do the actual reservation
       
   173     DoReserveL(aForceNoCCoeEnv);
       
   174     
       
   175     COMPONENT_TRACE1(_L( "HWRM FM Tx Client - CHWRMFmTxImpl::ReserveL - return" ) );          
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CHWRMFmTxImpl::Release
       
   180 // Handles client request to release FM Tx
       
   181 // -----------------------------------------------------------------------------
       
   182 //  
       
   183 void CHWRMFmTxImpl::Release()
       
   184     {
       
   185     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::Release()" ) );
       
   186 
       
   187     TInt err = DoRelease();
       
   188 
       
   189     if ( err != KErrNone )
       
   190         {
       
   191         COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::Release - execution failed: %d" ), err );
       
   192         }
       
   193     
       
   194     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::Release - return" ) );  
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CHWRMFmTxImpl::Status
       
   199 // Returns current FM Tx state
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 TFmTxState CHWRMFmTxImpl::Status() const
       
   203     {
       
   204     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::Status" ) );
       
   205     
       
   206     TFmTxState state = EFmTxStateUnknown;
       
   207 
       
   208     if ( iStatusObserver )
       
   209         {
       
   210         state = iStatusObserver->Status();
       
   211         }
       
   212 
       
   213     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::Status - return 0x%x" ), state );    
       
   214     
       
   215     return state;
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CHWRMFmTxImpl::EnableL
       
   220 // Handles client request to switch FM Tx ON
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 void CHWRMFmTxImpl::EnableL(TInt aFrequency)
       
   224     {
       
   225     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::EnableL(%d)"), aFrequency );
       
   226 
       
   227     // Defaults to last used frequency
       
   228     if ( !aFrequency )
       
   229         {
       
   230         aFrequency = iFrequencyObserver->Frequency();
       
   231         COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::EnableL default freq = %d"), aFrequency );
       
   232         }
       
   233 
       
   234     // Range check on aFrequency
       
   235     if ( !FrequencyRangeCheck(aFrequency) )
       
   236         {
       
   237         COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::EnableL Out of range error") );
       
   238         User::Leave(KErrArgument);
       
   239         }
       
   240         
       
   241 	// round up to the closest frequency
       
   242     aFrequency = RoundFreqToNearestStep(aFrequency);
       
   243     
       
   244     // Call server 
       
   245     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxOn, TIpcArgs(aFrequency)));
       
   246             
       
   247     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::EnableL - return" ) );
       
   248     }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CHWRMFmTxImpl::DisableL
       
   252 // Handles client request to switch FM Tx OFF
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CHWRMFmTxImpl::DisableL()
       
   256     {
       
   257     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::DisableL" ) );
       
   258         
       
   259     // Call server 
       
   260     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxOff, TIpcArgs()));
       
   261             
       
   262     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::DisableL - return" ) );
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CHWRMFmTxImpl::Frequency
       
   267 // Returns current Tx frequency
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 TInt CHWRMFmTxImpl::Frequency() const
       
   271     {
       
   272     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::Frequency" ) );
       
   273     
       
   274     TInt frequency = 0;
       
   275 
       
   276     if ( iFrequencyObserver )
       
   277         {
       
   278         frequency = iFrequencyObserver->Frequency();
       
   279         }
       
   280                
       
   281     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::Frequency - return %d" ), frequency );
       
   282     
       
   283     return frequency;
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CHWRMFmTxImpl::GetFrequencyRangeL
       
   288 // Handles client query of FM Tx frequency range, and channel spacing (step size)
       
   289 // This may already be cached, otherwise it's queried from the server-side
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 void CHWRMFmTxImpl::GetFrequencyRangeL(TFmTxFrequencyRange& aFrequencyRange) const
       
   293     {
       
   294     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetFrequencyRange" ) );
       
   295 
       
   296     if ( iFrequencyObserver )
       
   297         {
       
   298         if ( iFrequencyObserver->FrequencyRangeUpdated() )
       
   299             {
       
   300             // Return frequency range from CenRep
       
   301             aFrequencyRange.iMinFrequency = iFrequencyObserver->MinFrequency();
       
   302             aFrequencyRange.iMaxFrequency = iFrequencyObserver->MaxFrequency();
       
   303             aFrequencyRange.iStepSize     = iFrequencyObserver->StepSize();             
       
   304             }
       
   305         else
       
   306             {
       
   307             // Request frequency range update from server 
       
   308             TPckg<TFmTxFrequencyRange> freqRangePckg(aFrequencyRange);
       
   309             User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxGetFreqRange, TIpcArgs(&freqRangePckg)));
       
   310             }
       
   311         }
       
   312 
       
   313     COMPONENT_TRACE4( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetFrequencyRange - return %d-%d, %d" ), aFrequencyRange.iMinFrequency, aFrequencyRange.iMaxFrequency, aFrequencyRange.iStepSize );
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CHWRMFmTxImpl::SetFrequencyL
       
   318 // Handles client request to set the Tx frequency
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 void CHWRMFmTxImpl::SetFrequencyL(TInt aFrequency)
       
   322     {
       
   323     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetFrequencyL(%d)"), aFrequency );
       
   324 
       
   325     // Range check on aFrequency
       
   326     if ( !FrequencyRangeCheck(aFrequency) )
       
   327         {
       
   328         COMPONENT_TRACE1( ( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetFrequencyL Out of range error") ) );
       
   329         User::Leave(KErrArgument);
       
   330         }       
       
   331 
       
   332     // round up to the closest frequency
       
   333 	aFrequency = RoundFreqToNearestStep(aFrequency);
       
   334         
       
   335     // Call server 
       
   336     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxSetFreq, TIpcArgs(aFrequency)));
       
   337             
       
   338     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetFrequencyL - return" ) );     
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CHWRMFmTxImpl::GetNextClearFrequency
       
   343 // Handles client request, to scan for available clear frequencies
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CHWRMFmTxImpl::GetNextClearFrequencyL(TInt& aClearFrequency)
       
   347     {
       
   348     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetNextClearFrequencyL") );
       
   349 
       
   350     // Call server 
       
   351     TPckg<TInt> clearFreqPckg(aClearFrequency);    
       
   352     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxGetNextClearFreq, TIpcArgs(&clearFreqPckg)));
       
   353     
       
   354     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetNextClearFrequency - return %d" ), aClearFrequency );   
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CHWRMFmTxImpl::GetNextClearFrequency
       
   359 // Handles client request, to scan for available clear frequencies
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 void CHWRMFmTxImpl::GetNextClearFrequencyL(TClearFrequencyArray& aClearFrequencyArray, TUint& aCount)
       
   363     {
       
   364     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetNextClearFrequencyL, aCount %d"), aCount );
       
   365 
       
   366     // Range check on aCount
       
   367     if ( aCount == 0 ||
       
   368          aCount > KClearFrequencyArrayMax )
       
   369         {
       
   370         COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetNextClearFrequencyL Out of range error") );
       
   371         User::Leave(KErrArgument);
       
   372         }
       
   373 
       
   374     // Call server     
       
   375     TPckg<TClearFrequencyArray> clearFreqArrayPckg(aClearFrequencyArray);    
       
   376     TPckg<TUint> countPckg(aCount);
       
   377     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxGetNextClearFreqArray, TIpcArgs(&clearFreqArrayPckg, &countPckg)));
       
   378         
       
   379     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetNextClearFrequency - return" ) );   
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CHWRMFmTxImpl::GetNextClearFrequency
       
   384 // Handles client request, to scan for available clear frequencies
       
   385 // Asynchronous version
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 void CHWRMFmTxImpl::GetNextClearFrequency(TRequestStatus& aStatus, TInt& aClearFrequency)
       
   389     {
       
   390     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetNextClearFrequency async") );
       
   391 
       
   392     // Call server
       
   393     iClearFrequencyPckg.Set( TPckg<TInt>(aClearFrequency) );
       
   394     iClient.ExecuteAsyncOperation(EHWRMFmTxGetNextClearFreq, TIpcArgs(&iClearFrequencyPckg), aStatus);
       
   395  
       
   396     COMPONENT_TRACE3( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetNextClearFrequency - return %d, %d" ), aStatus.Int(), aClearFrequency );
       
   397     }
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CHWRMFmTxImpl::GetNextClearFrequencyL
       
   401 // Handles client request, to scan for available clear frequencies
       
   402 // Asynchronous version
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 void CHWRMFmTxImpl::GetNextClearFrequencyL(TRequestStatus& aStatus, TClearFrequencyArray& aClearFrequencyArray, TUint& aCount)
       
   406     {
       
   407     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetNextClearFrequencyL async, aCount %d"), aCount );
       
   408 
       
   409     // Range check on aCount
       
   410     if ( aCount == 0 ||
       
   411          aCount > KClearFrequencyArrayMax )
       
   412         {
       
   413         COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetNextClearFrequency Out of range error") );
       
   414         User::Leave(KErrArgument);
       
   415         }
       
   416 
       
   417     // Call server
       
   418 	iClearFrequencyPckg.Set( TPckg<TClearFrequencyArray>(aClearFrequencyArray) );
       
   419 	iClearFrequencyCountPckg.Set( TPckg<TUint>(aCount) );
       
   420     iClient.ExecuteAsyncOperation(EHWRMFmTxGetNextClearFreqArray, TIpcArgs(&iClearFrequencyPckg, &iClearFrequencyCountPckg), aStatus);
       
   421     
       
   422     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetNextClearFrequency - return" ) );     
       
   423     }
       
   424 
       
   425 // -----------------------------------------------------------------------------
       
   426 // CHWRMFmTxImpl::CancelGetNextClearFrequency
       
   427 // Cancels previous GetNextClearFrequency request
       
   428 // -----------------------------------------------------------------------------
       
   429 //
       
   430 void CHWRMFmTxImpl::CancelGetNextClearFrequency()
       
   431     {
       
   432     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::CancelGetNextClearFrequency" ) );
       
   433 
       
   434     TInt error = iClient.ExecuteOperation(EHWRMFmTxCancelGetNextClearFreq, TIpcArgs());
       
   435     
       
   436     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::CancelGetNextClearFrequency - return %d" ), error );
       
   437     }
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CHWRMFmTxImpl::SetNextClearFrequency
       
   441 // Handles client request, to set the Tx frequency to a new available channel
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 void CHWRMFmTxImpl::SetNextClearFrequencyL(TInt& aClearFrequency)
       
   445     {
       
   446     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetNextClearFrequencyL") );
       
   447 
       
   448     // Call server 
       
   449     TPckg<TInt> clearFreqPckg(aClearFrequency);     
       
   450     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxSetNextClearFreq, TIpcArgs(&clearFreqPckg)));
       
   451 
       
   452     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetNextClearFrequencyL - return %d" ), aClearFrequency );
       
   453     }
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // CHWRMFmTxImpl::SetNextClearFrequency
       
   457 // Handles client request, to set the Tx frequency to a new available channel
       
   458 // Asynchronous version
       
   459 // -----------------------------------------------------------------------------
       
   460 //
       
   461 void CHWRMFmTxImpl::SetNextClearFrequency(TRequestStatus& aStatus, TInt& aClearFrequency)
       
   462     {
       
   463     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetNextClearFrequency async") );
       
   464 
       
   465     // Call server     
       
   466     iClearFrequencyPckg.Set( TPckg<TInt>(aClearFrequency) );
       
   467     iClient.ExecuteAsyncOperation(EHWRMFmTxSetNextClearFreq, TIpcArgs(&iClearFrequencyPckg), aStatus);
       
   468     
       
   469     COMPONENT_TRACE3( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetNextClearFrequency - return %d, %d" ), aStatus.Int(), aClearFrequency );
       
   470     }
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // CHWRMFmTxImpl::CancelSetNextClearFrequency
       
   474 // Cancels previous SetNextClearFrequency request
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 void CHWRMFmTxImpl::CancelSetNextClearFrequency()
       
   478     {
       
   479     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::CancelSetNextClearFrequency" ) );
       
   480 
       
   481     TInt error = iClient.ExecuteOperation(EHWRMFmTxCancelSetNextClearFreq, TIpcArgs());
       
   482     
       
   483     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::CancelSetNextClearFrequency - return &d" ), error );
       
   484     }
       
   485 
       
   486 // -----------------------------------------------------------------------------
       
   487 // CHWRMFmTxImpl::IsAutoFrequencyEnabled
       
   488 // Returns whether the automatic frequency mode is ON
       
   489 // -----------------------------------------------------------------------------
       
   490 //
       
   491 TBool CHWRMFmTxImpl::IsAutoFrequencyEnabled()
       
   492     {
       
   493     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::IsAutoFrequencyEnabled" ) );
       
   494 
       
   495     // Not supported yet
       
   496     TBool autoFreqOn = EFalse;
       
   497 
       
   498     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::IsAutoFrequencyEnabled - return %d" ), autoFreqOn );
       
   499 
       
   500     return autoFreqOn;
       
   501     }
       
   502 
       
   503 // -----------------------------------------------------------------------------
       
   504 // CHWRMFmTxImpl::EnableAutoFrequency
       
   505 // Handles client request to turn automatic frequency mode ON
       
   506 // -----------------------------------------------------------------------------
       
   507 //
       
   508 void CHWRMFmTxImpl::EnableAutoFrequencyL()
       
   509     {
       
   510     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::EnableAutoFrequencyL") );
       
   511 
       
   512     // Call server 
       
   513     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxAutoFreqOn, TIpcArgs()));
       
   514 
       
   515     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::EnableAutoFrequencyL - return" ) );      
       
   516     }
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 // CHWRMFmTxImpl::DisableAutoFrequency
       
   520 // Handles client request to turn automatic frequency mode OFF
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 void  CHWRMFmTxImpl::DisableAutoFrequencyL()
       
   524     {
       
   525     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::DisableAutoFrequencyL") );
       
   526 
       
   527     // Call server 
       
   528     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxAutoFreqOff, TIpcArgs()));
       
   529 
       
   530     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::DisableAutoFrequencyL - return" ) );         
       
   531     }
       
   532 
       
   533 // -----------------------------------------------------------------------------
       
   534 // CHWRMFmTxImpl::GetRdsData
       
   535 // Returns current RDS data
       
   536 // -----------------------------------------------------------------------------
       
   537 //
       
   538 void CHWRMFmTxImpl::GetRdsData(TFmTxRdsData& aData)
       
   539     {
       
   540     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetRdsData") );
       
   541 
       
   542     // RDS properties are only defined after 1st SetRds request 
       
   543     if ( RProperty::Get(KPSUidHWRMFmTx, KHWRMFmTxRdsPty, aData.iPty) != KErrNone )
       
   544         {
       
   545         COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetRdsData - PTY Get error" ) );
       
   546         aData.iPty = KRdsPtyNone; // This is ok, use default value
       
   547         }
       
   548         
       
   549     if ( RProperty::Get(KPSUidHWRMFmTx, KHWRMFmTxRdsPtyn, aData.iPtyn) != KErrNone )
       
   550         {
       
   551         COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetRdsData - PTYN Get error" ) );                        
       
   552         aData.iPtyn.Zero(); // This is ok, use default value
       
   553         }       
       
   554 
       
   555     if ( RProperty::Get(KPSUidHWRMFmTx, KHWRMFmTxRdsMs, aData.iMs) != KErrNone )
       
   556         {
       
   557         COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetRdsData - MS Get error" ) );                      
       
   558         aData.iMs = ETrue; // default is Music
       
   559         }  
       
   560 
       
   561     if ( RProperty::Get(KPSUidHWRMFmTx, KHWRMFmTxRdsLangId, aData.iLanguageId) != KErrNone )
       
   562         {
       
   563         COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetRdsData - Language ID Get error" ) );                     
       
   564         aData.iLanguageId = KRdsLanguageUnknown; // This is ok, use default value
       
   565         }
       
   566 
       
   567     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::GetRdsData - return" ) );
       
   568     }
       
   569 
       
   570 // -----------------------------------------------------------------------------
       
   571 // CHWRMFmTxImpl::SetRdsPTY
       
   572 // Handles client request to set the Programme TYpe
       
   573 // -----------------------------------------------------------------------------
       
   574 //
       
   575 void CHWRMFmTxImpl::SetRdsPtyL(TRdsProgrammeType aPty)
       
   576     {
       
   577     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRdsPtyL(%d)"), aPty );
       
   578 
       
   579     if( aPty < KRdsPtyNone || aPty > KRdsPtyAlarm )
       
   580         {
       
   581         User::Leave(KErrArgument);
       
   582         }
       
   583 
       
   584     // Call server 
       
   585     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxSetRdsPty, TIpcArgs(aPty)));
       
   586             
       
   587     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRdsPtyL - return" ) );        
       
   588     }
       
   589 
       
   590 // -----------------------------------------------------------------------------
       
   591 // CHWRMFmTxImpl::SetRdsPTYN
       
   592 // Handles client request to set the Programme TYpe Name
       
   593 // -----------------------------------------------------------------------------
       
   594 //
       
   595 void CHWRMFmTxImpl::SetRdsPtynL(TRdsProgrammeTypeName& aPtyn)
       
   596     {
       
   597     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRdsPtynL(%S)"), &aPtyn );
       
   598 
       
   599     if( aPtyn.Length() > KMaxRdsPtynLength )
       
   600         {
       
   601         User::Leave(KErrArgument);
       
   602         }
       
   603 
       
   604     // Call server 
       
   605     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxSetRdsPtyn, TIpcArgs(&aPtyn)));
       
   606             
       
   607     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRdsPtynL - return" ) );           
       
   608     }
       
   609 
       
   610 // -----------------------------------------------------------------------------
       
   611 // CHWRMFmTxImpl::SetRdsMS
       
   612 // Handles client request to set the Music/Speech flag
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 void CHWRMFmTxImpl::SetRdsMsL(TBool aMusic)
       
   616     {
       
   617     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRdsMsL(%d)"), aMusic );
       
   618 
       
   619     // Call server 
       
   620     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxSetRdsMs, TIpcArgs(aMusic)));
       
   621             
       
   622     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRdsMsL - return" ) );         
       
   623     }
       
   624 
       
   625 // -----------------------------------------------------------------------------
       
   626 // CHWRMFmTxImpl::SetRdsLanguageId
       
   627 // Handles client request to set the language ID
       
   628 // -----------------------------------------------------------------------------
       
   629 //
       
   630 void CHWRMFmTxImpl::SetRdsLanguageIdL(TRdsLanguageIdType aLanguageId)
       
   631     {
       
   632     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRdsLanguageIdL(0x%x)"), aLanguageId );
       
   633 
       
   634     if( aLanguageId < KRdsLanguageUnknown || aLanguageId > KRdsLanguageAmharic )
       
   635         {
       
   636         User::Leave(KErrArgument);
       
   637         }
       
   638 
       
   639     // Call server 
       
   640     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxSetRdsLanguageId, TIpcArgs(aLanguageId)));
       
   641             
       
   642     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRdsLanguageIdL - return" ) );         
       
   643     }
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // CHWRMFmTxImpl::SetRadiotext
       
   647 // Handles client request to set the RT data
       
   648 // -----------------------------------------------------------------------------
       
   649 //
       
   650 void CHWRMFmTxImpl::SetRadiotextL(TDes& aText)
       
   651     {
       
   652     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRadiotextL(%S)"), &aText );
       
   653 
       
   654     // Call server 
       
   655     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxSetRadiotext, TIpcArgs(&aText)));
       
   656             
       
   657     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRadiotextL - return" ) );                 
       
   658     }
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // CHWRMFmTxImpl::SetRadiotextPlusL
       
   662 // Handles client request to set the RT+ data
       
   663 // -----------------------------------------------------------------------------
       
   664 //
       
   665 void CHWRMFmTxImpl::SetRadiotextPlusL(TDes& aText, TRtPlusContentType aContentType)
       
   666     {
       
   667     COMPONENT_TRACE3( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRadiotextPlusL(%S, ct %d)"), &aText, aContentType );
       
   668 
       
   669     // Call server 
       
   670     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxSetRadiotextPlus1, TIpcArgs(&aText, aContentType)));
       
   671             
       
   672     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRadiotextPlusL - return" ) );         
       
   673     }
       
   674 
       
   675 // -----------------------------------------------------------------------------
       
   676 // CHWRMFmTxImpl::SetRadiotextPlusL
       
   677 // Handles client request to set the RT+ data
       
   678 // -----------------------------------------------------------------------------
       
   679 //
       
   680 void CHWRMFmTxImpl::SetRadiotextPlusL(TDes& aText, TRtPlusTag aTag)
       
   681     {
       
   682     COMPONENT_TRACE3( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRadiotextPlusL(%S, tag %d)"), &aText, aTag.iContentType );
       
   683 
       
   684     THWRMRtPlusTagCmdPackage pckg(aTag);
       
   685 
       
   686     // Call server 
       
   687     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxSetRadiotextPlus2, TIpcArgs(&aText, &pckg)));
       
   688             
       
   689     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRadiotextPlusL - return" ) ); 
       
   690     }
       
   691 
       
   692 // -----------------------------------------------------------------------------
       
   693 // CHWRMFmTxImpl::SetRadiotextPlusL
       
   694 // Handles client request to set the RT+ data
       
   695 // -----------------------------------------------------------------------------
       
   696 //
       
   697 void CHWRMFmTxImpl::SetRadiotextPlusL(TDes& aText, TRtPlusTag aTag1, TRtPlusTag aTag2)
       
   698     {
       
   699     COMPONENT_TRACE4( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRadiotextPlusL(%S, tag %d, tag2 %d)"), &aText, aTag1.iContentType, aTag2.iContentType );
       
   700 
       
   701     THWRMRtPlusTagCmdPackage pckg(aTag1);
       
   702     THWRMRtPlusTagCmdPackage pckg2(aTag2);
       
   703 
       
   704     // Call server 
       
   705     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxSetRadiotextPlus3, TIpcArgs(&aText, &pckg, &pckg2)));
       
   706             
       
   707     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::SetRadiotextPlusL - return" ) );         
       
   708     }
       
   709 
       
   710 // -----------------------------------------------------------------------------
       
   711 // CHWRMFmTxImpl::ClearRdsData
       
   712 // Clears any previously set RDS data
       
   713 // -----------------------------------------------------------------------------
       
   714 //
       
   715 void CHWRMFmTxImpl::ClearRdsData()
       
   716     {
       
   717     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ClearRdsData") );
       
   718 
       
   719     // Call server 
       
   720     TInt err = iClient.ExecuteOperation(EHWRMFmTxClearRdsData, TIpcArgs());
       
   721     
       
   722     if ( err != KErrNone )
       
   723         {
       
   724         COMPONENT_TRACE2(  _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ClearRdsData - execution failed: %d" ), err );
       
   725         }
       
   726 
       
   727     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ClearRdsData - return" ) );                  
       
   728     }
       
   729 
       
   730 // -----------------------------------------------------------------------------
       
   731 // CHWRMFmTxImpl::ClearRadiotextData
       
   732 // Clears any previously set RT data
       
   733 // -----------------------------------------------------------------------------
       
   734 //
       
   735 void CHWRMFmTxImpl::ClearRadiotextData()
       
   736     {
       
   737     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ClearRadiotextData") );
       
   738 
       
   739     // Call server 
       
   740     TInt err = iClient.ExecuteOperation(EHWRMFmTxClearRtData, TIpcArgs());
       
   741     
       
   742     if ( err != KErrNone )
       
   743         {
       
   744         COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ClearRadiotextData - execution failed: %d" ), err );
       
   745         }
       
   746 
       
   747     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::ClearRadiotextData - return" ) );                    
       
   748     }
       
   749 
       
   750 //------------------------------------------------------------------------------
       
   751 // CHWRMFmTxImpl::HandleGainingForeground     
       
   752 // Inherited From MCoeForegroundObserver - called when app comes to foreground
       
   753 //------------------------------------------------------------------------------
       
   754 //
       
   755 void CHWRMFmTxImpl::HandleGainingForeground()
       
   756     {
       
   757     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::HandleGainingForeground()" ) );
       
   758 
       
   759     TRAPD(err, DoReserveL(EFalse));
       
   760         
       
   761     if ( err != KErrNone )
       
   762         {
       
   763         COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::HandleGainingForeground - Error reserving: %d " ), err );
       
   764         }
       
   765 
       
   766     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::HandleGainingForeground - return " ) );
       
   767     }
       
   768 
       
   769 //------------------------------------------------------------------------------
       
   770 // CHWRMFmTxImpl::HandleLosingForeground     
       
   771 // Inherited From MCoeForegroundObserver - called when app goes to background 
       
   772 //------------------------------------------------------------------------------
       
   773 void CHWRMFmTxImpl::HandleLosingForeground()
       
   774     {
       
   775     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::HandleLosingForeground()" ) );
       
   776 
       
   777     TInt err = DoRelease();
       
   778 
       
   779     if ( err != KErrNone )
       
   780         {
       
   781         COMPONENT_TRACE2( _L( "HWRM FmTxClient - CHWRMFmTxImpl::HandleLosingForeground - Error releasing: %d " ), err );
       
   782         }
       
   783 
       
   784     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::HandleLosingForeground - return " ) );
       
   785     }
       
   786     
       
   787 // -----------------------------------------------------------------------------
       
   788 // CHWRMFmTxImpl::FrequencyRangeCheck
       
   789 // Helper function for enabling or setting Tx frequency
       
   790 // -----------------------------------------------------------------------------
       
   791 //
       
   792 TBool CHWRMFmTxImpl::FrequencyRangeCheck(TInt aFrequency)   
       
   793     {
       
   794     
       
   795     COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::FrequencyRangeCheck()" ) );
       
   796     
       
   797     TBool retVal = ETrue;
       
   798     
       
   799     if ( iFrequencyObserver->FrequencyRangeUpdated() )
       
   800         {
       
   801         // Check against frequency range in CenRep
       
   802         if ( aFrequency < iFrequencyObserver->MinFrequency() || 
       
   803              aFrequency > iFrequencyObserver->MaxFrequency() )
       
   804             {
       
   805             retVal = EFalse;
       
   806             }
       
   807         }
       
   808     else
       
   809         {
       
   810         // Query frequency range from server    
       
   811         TPckgBuf<TFmTxFrequencyRange> freqRangePckg;
       
   812         TInt err = iClient.ExecuteOperation(EHWRMFmTxGetFreqRange, TIpcArgs(&freqRangePckg));
       
   813         TFmTxFrequencyRange freqRange = freqRangePckg();    
       
   814         COMPONENT_TRACE4( _L("HWRM FM Tx Client - CHWRMFmTxImpl::FrequencyRangeCheck() got from server %d-%d, %d"), freqRange.iMinFrequency, freqRange.iMaxFrequency, freqRange.iStepSize );
       
   815 
       
   816         // Check against frequency range from server        
       
   817         if ( err != KErrNone ||
       
   818              aFrequency < freqRange.iMinFrequency || 
       
   819              aFrequency > freqRange.iMaxFrequency )
       
   820             {
       
   821             retVal = EFalse;        
       
   822             }
       
   823         }
       
   824 
       
   825     COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxImpl::FrequencyRangeCheck() return %d" ), retVal );
       
   826     
       
   827     return retVal;
       
   828     }
       
   829 
       
   830 // -----------------------------------------------------------------------------
       
   831 // CHWRMFmTxImpl::DoReserveL
       
   832 // Helper function for reserving FM Tx resource
       
   833 // -----------------------------------------------------------------------------
       
   834 //
       
   835 void CHWRMFmTxImpl::DoReserveL(TBool aForceNoCCoeEnv)
       
   836     {
       
   837     User::LeaveIfError(iClient.ExecuteOperation(EHWRMFmTxReserve, TIpcArgs(aForceNoCCoeEnv)));
       
   838     }   
       
   839 
       
   840 // -----------------------------------------------------------------------------
       
   841 // CHWRMFmTxImpl::DoRelease
       
   842 // Helper function for releasing FM Tx resource
       
   843 // -----------------------------------------------------------------------------
       
   844 //
       
   845 TInt CHWRMFmTxImpl::DoRelease()
       
   846     {
       
   847     return iClient.ExecuteOperation(EHWRMFmTxRelease, TIpcArgs());
       
   848     }   
       
   849 
       
   850 // -----------------------------------------------------------------------------
       
   851 // CHWRMFmTxImpl::RoundFreqToNearestStep
       
   852 // Round up the frequency to the nearest valid frequency based on the 
       
   853 // frequency range and the step size
       
   854 // -----------------------------------------------------------------------------
       
   855 //
       
   856 TInt CHWRMFmTxImpl::RoundFreqToNearestStep(TInt aFrequency)
       
   857     {
       
   858     TInt stepSize = iFrequencyObserver->StepSize();
       
   859     TInt frequency;
       
   860     
       
   861     frequency = aFrequency - iFrequencyObserver->MinFrequency();
       
   862     
       
   863 	TInt remainder(0);
       
   864     if ( stepSize )
       
   865 	  {
       
   866 	  remainder = frequency % stepSize;
       
   867 	  }
       
   868     
       
   869     if ( remainder == 0)
       
   870     	{
       
   871     	frequency = aFrequency;
       
   872     	}
       
   873     else
       
   874     	{
       
   875     	if (remainder < stepSize / 2)
       
   876     		{
       
   877     		frequency = aFrequency - remainder;
       
   878     		}
       
   879     	else
       
   880     		{
       
   881     		frequency = aFrequency - remainder + stepSize;
       
   882     		}
       
   883     	}
       
   884     return frequency;
       
   885     }   
       
   886 
       
   887 
       
   888 //  End of File