os/mm/devsound/sounddevbt/src/SoundDevice/MmfBtDevSoundEventHandler.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsound/sounddevbt/src/SoundDevice/MmfBtDevSoundEventHandler.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,141 @@
     1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "MmfBtDevSoundEventHandler.h"
    1.20 +#include "MmfBtAudioPolicyProxy.h"
    1.21 +
    1.22 +#include "MmfBtDevSoundSessionXtnd.h"
    1.23 +
    1.24 +CMMFDevSoundEventHandler* CMMFDevSoundEventHandler::NewL(RMMFAudioPolicyProxy* aAudioPolicyProxy)
    1.25 +	{
    1.26 +	CMMFDevSoundEventHandler* self = new(ELeave) CMMFDevSoundEventHandler(aAudioPolicyProxy);
    1.27 +	CleanupStack::PushL(self);
    1.28 +	self->ConstructL();
    1.29 +	CleanupStack::Pop();
    1.30 +	return self;
    1.31 +	}
    1.32 +
    1.33 +CMMFDevSoundEventHandler::CMMFDevSoundEventHandler(RMMFAudioPolicyProxy* aAudioPolicyProxy) :
    1.34 +	CActive(EPriorityLow), iAudioPolicyProxy(aAudioPolicyProxy)
    1.35 +	{
    1.36 +	CActiveScheduler::Add(this);
    1.37 +	}
    1.38 +
    1.39 +void CMMFDevSoundEventHandler::ConstructL()
    1.40 +	{
    1.41 +	}
    1.42 +
    1.43 +void CMMFDevSoundEventHandler::SetDevSoundInfo(CMMFDevSoundSessionXtnd* aDevSound)
    1.44 +	{
    1.45 +	iDevSound = aDevSound;
    1.46 +	iDevSoundId++;
    1.47 +	aDevSound->SetDevSoundId(iDevSoundId);
    1.48 +	}
    1.49 +
    1.50 +CMMFDevSoundEventHandler::~CMMFDevSoundEventHandler()
    1.51 +	{
    1.52 +	Cancel();
    1.53 +	}
    1.54 +
    1.55 +void CMMFDevSoundEventHandler::ReceiveEvents()
    1.56 +	{
    1.57 +	iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
    1.58 +	SetActive();
    1.59 +	}
    1.60 +
    1.61 +void CMMFDevSoundEventHandler::CancelReceiveEvents()
    1.62 +	{
    1.63 +	Cancel();
    1.64 +	}
    1.65 +
    1.66 +void CMMFDevSoundEventHandler::RunL()
    1.67 +	{
    1.68 +	TMMFAudioPolicyEvent aEvent;
    1.69 +	aEvent.iEventType = iAudioPolicyEventPckg().iEventType;
    1.70 +	aEvent.iErrorCode = iAudioPolicyEventPckg().iErrorCode;
    1.71 +	aEvent.iState = iAudioPolicyEventPckg().iState;
    1.72 +
    1.73 +	// Determine whether or not to call on client to send event or call on other
    1.74 +	// SoundDevice's to start play/record functions:
    1.75 +	if ( (aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicySwitchToIdle)
    1.76 +		 || (aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicyNoEvent) )
    1.77 +		{
    1.78 +		// Determine what to do, based on state:
    1.79 +		switch (aEvent.iState)
    1.80 +			{
    1.81 +		case EMMFStatePlayData:
    1.82 +			iDevSound->StartPlayDataL();
    1.83 +			break;
    1.84 +		case EMMFStateRecordData:
    1.85 +			iDevSound->StartRecordDataL();
    1.86 +			break;
    1.87 +		case EMMFStatePlayTone:
    1.88 +			iDevSound->StartPlayToneL();
    1.89 +			break;
    1.90 +		case EMMFStatePlayDualTone:
    1.91 +			iDevSound->StartPlayDualToneL();
    1.92 +			break;
    1.93 +		case EMMFStatePlayDTMFString:
    1.94 +			iDevSound->StartPlayDTMFStringL();
    1.95 +			break;
    1.96 +		case EMMFStatePlayToneSequence:
    1.97 +			iDevSound->StartPlayToneSequenceL();
    1.98 +			break;
    1.99 +		default:
   1.100 +			break;
   1.101 +			}  // End switch
   1.102 +		// Set self up to receive more events:
   1.103 +		iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
   1.104 +		SetActive();
   1.105 +		}
   1.106 +	else if(aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification)	
   1.107 +		{
   1.108 +		TMMFEvent event;
   1.109 +		event.iErrorCode = aEvent.iErrorCode;
   1.110 +		event.iEventType = KMMFEventCategoryAudioResourceAvailable;
   1.111 +		iDevSound->SendEvent(event);
   1.112 +		}
   1.113 +	else
   1.114 +		{
   1.115 +		//Create a TMMFEvent element for client:
   1.116 +		//NB KErrInUse, KErrDied OR KErrAccessDenied may be returned by the 
   1.117 +		//policy server to indicate that the sound device is in use by another 
   1.118 +		//higher priority client.
   1.119 +		TMMFEvent event;
   1.120 +		event.iErrorCode = aEvent.iErrorCode;
   1.121 +		iDevSound->SendEvent(event);
   1.122 +		if(!iAudioPolicyProxy->IsRegisteredResourceNotification(KMMFEventCategoryAudioResourceAvailable))
   1.123 +			{
   1.124 +			iAudioPolicyEventPckg().iEventType = TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification;
   1.125 +			iAudioPolicyEventPckg().iErrorCode = 0;
   1.126 +			iAudioPolicyEventPckg().iState = EMMFStateNotified;
   1.127 +			iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
   1.128 +			SetActive();
   1.129 +			}
   1.130 +		}
   1.131 +	}
   1.132 +
   1.133 +void CMMFDevSoundEventHandler::DoCancel()
   1.134 +	{
   1.135 +	iAudioPolicyProxy->CancelReceiveEvents();
   1.136 +	}
   1.137 +
   1.138 +TInt CMMFDevSoundEventHandler::RunError(TInt aError)
   1.139 +	{
   1.140 +	TMMFEvent event;
   1.141 +	event.iErrorCode = aError;//should probably have an appropriate event type here too?
   1.142 +	iDevSound->SendEventToClient(event);
   1.143 +	return KErrNone;
   1.144 +	}