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