os/mm/devsound/sounddevbt/src/server/Policy/MmfBtAudioPolicyServer.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsound/sounddevbt/src/server/Policy/MmfBtAudioPolicyServer.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,163 @@
     1.4 +// Copyright (c) 2000-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 <e32math.h>
    1.20 +#include "MmfBtAudioPolicyServer.h"
    1.21 +#include "MmfBtAudioPolicyStart.h"
    1.22 +#include "MmfBtAudioPolicySession.h"
    1.23 +
    1.24 +const TInt KTimeOutInterval = 1000000;
    1.25 +
    1.26 +CMMFAudioPolicyServer* CMMFAudioPolicyServer::NewL()
    1.27 +	{
    1.28 +	CMMFAudioPolicyServer* s = new(ELeave) CMMFAudioPolicyServer();
    1.29 +	CleanupStack::PushL(s);
    1.30 +	s->ConstructL();
    1.31 +	CleanupStack::Pop();
    1.32 +	return s;
    1.33 +	}
    1.34 +
    1.35 +CMMFAudioPolicyServer::CMMFAudioPolicyServer() :
    1.36 +	CMmfIpcServer(EPriorityStandard)
    1.37 +	{
    1.38 +	}
    1.39 +
    1.40 +void CMMFAudioPolicyServer::ConstructL()
    1.41 +	{
    1.42 +	// Create AudioPolicy singleton
    1.43 +	iAudioPolicy = CAudioPolicy::NewL(this);
    1.44 +	TCallBack callBack(SendNotification,this);
    1.45 +	iNotificationTimer = CNotificationTimer::NewL(callBack);
    1.46 +	// Call base class to Start server
    1.47 +	StartL(KNullDesC);
    1.48 +	}
    1.49 +
    1.50 +CMMFAudioPolicyServer::~CMMFAudioPolicyServer()
    1.51 +	{
    1.52 +	if(iNotificationTimer != NULL)
    1.53 +		{
    1.54 +		StopNotificationTimer();
    1.55 +		}
    1.56 +	delete iAudioPolicy;
    1.57 +	delete iNotificationTimer;
    1.58 +	}
    1.59 +
    1.60 +CMmfIpcSession* CMMFAudioPolicyServer::NewSessionL(const TVersion& aVersion) const
    1.61 +	{
    1.62 +	TVersion v(KMMFAudioPolicyVersion,KMMFAudioPolicyMinorVersionNumber,KMMFAudioPolicyBuildVersionNumber);
    1.63 +	if(!User::QueryVersionSupported(v, aVersion))
    1.64 +		User::Leave(KErrNotSupported);
    1.65 +	
    1.66 +	CMMFAudioPolicySession* aAudioPolicySession = CMMFAudioPolicySession::NewL();
    1.67 +	return aAudioPolicySession;
    1.68 +	}
    1.69 +
    1.70 +void CMMFAudioPolicyServer::IncrementSessionId()
    1.71 +	{
    1.72 +	iPolicySessionId++;
    1.73 +	}
    1.74 +
    1.75 +void CMMFAudioPolicyServer::SendEventToClient(TInt aSessionToAlert, TInt /*aSessionToBeLaunched*/, TMMFAudioPolicyEvent& aEvent)
    1.76 +	{
    1.77 +	TMMFAudioPolicyEvent eventForClient;
    1.78 +	eventForClient.iEventType = aEvent.iEventType;
    1.79 +	eventForClient.iErrorCode = aEvent.iErrorCode;
    1.80 +	eventForClient.iState = aEvent.iState;
    1.81 +
    1.82 +	// For the session requested, send event to client
    1.83 +	iSessionIter.SetToFirst();
    1.84 +	CMMFAudioPolicySession* session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
    1.85 +	while (session != NULL)
    1.86 +		{
    1.87 +		if (session->PolicySessionId() == aSessionToAlert)
    1.88 +			{
    1.89 +			session->SendEventToClient(eventForClient);
    1.90 +			break;  // Finished
    1.91 +			}
    1.92 +		session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
    1.93 +		}
    1.94 +	}
    1.95 +	
    1.96 +void CMMFAudioPolicyServer::LaunchRequest(TInt aSessionId, TMMFAudioPolicyEvent& aEvent)
    1.97 +	{
    1.98 +	iSessionIter.SetToFirst();
    1.99 +	CMMFAudioPolicySession* session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
   1.100 +	while (session != NULL)
   1.101 +		{
   1.102 +		if (session->PolicySessionId() == aSessionId)
   1.103 +			{
   1.104 +			session->SendEventToClient(aEvent);
   1.105 +			break;  // Finished
   1.106 +			}
   1.107 +		session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
   1.108 +		}
   1.109 +	}
   1.110 +
   1.111 +void CMMFAudioPolicyServer::IncrementSessionCount()
   1.112 +	{
   1.113 +	iPolicySessionCount++;
   1.114 +	}
   1.115 +
   1.116 +CMMFAudioPolicyServer::CNotificationTimer *CMMFAudioPolicyServer::CNotificationTimer::NewL(TCallBack aCallBack)	
   1.117 +	{
   1.118 +	CNotificationTimer* self = new(ELeave) CNotificationTimer(aCallBack);
   1.119 +	CleanupStack::PushL(self);
   1.120 +	self->ConstructL();
   1.121 +	CleanupStack::Pop(); // self
   1.122 +	return self;
   1.123 +	}
   1.124 +
   1.125 +CMMFAudioPolicyServer::CNotificationTimer::CNotificationTimer(TCallBack aCallBack)
   1.126 +: CTimer(EPriorityHigh),iCallBack(aCallBack)
   1.127 +	{
   1.128 +	CActiveScheduler::Add(this);
   1.129 +	}
   1.130 +
   1.131 +void CMMFAudioPolicyServer::CNotificationTimer::RunL()
   1.132 +	{
   1.133 +	iCallBack.CallBack();
   1.134 +	}
   1.135 +
   1.136 +void CMMFAudioPolicyServer::DecrementSessionCount()
   1.137 +	{
   1.138 +	iPolicySessionCount--;
   1.139 +	}
   1.140 +
   1.141 +TInt CMMFAudioPolicyServer::PolicySessionCount() 
   1.142 +	{
   1.143 +	return iPolicySessionCount;
   1.144 +	}
   1.145 +
   1.146 +void CMMFAudioPolicyServer::StartNotificationTimer()
   1.147 +	{
   1.148 +	iNotificationTimer->After(KTimeOutInterval);
   1.149 +	}
   1.150 +	
   1.151 +void CMMFAudioPolicyServer::StopNotificationTimer()
   1.152 +	{
   1.153 +	iNotificationTimer->Cancel();			
   1.154 +	}
   1.155 +
   1.156 +TInt CMMFAudioPolicyServer::SendNotification(TAny* aAny)
   1.157 +	{
   1.158 +	CMMFAudioPolicyServer* policyServer = reinterpret_cast<CMMFAudioPolicyServer*>(aAny);
   1.159 +	policyServer->iAudioPolicy->DoSendNotification();
   1.160 +	return KErrNone;
   1.161 +	}
   1.162 +
   1.163 +TBool CMMFAudioPolicyServer::IsTimerActive() const 
   1.164 +	{
   1.165 +	return iNotificationTimer->IsActive();
   1.166 +	}