os/mm/devsoundextensions/telephonyaudiorouting/Session/src/TelephonyAudioRoutingSession.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:   This class is the main interface to the TelephonyAudioRoutingServer. 
sl@0
    15
*				 It implements the client-side session.
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
                                                           
sl@0
    21
#include <e32math.h>    
sl@0
    22
#include <s32mem.h> 
sl@0
    23
#include "TelephonyAudioRoutingClientServer.h"          
sl@0
    24
#include "TelephonyAudioRoutingSession.h"      
sl@0
    25
#include "TelephonyAudioRoutingRequest.h"
sl@0
    26
#include "TelephonyAudioRoutingPolicyRequest.h"     
sl@0
    27
sl@0
    28
const TInt KReqSetOutput					= 0;
sl@0
    29
const TInt KReqNotifyIfOutputChanged		= 1;
sl@0
    30
const TInt KReqNotifyIfAvailOutputsChanged	= 2; 
sl@0
    31
const TInt KReqMaxSize 						= 3;    
sl@0
    32
                                       
sl@0
    33
// -----------------------------------------------------------------------------
sl@0
    34
// RTelephonyAudioRoutingSession::RTelephonyAudioRoutingSession
sl@0
    35
// C++ default constructor can NOT contain any code, that
sl@0
    36
// might leave.
sl@0
    37
// -----------------------------------------------------------------------------
sl@0
    38
//                                                                                                 
sl@0
    39
EXPORT_C RTelephonyAudioRoutingSession::RTelephonyAudioRoutingSession()                                                         
sl@0
    40
	: RSessionBase(), iConnected(EFalse)                                                                    
sl@0
    41
    {                                                                                            
sl@0
    42
    // No implementation required  
sl@0
    43
                                                         
sl@0
    44
    }                                                                                            
sl@0
    45
                                                                                                 
sl@0
    46
// -----------------------------------------------------------------------------
sl@0
    47
// RTelephonyAudioRoutingSession::ConnectL
sl@0
    48
// Connects a client to the  server
sl@0
    49
// (other items were commented in a header).
sl@0
    50
// -----------------------------------------------------------------------------
sl@0
    51
//                                                                                                
sl@0
    52
EXPORT_C TInt RTelephonyAudioRoutingSession::ConnectL(
sl@0
    53
	CTelephonyAudioRouting& aAudioRouting,
sl@0
    54
	MTelephonyAudioRoutingObserver& aObserver)                                                               
sl@0
    55
    {
sl@0
    56
    	
sl@0
    57
    TELAUDRTNG_RDEBUG(_L("[TELAUDRTNG]\t TelephonyAudioRoutingSession::ConnectL "));
sl@0
    58
    
sl@0
    59
	TInt retry=2;
sl@0
    60
  	TInt err = KErrGeneral;
sl@0
    61
  	
sl@0
    62
 
sl@0
    63
	for (;;)
sl@0
    64
		{
sl@0
    65
		err=CreateSession(KTelAudRtngServName,TVersion(0,0,0));		
sl@0
    66
		if (err!=KErrNotFound && err!=KErrServerTerminated && err!=KErrPermissionDenied)
sl@0
    67
		break;
sl@0
    68
		
sl@0
    69
		if (--retry==0)
sl@0
    70
		break;
sl@0
    71
		} 
sl@0
    72
	
sl@0
    73
	if ( err == KErrNone )
sl@0
    74
		{
sl@0
    75
		// Create active object receive handlers and add it to scheduler
sl@0
    76
		TRAP(err, StartRequestHandlersL(aAudioRouting, aObserver));
sl@0
    77
		if ( err == KErrNone )
sl@0
    78
			{
sl@0
    79
			iConnected = ETrue;
sl@0
    80
			}
sl@0
    81
			
sl@0
    82
		SendReceive(ETelAudRtngServInitialize, TIpcArgs());
sl@0
    83
sl@0
    84
		}
sl@0
    85
	
sl@0
    86
	return err;                                                                                           
sl@0
    87
                                                                              
sl@0
    88
    }        
sl@0
    89
  
sl@0
    90
// -----------------------------------------------------------------------------
sl@0
    91
// RTelephonyAudioRoutingSession::Close
sl@0
    92
// Closes connection to the server.
sl@0
    93
// (other items were commented in a header).
sl@0
    94
// -----------------------------------------------------------------------------
sl@0
    95
//  
sl@0
    96
