os/mm/devsoundextensions/telephonyaudiorouting/TelephonyAudioRoutingManager/src/TelephonyAudioRoutingManager.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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:   Methods for CTelephonyAudioRoutingManager class
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
// INCLUDE FILES
sl@0
    21
#include <e32base.h>
sl@0
    22
#include <e32svr.h>
sl@0
    23
#include <e32std.h>
sl@0
    24
sl@0
    25
#include "TelephonyAudioRoutingManager.h"
sl@0
    26
#include "TelephonyAudioRoutingClientServer.h"
sl@0
    27
#include "TelephonyAudioRoutingServer.h"
sl@0
    28
#include "TelephonyAudioRoutingManagerSession.h"
sl@0
    29
sl@0
    30
const TUid KTelAudRtngServerUid = {0x10207A93};
sl@0
    31
sl@0
    32
const TInt KTelAudRtngServerStackSize=0x2000;			//  8KB
sl@0
    33
const TInt KTelAudRtngServerInitHeapSize=0x1000;		//  4KB
sl@0
    34
const TInt KTelAudRtngServerMaxHeapSize=0x1000000;		// 16MB
sl@0
    35
    
sl@0
    36
// ================= MEMBER FUNCTIONS =======================
sl@0
    37
sl@0
    38
// C++ default constructor can NOT contain any code, that
sl@0
    39
// might leave.
sl@0
    40
//
sl@0
    41
CTelephonyAudioRoutingManager::CTelephonyAudioRoutingManager(
sl@0
    42
	MTelephonyAudioRoutingPolicyObserver& aObserver)
sl@0
    43
	: iObserver(aObserver)
sl@0
    44
    {
sl@0
    45
    }
sl@0
    46
    
sl@0
    47
    
sl@0
    48
// -----------------------------------------------------------------------------
sl@0
    49
// CAudioOutputProxy::ConstructL
sl@0
    50
// Symbian 2nd phase constructor can leave.
sl@0
    51
// -----------------------------------------------------------------------------
sl@0
    52
//
sl@0
    53
void CTelephonyAudioRoutingManager::ConstructL(
sl@0
    54
const TArray<CTelephonyAudioRouting::TAudioOutput>& aArray)
sl@0
    55
	{
sl@0
    56
	TELAUDRTNG_RDEBUG(_L("[TELAUDRTNG]\t CTelephonyAudioRoutingManager::ConstructL "));
sl@0
    57
sl@0
    58
	User::LeaveIfError(StartServer());
sl@0
    59
	iMgrSession = new (ELeave)RTelephonyAudioRoutingManagerSession;
sl@0
    60
	User::LeaveIfError(iMgrSession->Connect(*this, iObserver));
sl@0
    61
	
sl@0
    62
	iMgrSession->SetPolicySessionIdL();	
sl@0
    63
	iMgrSession->MonitorOutputChangeRequest();
sl@0
    64
	iMgrSession->AvailableOutputsChangedL(aArray); 
sl@0
    65
	
sl@0
    66
	}
sl@0
    67
sl@0
    68
// Two-phased constructor.
sl@0
    69
EXPORT_C CTelephonyAudioRoutingManager* CTelephonyAudioRoutingManager::NewL(
sl@0
    70
MTelephonyAudioRoutingPolicyObserver& aObserver,
sl@0
    71
const TArray<CTelephonyAudioRouting::TAudioOutput>& aArray)
sl@0
    72
    {
sl@0
    73
	CTelephonyAudioRoutingManager* self = new(ELeave) CTelephonyAudioRoutingManager(aObserver);
sl@0
    74
	CleanupStack::PushL(self);
sl@0
    75
	self->ConstructL(aArray);
sl@0
    76
	CleanupStack::Pop(self);
sl@0
    77
	return self;
sl@0
    78
    }
sl@0
    79
sl@0
    80
sl@0
    81
// Destructor
sl@0
    82
CTelephonyAudioRoutingManager::~CTelephonyAudioRoutingManager()
sl@0
    83
    { 
sl@0
    84
	TELAUDRTNG_RDEBUG(_L("[TELAUDRTNG]\t CTelephonyAudioRoutingManager::~CTelephonyAudioRoutingManager "));    
sl@0
    85
    if (iMgrSession) 
sl@0
    86
        {
sl@0
    87
        iMgrSession->Close();        
sl@0
    88
        }
sl@0
    89
    delete iMgrSession;
sl@0
    90
    iServer.Close();
sl@0
    91
    }
sl@0
    92
sl@0
    93
// ---------------------------------------------------------
sl@0
    94
// CAudioOutput::OutputChanged
sl@0
    95
// Policy is sending out notification that the output has changed 
sl@0
    96
// (a change initiated by policy)
sl@0
    97
// (other items were commented in a header).
sl@0
    98
// ---------------------------------------------------------
sl@0
    99
//
sl@0
   100
sl@0
   101
EXPORT_C void CTelephonyAudioRoutingManager::OutputChanged(CTelephonyAudioRouting::TAudioOutput aOutput)
sl@0
   102
	{
sl@0
   103
	TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t CTelephonyAudioRoutingManager::OutputChanged to: %d"), aOutput);	
sl@0
   104
    iMgrSession->OutputChanged(aOutput);
sl@0
   105
	}
