os/mm/devsound/sounddevbt/src/SoundDevice/MmfBtDevSoundEventHandler.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
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "MmfBtDevSoundEventHandler.h"
sl@0
    17
#include "MmfBtAudioPolicyProxy.h"
sl@0
    18
sl@0
    19
#include "MmfBtDevSoundSessionXtnd.h"
sl@0
    20
sl@0
    21
CMMFDevSoundEventHandler* CMMFDevSoundEventHandler::NewL(RMMFAudioPolicyProxy* aAudioPolicyProxy)
sl@0
    22
	{
sl@0
    23
	CMMFDevSoundEventHandler* self = new(ELeave) CMMFDevSoundEventHandler(aAudioPolicyProxy);
sl@0
    24
	CleanupStack::PushL(self);
sl@0
    25
	self->ConstructL();
sl@0
    26
	CleanupStack::Pop();
sl@0
    27
	return self;
sl@0
    28
	}
sl@0
    29
sl@0
    30
CMMFDevSoundEventHandler::CMMFDevSoundEventHandler(RMMFAudioPolicyProxy* aAudioPolicyProxy) :
sl@0
    31
	CActive(EPriorityLow), iAudioPolicyProxy(aAudioPolicyProxy)
sl@0
    32
	{
sl@0
    33
	CActiveScheduler::Add(this);
sl@0
    34
	}
sl@0
    35
sl@0
    36
void CMMFDevSoundEventHandler::ConstructL()
sl@0
    37
	{
sl@0
    38
	}
sl@0
    39
sl@0
    40
void CMMFDevSoundEventHandler::SetDevSoundInfo(CMMFDevSoundSessionXtnd* aDevSound)
sl@0
    41
	{
sl@0
    42
	iDevSound = aDevSound;
sl@0
    43
	iDevSoundId++;
sl@0
    44
	aDevSound->SetDevSoundId(iDevSoundId);
sl@0
    45
	}
sl@0
    46
sl@0
    47
CMMFDevSoundEventHandler::~CMMFDevSoundEventHandler()
sl@0
    48
	{
sl@0
    49
	Cancel();
sl@0
    50
	}
sl@0
    51
sl@0
    52
void CMMFDevSoundEventHandler::ReceiveEvents()
sl@0
    53
	{
sl@0
    54
	iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
sl@0
    55
	SetActive();
sl@0
    56
	}
sl@0
    57
sl@0
    58
void CMMFDevSoundEventHandler::CancelReceiveEvents()
sl@0
    59
	{
sl@0
    60
	Cancel();
sl@0
    61
	}
sl@0
    62
sl@0
    63
void CMMFDevSoundEventHandler::RunL()
sl@0
    64
	{
sl@0
    65
	TMMFAudioPolicyEvent aEvent;
sl@0
    66
	aEvent.iEventType = iAudioPolicyEventPckg().iEventType;
sl@0
    67
	aEvent.iErrorCode = iAudioPolicyEventPckg().iErrorCode;
sl@0
    68
	aEvent.iState = iAudioPolicyEventPckg().iState;
sl@0
    69
sl@0
    70
	// Determine whether or not to call on client to send event or call on other
sl@0
    71
	// SoundDevice's to start play/record functions:
sl@0
    72
	if ( (aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicySwitchToIdle)
sl@0
    73
		 || (aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicyNoEvent) )
sl@0
    74
		{
sl@0
    75
		// Determine what to do, based on state:
sl@0
    76
		switch (aEvent.iState)
sl@0
    77
			{
sl@0
    78
		case EMMFStatePlayData:
sl@0
    79
			iDevSound->StartPlayDataL();
sl@0
    80
			break;
sl@0
    81
		case EMMFStateRecordData:
sl@0
    82
			iDevSound->StartRecordDataL();
sl@0
    83
			break;
sl@0
    84
		case EMMFStatePlayTone:
sl@0
    85
			iDevSound->StartPlayToneL();
sl@0
    86
			break;
sl@0
    87
		case EMMFStatePlayDualTone:
sl@0
    88
			iDevSound->StartPlayDualToneL();
sl@0
    89
			break;
sl@0
    90
		case EMMFStatePlayDTMFString:
sl@0
    91
			iDevSound->StartPlayDTMFStringL();
sl@0
    92
			break;
sl@0
    93
		case EMMFStatePlayToneSequence:
sl@0
    94
			iDevSound->StartPlayToneSequenceL();
sl@0
    95
			break;
sl@0
    96
		default:
sl@0
    97
			break;
sl@0
    98
			}  // End switch
sl@0
    99
		// Set self up to receive more events:
sl@0
   100
		iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
sl@0
   101
		SetActive();
sl@0
   102
		}
sl@0
   103
	else if(aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification)	
sl@0
   104
		{
sl@0
   105
		TMMFEvent event;
sl@0
   106
		event.iErrorCode = aEvent.iErrorCode;
sl@0
   107
		event.iEventType = KMMFEventCategoryAudioResourceAvailable;
sl@0
   108
		iDevSound->SendEvent(event);
sl@0
   109
		}
sl@0
   110
	else
sl@0
   111
		{
sl@0
   112
		//Create a TMMFEvent element for client:
sl@0
   113
		//NB KErrInUse, KErrDied OR KErrAccessDenied may be returned by the 
sl@0
   114
		//policy server to indicate that the sound device is in use by another 
sl@0
   115
		//higher priority client.
sl@0
   116
		TMMFEvent event;
sl@0
   117
		event.iErrorCode = aEvent.iErrorCode;
sl@0
   118
		iDevSound->SendEvent(event);
sl@0
   119
		if(!iAudioPolicyProxy->IsRegisteredResourceNotification(KMMFEventCategoryAudioResourceAvailable))
sl@0
   120
			{
sl@0
   121
			iAudioPolicyEventPckg().iEventType = TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification;
sl@0
   122
			iAudioPolicyEventPckg().iErrorCode = 0;
sl@0
   123
			iAudioPolicyEventPckg().iState = EMMFStateNotified;
sl@0
   124
			iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
sl@0
   125
			SetActive();
sl@0
   126
			}
sl@0
   127
		}
sl@0
   128
	}
sl@0
   129
sl@0
   130
void CMMFDevSoundEventHandler::DoCancel()
sl@0
   131
	{
sl@0
   132
	iAudioPolicyProxy->CancelReceiveEvents();
sl@0
   133
	}
sl@0
   134
sl@0
   135
TInt CMMFDevSoundEventHandler::RunError(TInt aError)
sl@0
   136
	{
sl@0
   137
	TMMFEvent event;
sl@0
   138
	event.iErrorCode = aError;//should probably have an appropriate event type here too?
sl@0
   139
	iDevSound->SendEventToClient(event);
sl@0
   140
	return KErrNone;
sl@0
   141
	}