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