EXPORT_C void RTelephonyAudioRoutingSession::Close()
sl@0
    97
	{
sl@0
    98
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t RTelephonyAudioRoutingSession[%x]::Close "),this);		
sl@0
    99
	if ( iConnected )
sl@0
   100
		{
sl@0
   101
				
sl@0
   102
		for (TInt i = 0; i < KReqMaxSize; i++)
sl@0
   103
		{
sl@0
   104
			delete iRequests[i];
sl@0
   105
		}
sl@0
   106
		iRequests.Close();		
sl@0
   107
		iAvailableOutputs.Close();
sl@0
   108
		RSessionBase::Close();
sl@0
   109
		iConnected = EFalse;
sl@0
   110
		
sl@0
   111
		}
sl@0
   112
		
sl@0
   113
	}                                                                                       
sl@0
   114
                                                                                                 
sl@0
   115
// -----------------------------------------------------------------------------
sl@0
   116
// RTelephonyAudioRoutingSession::Version
sl@0
   117
// Gets the client side version number.
sl@0
   118
// (other items were commented in a header).
sl@0
   119
// -----------------------------------------------------------------------------
sl@0
   120
//                                                                                            
sl@0
   121
EXPORT_C TVersion RTelephonyAudioRoutingSession::Version() const                                                     
sl@0
   122
    {                                                                                            
sl@0
   123
    return(TVersion(0,0,0));                                               
sl@0
   124
    }   
sl@0
   125
           
sl@0
   126
// -----------------------------------------------------------------------------
sl@0
   127
// RTelephonyAudioRoutingSession::GetDefaultValues
sl@0
   128
// Gets default values for current audio output, previous audio output, and 
sl@0
   129
// show note mode from the server.
sl@0
   130
// (other items were commented in a header).
sl@0
   131
// -----------------------------------------------------------------------------
sl@0
   132
//                                                                                         
sl@0
   133
EXPORT_C void RTelephonyAudioRoutingSession::GetDefaultValuesL()                                        
sl@0
   134
    {
sl@0
   135
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t RTelephonyAudioRoutingSession[%x]::GetDefaultValuesL "),this);	   
sl@0
   136
		
sl@0
   137
	User::LeaveIfError( SendReceive(ETelAudRtngServGetDefaultValues, TIpcArgs(&iDefaultValuePkg)) ); 
sl@0
   138
	
sl@0
   139
	// Set session attributes with values retrieved from Server:
sl@0
   140
	TTelephonyAudioRoutingDefaultParams defParams = iDefaultValuePkg();
sl@0
   141
	
sl@0
   142
	CTelephonyAudioRouting::TAudioOutput currentAudioOutput = defParams.iCurrentAudio;
sl@0
   143
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t GetDefaultValuesL: current audio output = %d "), currentAudioOutput);	
sl@0
   144
	iCurrentAudioOutputPkg() = currentAudioOutput;	 
sl@0
   145
	
sl@0
   146
	CTelephonyAudioRouting::TAudioOutput previousAudioOutput = defParams.iPreviousAudio;
sl@0
   147
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t GetDefaultValuesL: Previous audio output = %d "), previousAudioOutput);	
sl@0
   148
	iPreviousAudioOutputPkg() = previousAudioOutput;
sl@0
   149
	
sl@0
   150
	TBool showNoteMode = defParams.iShowNoteMode;
sl@0
   151
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t GetDefaultValuesL: showNoteMode = %d "), showNoteMode);	
sl@0
   152
	iShowNoteModePkg() = showNoteMode;	 		 	                           
sl@0
   153
    
sl@0
   154
 	} 
sl@0
   155
                                                                                                    
sl@0
   156
// -----------------------------------------------------------------------------
sl@0
   157
// RTelephonyAudioRoutingSession::SetOutput
sl@0
   158
// Send a SetOutput request to server.
sl@0
   159
// (other items were commented in a header).
sl@0
   160
// -----------------------------------------------------------------------------
sl@0
   161
//                                                                                         
sl@0
   162
EXPORT_C void RTelephonyAudioRoutingSession::SetOutput(
sl@0
   163
	CTelephonyAudioRouting::TAudioOutput aOutput, TBool aShowNote)                                        
sl@0
   164
    {
sl@0
   165
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t RTelephonyAudioRoutingSession[%x]::SetOutput "),this);	   
sl@0
   166
sl@0
   167
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t RTelephonyAudioRoutingSession::SetOutput: ShowNote = %d "), aShowNote);	   
sl@0
   168
sl@0
   169
	iRequests[KReqSetOutput]->Cancel();
sl@0
   170
                                                                          
sl@0
   171
	iCurrentAudioOutputPkg() = aOutput;  
sl@0
   172
	iPreviousAudioOutputPkg() = CTelephonyAudioRouting::ENone; 
sl@0
   173
	iErrPkg() = KErrNone;  	
sl@0
   174
	iShowNoteModePkg() = aShowNote;
sl@0
   175
	
sl@0
   176
  	iRequests[KReqSetOutput]->SetActive();	
sl@0
   177
	SendReceive(ETelAudRtngServDoSetOutput, TIpcArgs(&iCurrentAudioOutputPkg, &iPreviousAudioOutputPkg, &iErrPkg, &iShowNoteModePkg), iRequests[KReqSetOutput]->iStatus);  	                            
sl@0
   178
    
sl@0
   179
    } 