sl@0
   106
	
sl@0
   107
// ---------------------------------------------------------
sl@0
   108
// CAudioOutput::AvailableOutputsChanged
sl@0
   109
// Policy is sending out notification that the available outputs have changed
sl@0
   110
// (other items were commented in a header).
sl@0
   111
// ---------------------------------------------------------
sl@0
   112
//
sl@0
   113
	
sl@0
   114
EXPORT_C void CTelephonyAudioRoutingManager::AvailableOutputsChanged(const TArray<CTelephonyAudioRouting::TAudioOutput>& aArray)
sl@0
   115
	{
sl@0
   116
	TELAUDRTNG_RDEBUG(_L("[TELAUDRTNG]\t CTelephonyAudioRoutingManager::AvailableOutputsChanged "));
sl@0
   117
    TRAPD(err,iMgrSession->AvailableOutputsChangedL(aArray));
sl@0
   118
   	if (err != KErrNone)
sl@0
   119
		{
sl@0
   120
		TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t CTelephonyAudioRoutingManager::AvailableOutputsChanged: ERROR from Adaptation: %d "), err);			
sl@0
   121
		}		
sl@0
   122
	}
sl@0
   123
	
sl@0
   124
// ---------------------------------------------------------
sl@0
   125
// CAudioOutput::OutputChangeRequestCompleted
sl@0
   126
// Policy is sending out notification that the request change in output has been completed
sl@0
   127
// (other items were commented in a header).
sl@0
   128
// ---------------------------------------------------------
sl@0
   129
//	
sl@0
   130
EXPORT_C void CTelephonyAudioRoutingManager::OutputChangeRequestCompleted(CTelephonyAudioRouting::TAudioOutput aOutput, TInt aError)
sl@0
   131
	{
sl@0
   132
	TELAUDRTNG_RDEBUG(_L("[TELAUDRTNG]\t CTelephonyAudioRoutingManager::OutputChangeRequestCompleted "));	
sl@0
   133
	if (aError != KErrNone)
sl@0
   134
	{
sl@0
   135
		TELAUDRTNG_RDEBUG1(_L("[TELAUDRTNG]\t CTelephonyAudioRoutingManager::OutputChangeRequestCompleted: ERROR from Adaptation: %d "), aError);			
sl@0
   136
	}
sl@0
   137
sl@0
   138
    iMgrSession->OutputChangeCompleted(aOutput, aError);
sl@0
   139
	}
sl@0
   140
	
sl@0
   141
		
sl@0
   142
// -----------------------------------------------------------------------------
sl@0
   143
// CStartTelephonyAudioRoutingServer::StartServer
sl@0
   144
// Start TelephonyAudioRouting Server
sl@0
   145
// (other items were commented in a header).
sl@0
   146
// -----------------------------------------------------------------------------
sl@0
   147
//	
sl@0
   148
TInt CTelephonyAudioRoutingManager::StartServer()                                                                        
sl@0
   149
    {       
sl@0
   150
    TELAUDRTNG_RDEBUG(_L("[TELAUDRTNG]\t CTelephonyAudioRoutingManager::StartServer "));
sl@0
   151
    	
sl@0
   152
	const TUidType serverUid(KNullUid,KNullUid,KTelAudRtngServerUid);
sl@0
   153
		
sl@0
   154
	TThreadFunction serverFunc=CTelephonyAudioRoutingServer::StartThreadL;
sl@0
   155
	
sl@0
   156
	TInt err(KErrNone);
sl@0
   157
	TName name(KTelAudRtngServName);
sl@0
   158
			
sl@0
   159
	err = iServer.Create(name, serverFunc, KTelAudRtngServerStackSize,
sl@0
   160
	        	KTelAudRtngServerInitHeapSize, KTelAudRtngServerMaxHeapSize,
sl@0
   161
	        	/*&start*/ NULL, EOwnerProcess);
sl@0
   162
				
sl@0
   163
sl@0
   164
	if(err != KErrNone)
sl@0
   165
		return err;
sl@0
   166
	// Synchronise with the server
sl@0
   167
	TRequestStatus reqStatus;
sl@0
   168
	iServer.Rendezvous(reqStatus);
sl@0
   169
	
sl@0
   170
	if (reqStatus!=KRequestPending)
sl@0
   171
		{
sl@0
   172
		iServer.Kill(0);
sl@0
   173
		}
sl@0
   174
	else
sl@0
   175
		{
sl@0
   176
		// Start the test harness
sl@0
   177
		iServer.Resume();
sl@0
   178
		// Server will call the reciprocal static synchronise call	
sl@0
   179
		}
sl@0
   180
sl@0
   181
	User::WaitForRequest(reqStatus); // wait for start or death
sl@0
   182
	if(reqStatus.Int() != KErrNone)
sl@0
   183
		{
sl@0
   184
		iServer.Close();
sl@0
   185
		return reqStatus.Int();
sl@0
   186
		}
sl@0
   187
		
sl@0
   188
	return KErrNone;
sl@0
   189
   	                                                                    
sl@0
   190
    }    
sl@0
   191
sl@0
   192
// End of File