os/mm/devsound/sounddevbt/src/SoundDevice/MmfBtDevSoundEventHandler.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-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 "MmfBtDevSoundEventHandler.h"
    17 #include "MmfBtAudioPolicyProxy.h"
    18 
    19 #include "MmfBtDevSoundSessionXtnd.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 			break;
    98 			}  // End switch
    99 		// Set self up to receive more events:
   100 		iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
   101 		SetActive();
   102 		}
   103 	else if(aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification)	
   104 		{
   105 		TMMFEvent event;
   106 		event.iErrorCode = aEvent.iErrorCode;
   107 		event.iEventType = KMMFEventCategoryAudioResourceAvailable;
   108 		iDevSound->SendEvent(event);
   109 		}
   110 	else
   111 		{
   112 		//Create a TMMFEvent element for client:
   113 		//NB KErrInUse, KErrDied OR KErrAccessDenied may be returned by the 
   114 		//policy server to indicate that the sound device is in use by another 
   115 		//higher priority client.
   116 		TMMFEvent event;
   117 		event.iErrorCode = aEvent.iErrorCode;
   118 		iDevSound->SendEvent(event);
   119 		if(!iAudioPolicyProxy->IsRegisteredResourceNotification(KMMFEventCategoryAudioResourceAvailable))
   120 			{
   121 			iAudioPolicyEventPckg().iEventType = TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification;
   122 			iAudioPolicyEventPckg().iErrorCode = 0;
   123 			iAudioPolicyEventPckg().iState = EMMFStateNotified;
   124 			iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
   125 			SetActive();
   126 			}
   127 		}
   128 	}
   129 
   130 void CMMFDevSoundEventHandler::DoCancel()
   131 	{
   132 	iAudioPolicyProxy->CancelReceiveEvents();
   133 	}
   134 
   135 TInt CMMFDevSoundEventHandler::RunError(TInt aError)
   136 	{
   137 	TMMFEvent event;
   138 	event.iErrorCode = aError;//should probably have an appropriate event type here too?
   139 	iDevSound->SendEventToClient(event);
   140 	return KErrNone;
   141 	}