sl@0
   180
sl@0
   181
// -----------------------------------------------------------------------------
sl@0
   182
// RTelephonyAudioRoutingSession::GetAvailableOutputsL
sl@0
   183
// Get the available audio outputs from the server.
sl@0
   184
// (other items were commented in a header).
sl@0
   185
// -----------------------------------------------------------------------------
sl@0
   186
//
sl@0
   187
EXPORT_C void RTelephonyAudioRoutingSession::GetAvailableOutputsL()
sl@0
   188
	{
sl@0
   189
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t RTelephonyAudioRoutingSession[%x]::GetAvailableOutputsL"),this);		
sl@0
   190
	iAvailableOutputs.Reset();
sl@0
   191
sl@0
   192
	TPckgBuf<TInt> numOfOutputs;
sl@0
   193
	User::LeaveIfError(SendReceive(ETelAudRtngServGetNoOutputs, TIpcArgs(&numOfOutputs)));
sl@0
   194
	HBufC8* buf = HBufC8::NewLC(numOfOutputs()*sizeof(CTelephonyAudioRouting::TAudioOutput));
sl@0
   195
	TPtr8 ptr = buf->Des();
sl@0
   196
	
sl@0
   197
	User::LeaveIfError(SendReceive(ETelAudRtngServGetAvailableOutputs, TIpcArgs(&ptr)));
sl@0
   198
	RDesReadStream stream(ptr);
sl@0
   199
	CleanupClosePushL(stream);
sl@0
   200
sl@0
   201
	for (TInt i=0; i<numOfOutputs(); i++)
sl@0
   202
		{
sl@0
   203
		TInt err = iAvailableOutputs.Append((CTelephonyAudioRouting::TAudioOutput)stream.ReadInt32L());
sl@0
   204
		if (err)
sl@0
   205
			{
sl@0
   206
			iAvailableOutputs.Reset();
sl@0
   207
			User::Leave(err);
sl@0
   208
			}
sl@0
   209
		}
sl@0
   210
	
sl@0
   211
	CleanupStack::PopAndDestroy(2, buf);//stream, buf
sl@0
   212
		
sl@0
   213
	}
sl@0
   214
	
sl@0
   215
// -----------------------------------------------------------------------------
sl@0
   216
// RTelephonyAudioRoutingSession::NotifyIfOutputChanged
sl@0
   217
// Send a request to server to receive notification whenever current audio output changes.
sl@0
   218
// (other items were commented in a header).
sl@0
   219
// -----------------------------------------------------------------------------
sl@0
   220
//
sl@0
   221
EXPORT_C void RTelephonyAudioRoutingSession::NotifyIfOutputChanged()
sl@0
   222
	{
sl@0
   223
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t RTelephonyAudioRoutingSession[%x]::NotifyIfOutputChanged"),this);	 
sl@0
   224
sl@0
   225
	iRequests[KReqNotifyIfOutputChanged]->Cancel();
sl@0
   226
	
sl@0
   227
	SendReceive(ETelAudRtngServNotifyIfOutputChanged, TIpcArgs(&iCurrentAudioOutputPkg, &iPreviousAudioOutputPkg, &iErrPkg, &iShowNoteModePkg), iRequests[KReqNotifyIfOutputChanged]->iStatus);
sl@0
   228
	iRequests[KReqNotifyIfOutputChanged]->SetActive();
sl@0
   229
	
sl@0
   230
	}
sl@0
   231
sl@0
   232
// -----------------------------------------------------------------------------
sl@0
   233
// RTelephonyAudioRoutingSession::NotifyIfAvailableOutputsChanged
sl@0
   234
// Send a request to server to receive notification whenever available audio output changes.
sl@0
   235
// (other items were commented in a header).
sl@0
   236
// -----------------------------------------------------------------------------
sl@0
   237
//
sl@0
   238
