mmserv/radioutility/radioserver/Session/Src/RadioRequest.cpp
changeset 0 71ca22bcf22a
child 20 b67dd1fc57c5
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Active object for each asynchronous request in RRadioSession.
       
    15 *				 Notifies MRadioObserver upon request completion.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include    "RadioRequest.h"
       
    23 #include    "RadioDebug.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CRadioRequest::CRadioRequest
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CRadioRequest::CRadioRequest(
       
    34 	RRadioSession& aSession,
       
    35 	MRadioObserver& aObserver,
       
    36 	TRadioServerRequest aRequest )
       
    37 	:	CActive(EPriorityStandard),
       
    38 		iSession(aSession),
       
    39 		iObserver(aObserver),
       
    40 		iRequest(aRequest),
       
    41 		iBool(EFalse),
       
    42 		iBoolPckg(iBool),
       
    43 		iInt(0),
       
    44 		iIntPckg(iInt)
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CRadioRequest::ConstructL
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CRadioRequest::ConstructL()
       
    54     {
       
    55 	RADIO_RDEBUG(_L("[RADIO-SESS] CRadioRequest::ConstructL()"));
       
    56 	CActiveScheduler::Add(this);
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CRadioRequest::NewLC
       
    61 // Two-phased constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CRadioRequest* CRadioRequest::NewLC(
       
    65 	RRadioSession& aSession,
       
    66 	MRadioObserver& aObserver,
       
    67 	TRadioServerRequest aRequest )
       
    68     {
       
    69     CRadioRequest* self = new( ELeave ) CRadioRequest(aSession, aObserver, aRequest);
       
    70     CleanupStack::PushL( self );
       
    71     self->ConstructL();
       
    72     return self;
       
    73     }
       
    74 
       
    75 // Destructor
       
    76 CRadioRequest::~CRadioRequest()
       
    77     {
       
    78 	if ( IsActive() )
       
    79 		{
       
    80 		Cancel();
       
    81 		}
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CRadioRequest::CompleteRequest
       
    86 // This method completes the request status and sets the object active
       
    87 // to provide asynchronous behavior.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CRadioRequest::CompleteRequest(
       
    91 	TRadioServerRequest aRequest,
       
    92 	TInt aError )
       
    93     {
       
    94 	iRequest = aRequest;
       
    95 
       
    96 	TRequestStatus* stat = &iStatus;
       
    97     User::RequestComplete(stat, aError);
       
    98 	SetActive();
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CRadioRequest::DoCancel
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CRadioRequest::DoCancel()
       
   106     {
       
   107 	iSession.CancelRequest(iRequest);
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CRadioRequest::RunL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CRadioRequest::RunL()
       
   115     {
       
   116 	TInt err = iStatus.Int();
       
   117 	if ( err == KErrCancel )
       
   118 		{
       
   119 		// Ignore the cancelled request
       
   120 		RADIO_RDEBUG_INT(_L("[RADIO-SESS] CRadioRequest::RunL():cancelled [%d]"), iRequest);
       
   121 		return;
       
   122 		}
       
   123 
       
   124 	switch( iRequest )
       
   125 		{
       
   126 		// Place the most frequent ones on top
       
   127 		case ERadioServStationSeek:
       
   128 			{
       
   129 			iInt = iIntPckg();
       
   130 			RADIO_RDEBUG_INT(_L("[RADIO-SESS] CRadioRequest::RunL(): ERadioServStationSeek [%d]"), iInt);
       
   131 			iObserver.StationSeekComplete(err, iInt);
       
   132 			}
       
   133 			break;
       
   134 		case ERadioServSetFrequency:
       
   135 			{
       
   136 			RADIO_RDEBUG(_L("[RADIO-SESS] CRadioRequest::RunL(): ERadioServSetFrequency"));
       
   137 			iObserver.SetFrequencyComplete(err);
       
   138 			}
       
   139 			break;
       
   140 		case ERadioServRequestTunerControl:
       
   141 			{
       
   142 			RADIO_RDEBUG(_L("[RADIO-SESS] CRadioRequest::RunL(): ERadioServRequestTunerControl"));
       
   143 			iObserver.RequestTunerControlComplete(err);
       
   144 			}
       
   145 			break;
       
   146 		case ERadioServSetFrequencyRange:
       
   147 			{
       
   148 			RADIO_RDEBUG(_L("[RADIO-SESS] CRadioRequest::RunL(): ERadioServSetFrequencyRange"));
       
   149 			iObserver.SetFrequencyRangeComplete(err);
       
   150 			}
       
   151 			break;
       
   152 		case ERadioServPlay:
       
   153 			{
       
   154 			RADIO_RDEBUG(_L("[RADIO-SESS] CRadioRequest::RunL(): ERadioServPlay"));
       
   155 			if ( err != KErrNone )
       
   156 				{
       
   157 				iObserver.RadioEventStateChange(EFalse, err);
       
   158 				}
       
   159 			}
       
   160 			break;
       
   161 		case ERadioServStationSeekByPTY:
       
   162 			{
       
   163 			iInt = iIntPckg();
       
   164 			RADIO_RDEBUG_INT(_L("[RADIO-SESS] CRadioRequest::RunL(): ERadioServStationSeekByPTY [%d]"), iInt);
       
   165 			iObserver.StationSeekByPTYComplete(err, iInt);
       
   166 			}
       
   167 			break;
       
   168 		case ERadioServStationSeekByTA:
       
   169 			{
       
   170 			iInt = iIntPckg();
       
   171 			RADIO_RDEBUG_INT(_L("[RADIO-SESS] CRadioRequest::RunL(): ERadioServStationSeekByTA [%d]"), iInt);
       
   172 			iObserver.StationSeekByTAComplete(err, iInt);
       
   173 			}
       
   174 			break;
       
   175 		case ERadioServStationSeekByTP:
       
   176 			{
       
   177 			iInt = iIntPckg();
       
   178 			RADIO_RDEBUG_INT(_L("[RADIO-SESS] CRadioRequest::RunL(): ERadioServStationSeekByTP [%d]"), iInt);
       
   179 			iObserver.StationSeekByTPComplete(err, iInt);
       
   180 			}
       
   181 			break;
       
   182 		case ERadioServGetFreqByPTY:
       
   183 			{
       
   184 			RArray<TInt> freqList(1);
       
   185 			iObserver.GetFreqByPTYComplete(err, freqList);
       
   186 			}
       
   187 			break;
       
   188 		case ERadioServGetFreqByTA:
       
   189 			{
       
   190 			RArray<TInt> freqList(1);
       
   191 			iObserver.GetFreqByTAComplete(err, freqList);
       
   192 			}
       
   193 			break;
       
   194 		case ERadioServGetPSByPTY:
       
   195 			{
       
   196 			RArray<TRsRdsPSName> psList(1);
       
   197 			iObserver.GetPSByPTYComplete(err, psList);
       
   198 			}
       
   199 			break;
       
   200 		case ERadioServGetPSByTA:
       
   201 			{
       
   202 			RArray<TRsRdsPSName> psList(1);
       
   203 			iObserver.GetPSByTAComplete(err, psList);
       
   204 			}
       
   205 			break;
       
   206 		default:
       
   207 			{
       
   208 			RADIO_RDEBUG(_L("[RADIO-SESS] CRadioRequest::RunL(): ERROR case default !!!"));
       
   209 			User::Panic(_L("RadioServer"), KErrGeneral );
       
   210 			break;
       
   211 			}
       
   212 		}
       
   213     }
       
   214 
       
   215 //  End of File
       
   216