internetradio2.0/commandchannelsrc/irctrlcmdobserver.cpp
changeset 0 09774dfdd46b
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "irctrlcmdobserver.h"
       
    20 #include "irctrlcommand.h"
       
    21 #include "irdebug.h"
       
    22 #include "ircontrolparams.h"
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 // ---------------------------------------------------------------------------
       
    26 // Function : NewL
       
    27 // Function returns an instance of CIRCtrlCmdObserver
       
    28 // Two phase constructor
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C CIRCtrlCmdObserver* CIRCtrlCmdObserver::NewL
       
    32 	(MIRCtrlCmdObserver* aObserver,MIRStreamFill* aStream)
       
    33     {
       
    34     IRLOG_DEBUG( "CIRCtrlCmdObserver::NewL" );
       
    35     CIRCtrlCmdObserver* self = CIRCtrlCmdObserver::NewLC(aObserver,aStream);
       
    36     CleanupStack::Pop(self);
       
    37     IRLOG_DEBUG( "CIRCtrlCmdObserver::NewL - Exiting." );
       
    38     return self;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // Function : NewLC
       
    43 // Function returns an instance of CIRCtrlCmdObserver
       
    44 // Two phase constructor
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 EXPORT_C CIRCtrlCmdObserver* CIRCtrlCmdObserver::NewLC
       
    48 	(MIRCtrlCmdObserver* aObserver,MIRStreamFill* aStream)
       
    49     {
       
    50     IRLOG_DEBUG( "CIRCtrlCmdObserver::NewLC" );
       
    51     CIRCtrlCmdObserver* self = new (ELeave) CIRCtrlCmdObserver;
       
    52     CleanupStack::PushL(self);
       
    53     self->ConstructL(aObserver,aStream);
       
    54     IRLOG_DEBUG( "CIRCtrlCmdObserver::NewLC - Exiting." );
       
    55     return self;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // Function : ~CIRCtrlCmdObserver
       
    60 //  Default destructor calls Cancel function which cancel the active request 
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CIRCtrlCmdObserver::~CIRCtrlCmdObserver()
       
    64     {
       
    65     IRLOG_DEBUG( "CIRCtrlCmdObserver::~CIRCtrlCmdObserver" );
       
    66     if ( iVolumeTimer->IsActive() )
       
    67         {
       
    68         iVolumeTimer->Cancel();            
       
    69         }
       
    70     delete iVolumeTimer;    
       
    71     IRLOG_DEBUG( "CIRCtrlCmdObserver::~CIRCtrlCmdObserver - Exiting." );
       
    72     }
       
    73     
       
    74 // ---------------------------------------------------------------------------
       
    75 // Function : SentRequest
       
    76 // Function sends request to handle events represented by TIRControlCommmand
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C void CIRCtrlCmdObserver::SentRequest( TIRControlCommmand aCommand, TInt aValue )
       
    80     {
       
    81     IRLOG_DEBUG( "CIRCtrlCmdObserver::SentRequest" );
       
    82    if(aCommand==EPlayerChanged)
       
    83 	    {
       
    84 	    iObserver->PlayerChanged();	
       
    85 	    }
       
    86     else
       
    87 	    {
       
    88 	    iObserver->MCtrlCommand( aCommand, aValue );
       
    89 	    }
       
    90     IRLOG_DEBUG( "CIRCtrlCmdObserver::SentRequest - Exiting." );
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // Function : FilltheBuffer
       
    95 // Function sends request to fill the buffer
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 EXPORT_C void CIRCtrlCmdObserver::FilltheBuffer(TDes8& aInputBuffer)
       
    99     {
       
   100     IRLOG_DEBUG( "CIRCtrlCmdObserver::FilltheBuffer" );
       
   101     iStream->FilltheBuffer(aInputBuffer);
       
   102     IRLOG_DEBUG( "CIRCtrlCmdObserver::FilltheBuffer - Exiting." );
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // Function : FetchVolume
       
   107 // Function sends request to get the current volume index
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C TInt CIRCtrlCmdObserver::FetchVolume()
       
   111     {
       
   112     IRLOG_DEBUG( "CIRCtrlCmdObserver::FetchVolume" );
       
   113     return iObserver->FetchVolume();
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // Function : AudioFadeInOut
       
   118 // Function is called for audio Fade In Fade Out Effects
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 EXPORT_C void CIRCtrlCmdObserver::AudioFadeInOut
       
   122 	(TIRControlCommmand& aCommand,TInt aValue)
       
   123     {
       
   124     IRLOG_DEBUG( "CIRCtrlCmdObserver::AudioFadeInOut" );
       
   125     iPersistentVolume = aValue;    
       
   126     if ( EBufferFadeIn == aCommand )
       
   127         {
       
   128 		//Audio Fade In effect
       
   129         if ( iVolumeTimer->IsActive() )
       
   130             {
       
   131 			//cancels the previous request if pending
       
   132             iVolumeTimer->Cancel();            
       
   133             }
       
   134         if ( !iVolumeTimer->IsActive() )
       
   135             {
       
   136 			//starts the fade in effect
       
   137             iVolumeLevel = 0;            
       
   138             TTimeIntervalMicroSeconds32 interval(KVolumeTime);
       
   139             iVolumeTimer->Start(interval,interval,TCallBack(
       
   140 			CIRCtrlCmdObserver::StartAudioFadeIn,this));
       
   141             }
       
   142         }
       
   143     else if ( EBufferFadeOut == aCommand )
       
   144         {
       
   145 		//Audio Fade Out effect
       
   146         if ( iVolumeTimer->IsActive() )
       
   147             {
       
   148 			//cancels the previous request if pending
       
   149             iVolumeTimer->Cancel();            
       
   150             }
       
   151         if ( !iVolumeTimer->IsActive() )
       
   152             {
       
   153 			//starts the fade out effect
       
   154             iVolumeLevel = iPersistentVolume;
       
   155             TTimeIntervalMicroSeconds32 interval(KDownVolumeTime);
       
   156             iVolumeTimer->Start(interval,interval,TCallBack(
       
   157 			CIRCtrlCmdObserver::StartAudioFadeOut,this));
       
   158             }
       
   159         }
       
   160     else
       
   161 		{
       
   162         IRLOG_DEBUG( "CIRCtrlCmdObserver::AudioFadeInOut - Exiting." );    
       
   163         return;    
       
   164 		}        
       
   165     IRLOG_DEBUG( "CIRCtrlCmdObserver::AudioFadeInOut - Exiting." );   
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // Function : DoAudioFadeOut
       
   170 // Function is used to sent request start audio Fade Out
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 EXPORT_C void CIRCtrlCmdObserver::DoAudioFadeOut()
       
   174     {
       
   175     IRLOG_DEBUG( "CIRCtrlCmdObserver::DoAudioFadeOut" );
       
   176     //requests to start Audio Fade Out
       
   177 	iObserver->DoAudioFadeOut();
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // Function : ConstructL
       
   182 // Function does all the initializations
       
   183 // Two phase constructor
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CIRCtrlCmdObserver::ConstructL(MIRCtrlCmdObserver* aObserver,
       
   187     MIRStreamFill* aStream)
       
   188     {
       
   189     IRLOG_DEBUG( "CIRCtrlCmdObserver::ConstructL" );
       
   190     iObserver = aObserver;
       
   191     iStream = aStream;
       
   192     iVolumeTimer = CPeriodic::NewL(CPeriodic::EPriorityStandard);
       
   193     IRLOG_DEBUG( "CIRCtrlCmdObserver::ConstructL - Exiting." );
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // Function : CIRCtrlCmdObserver
       
   198 // Function is the default constructor, sets the CActive priority, Line status
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 CIRCtrlCmdObserver::CIRCtrlCmdObserver()
       
   202     {
       
   203     //No implementation    
       
   204     }    
       
   205     
       
   206 // ---------------------------------------------------------------------------
       
   207 // Function : StartAudioFadeIn
       
   208 // Function Starts audio Fade In effects
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 TInt CIRCtrlCmdObserver::StartAudioFadeIn(TAny* aPtr)     
       
   212     {
       
   213     IRLOG_DEBUG( "CIRCtrlCmdObserver::StartAudioFadeIn" );
       
   214     CIRCtrlCmdObserver* self = static_cast<CIRCtrlCmdObserver*>(aPtr);
       
   215     if( self )
       
   216 		{
       
   217 		self->UpdateVolumeInc();
       
   218 		}
       
   219     IRLOG_DEBUG( "CIRCtrlCmdObserver::StartAudioFadeIn - Exiting." );
       
   220     return KErrNone;        
       
   221     }
       
   222  
       
   223 // ---------------------------------------------------------------------------
       
   224 // Function : StartAudioFadeOut
       
   225 // Function Starts audio Fade Out effects
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 TInt CIRCtrlCmdObserver::StartAudioFadeOut(TAny* aPtr)
       
   229     {
       
   230     IRLOG_DEBUG( "CIRCtrlCmdObserver::StartAudioFadeOut" );
       
   231     CIRCtrlCmdObserver* self = static_cast<CIRCtrlCmdObserver*>(aPtr);
       
   232     if( self )
       
   233 		{
       
   234 		self->UpdateVolumeDec();
       
   235 		}
       
   236     IRLOG_DEBUG( "CIRCtrlCmdObserver::StartAudioFadeOut - Exiting." );
       
   237     return KErrNone;
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // Function : UpdateVolumeInc
       
   242 // Function does the Fade In effect
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 void CIRCtrlCmdObserver::UpdateVolumeInc()     
       
   246     {
       
   247     IRLOG_DEBUG( "CIRCtrlCmdObserver::UpdateVolumeInc" );
       
   248     //less than zero condition check the value will never be less than zero
       
   249 	//even when when we start 
       
   250     //primary check is volume becoming greater than equal to current volume 
       
   251 	//level stored in iPersistentVolume
       
   252     if ( iVolumeTimer->IsActive()
       
   253 		&& ( ( 0 <= iVolumeLevel ) 
       
   254 		&& ( iPersistentVolume >= iVolumeLevel ) ) )
       
   255         {
       
   256 		//if the time is volume level is not equal to current volume stored in
       
   257 		// iPersistentVolume
       
   258 		//it will initiates fade in effect
       
   259         iCommand = EBufferFadeIn;
       
   260         iObserver->MCtrlCommand(iCommand,iVolumeLevel);
       
   261         iVolumeLevel++;
       
   262         }
       
   263     else
       
   264         {
       
   265         if ( iVolumeTimer->IsActive() )
       
   266             {
       
   267             iVolumeTimer->Cancel();            
       
   268             }
       
   269         }
       
   270     IRLOG_DEBUG( "CIRCtrlCmdObserver::UpdateVolumeInc - Exiting." );
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // Function : UpdateVolumeDec
       
   275 // Function does the Fade In effect 
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void  CIRCtrlCmdObserver::UpdateVolumeDec()     
       
   279     {
       
   280 	IRLOG_DEBUG( "CIRCtrlCmdObserver::UpdateVolumeDec" );
       
   281 	//primary check is volume becoming lesser than equal to zero level 
       
   282 	if ( iVolumeTimer->IsActive()
       
   283 		&& ( ( 0 <= iVolumeLevel ) 
       
   284 		&& ( iPersistentVolume >= iVolumeLevel ) ) )
       
   285 		{
       
   286 		//if the time is volume level is not equal to current zero
       
   287 		//it will initiates fade out effect
       
   288 		iCommand = EBufferFadeOut;
       
   289 		iObserver->MCtrlCommand(iCommand,iVolumeLevel);
       
   290 		iVolumeLevel--;
       
   291 		}
       
   292 	else
       
   293 		{
       
   294 		if ( iVolumeTimer->IsActive() )
       
   295 			{
       
   296 			iVolumeTimer->Cancel();
       
   297 			}
       
   298 		}
       
   299     IRLOG_DEBUG( "CIRCtrlCmdObserver::UpdateVolumeDec - Exiting." );    
       
   300     }
       
   301 
       
   302