EXPORT_C void RTelephonyAudioRoutingSession::NotifyIfAvailableOutputsChanged()
sl@0
   239
	{
sl@0
   240
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t RTelephonyAudioRoutingSession[%x]::NotifyIfAvailbleOutputsChanged"),this);	
sl@0
   241
	iRequests[KReqNotifyIfAvailOutputsChanged]->Cancel();
sl@0
   242
	     
sl@0
   243
	SendReceive(ETelAudRtngServNotifyIfAvailOutputsChanged, TIpcArgs(&iCurrentAudioOutputPkg), iRequests[KReqNotifyIfAvailOutputsChanged]->iStatus);
sl@0
   244
	iRequests[KReqNotifyIfAvailOutputsChanged]->SetActive();
sl@0
   245
	
sl@0
   246
	}
sl@0
   247
	
sl@0
   248
// -----------------------------------------------------------------------------
sl@0
   249
// RTelephonyAudioRoutingSession::CancelRequest
sl@0
   250
// Cancel a previously sent request.
sl@0
   251
// aRequestOpcode = index into array as to which request object to cancel. 
sl@0
   252
// (other items were commented in a header).
sl@0
   253
// -----------------------------------------------------------------------------
sl@0
   254
//	
sl@0
   255
EXPORT_C void RTelephonyAudioRoutingSession::CancelRequest(TTelAudRtngServRqst aRequestOpcode)
sl@0
   256
	{
sl@0
   257
	TPckgBuf<TInt> request;   
sl@0
   258
  	request() = aRequestOpcode;
sl@0
   259
sl@0
   260
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t CTelephonyAudioRoutingSession::CancelRequest Number: %d"), aRequestOpcode);
sl@0
   261
	SendReceive(ETelAudRtngServCancelRequest, TIpcArgs(&request));	
sl@0
   262
	
sl@0
   263
	}
sl@0
   264
	
sl@0
   265
// -----------------------------------------------------------------------------
sl@0
   266
// RTelephonyAudioRoutingSession::CurrentAudioOutputPkg
sl@0
   267
// Accessor method returns iCurrentAudioOutputPkg to caller.
sl@0
   268
// (other items were commented in a header).
sl@0
   269
// -----------------------------------------------------------------------------
sl@0
   270
//	
sl@0
   271
EXPORT_C TPckgBuf<CTelephonyAudioRouting::TAudioOutput>& RTelephonyAudioRoutingSession::CurrentAudioOutputPkg()
sl@0
   272
	{
sl@0
   273
		return iCurrentAudioOutputPkg;
sl@0
   274
	}
sl@0
   275
	
sl@0
   276
// -----------------------------------------------------------------------------
sl@0
   277
// RTelephonyAudioRoutingSession::PreviousAudioOutputPkg
sl@0
   278
// Accessor method returns iPreviousAudioOutputPkg to caller.
sl@0
   279
// (other items were commented in a header).
sl@0
   280
// -----------------------------------------------------------------------------
sl@0
   281
//	
sl@0
   282
EXPORT_C TPckgBuf<CTelephonyAudioRouting::TAudioOutput>& RTelephonyAudioRoutingSession::PreviousAudioOutputPkg()
sl@0
   283
	{
sl@0
   284
		return iPreviousAudioOutputPkg;
sl@0
   285
	}
sl@0
   286
	
sl@0
   287
// -----------------------------------------------------------------------------
sl@0
   288
// RTelephonyAudioRoutingSession::ErrPkg
sl@0
   289
// Accessor method returns iErrPkg to caller. 
sl@0
   290
// (other items were commented in a header).
sl@0
   291
// -----------------------------------------------------------------------------
sl@0
   292
//	
sl@0
   293
EXPORT_C TPckgBuf<TInt>& RTelephonyAudioRoutingSession::ErrPkg()
sl@0
   294
	{
sl@0
   295
		return iErrPkg;
sl@0
   296
	}
sl@0
   297
	
sl@0
   298
// -----------------------------------------------------------------------------
sl@0
   299
// RTelephonyAudioRoutingSession::AvailableOutputs
sl@0
   300
// Accessor method returns iAvailableOutputs to caller.
sl@0
   301
// (other items were commented in a header).
sl@0
   302
// -----------------------------------------------------------------------------
sl@0
   303
//	
sl@0
   304
EXPORT_C RArray<CTelephonyAudioRouting::TAudioOutput>& RTelephonyAudioRoutingSession::AvailableOutputs()
sl@0
   305
	{
sl@0
   306
		return iAvailableOutputs;
sl@0
   307
	}					
sl@0
   308
sl@0
   309
// -----------------------------------------------------------------------------
sl@0
   310
// RTelephonyAudioRoutingSession::StartRequestHandlersL
sl@0
   311
// Start asynchronous request handlers.
sl@0
   312
