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