// (other items were commented in a header).
sl@0
   313
// -----------------------------------------------------------------------------
sl@0
   314
//
sl@0
   315
void RTelephonyAudioRoutingSession::StartRequestHandlersL(
sl@0
   316
	CTelephonyAudioRouting& aAudioRouting,	
sl@0
   317
	MTelephonyAudioRoutingObserver& aObserver )
sl@0
   318
	{
sl@0
   319
	
sl@0
   320
	CTelephonyAudioRoutingRequest* req = NULL;
sl@0
   321
sl@0
   322
	req = CTelephonyAudioRoutingRequest::NewL(*this, aObserver, aAudioRouting, ETelAudRtngServDoSetOutput);
sl@0
   323
	User::LeaveIfError( iRequests.Append(req) );
sl@0
   324
sl@0
   325
	req = CTelephonyAudioRoutingRequest::NewL(*this, aObserver, aAudioRouting, ETelAudRtngServNotifyIfOutputChanged);
sl@0
   326
	User::LeaveIfError( iRequests.Append(req) );
sl@0
   327
sl@0
   328
	req = CTelephonyAudioRoutingRequest::NewL(*this, aObserver, aAudioRouting, ETelAudRtngServNotifyIfAvailOutputsChanged);
sl@0
   329
	User::LeaveIfError( iRequests.Append(req) );
sl@0
   330
sl@0
   331
	}
sl@0
   332
	
sl@0
   333
// -----------------------------------------------------------------------------
sl@0
   334
// RTelephonyAudioRoutingSession::SetShowNoteMode
sl@0
   335
// Sets session flag iOkToGetShowNoteMode to indicate that it is OK to retrieve value of
sl@0
   336
// iShowNoteMode from the server.
sl@0
   337
// (other items were commented in a header).
sl@0
   338
// -----------------------------------------------------------------------------
sl@0
   339
//	
sl@0
   340
EXPORT_C void RTelephonyAudioRoutingSession::SetShowNoteMode()
sl@0
   341
	{
sl@0
   342
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t RTelephonyAudioRoutingSession[%x]::SetShowNoteMode"),this);	
sl@0
   343
	iOkToGetShowNoteMode = ETrue;
sl@0
   344
	}
sl@0
   345
	
sl@0
   346
// -----------------------------------------------------------------------------
sl@0
   347
// RTelephonyAudioRoutingSession::ShowNoteMode
sl@0
   348
// Provide caller with value of iShowNoteModePkg from server
sl@0
   349
// (other items were commented in a header).
sl@0
   350
// -----------------------------------------------------------------------------
sl@0
   351
//	
sl@0
   352
EXPORT_C TPckgBuf<TBool>& RTelephonyAudioRoutingSession::ShowNoteMode()
sl@0
   353
	{	
sl@0
   354
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t RTelephonyAudioRoutingSession[%x]::ShowNoteMode"),this);
sl@0
   355
	
sl@0
   356
	return iShowNoteModePkg;
sl@0
   357
	}
sl@0
   358
	
sl@0
   359
	
sl@0
   360
// -----------------------------------------------------------------------------
sl@0
   361
// RTelephonyAudioRoutingSession::ResetShowNoteMode
sl@0
   362
// Resets the session flag iOkToGetShowNoteMode to indicate it's not ok to retrieve
sl@0
   363
// value of iSetShowNoteMode from server. (Client can only retrieve it once after a
sl@0
   364
// SetOutputComplete call). (But it can be set internally from an OutputChanged call).
sl@0
   365
// (other items were commented in a header).
sl@0
   366
// -----------------------------------------------------------------------------
sl@0
   367
//	
sl@0
   368
EXPORT_C void RTelephonyAudioRoutingSession::ResetShowNoteMode()
sl@0
   369
	{
sl@0
   370
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t RTelephonyAudioRoutingSession[%x]::ResetShowNoteMode"),this);	
sl@0
   371
	iOkToGetShowNoteMode = EFalse;
sl@0
   372
	}
sl@0
   373
// -----------------------------------------------------------------------------
sl@0
   374
// RTelephonyAudioRoutingSession::OkToGetShowNoteMode
sl@0
   375
// Provide caller with value of iOkToGetShowNoteMode
sl@0
   376
// (other items were commented in a header).
sl@0
   377
// -----------------------------------------------------------------------------
sl@0
   378
//	
sl@0
   379
EXPORT_C TBool RTelephonyAudioRoutingSession::OkToGetShowNoteMode()
sl@0
   380
	{		
sl@0
   381
	return iOkToGetShowNoteMode;
sl@0
   382
	}	
sl@0
   383
// End of File