First public contribution.
1 // Copyright (c) 2000-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include "MmfBtAudioPolicyServer.h"
18 #include "MmfBtAudioPolicyStart.h"
19 #include "MmfBtAudioPolicySession.h"
21 const TInt KTimeOutInterval = 1000000;
23 CMMFAudioPolicyServer* CMMFAudioPolicyServer::NewL()
25 CMMFAudioPolicyServer* s = new(ELeave) CMMFAudioPolicyServer();
26 CleanupStack::PushL(s);
32 CMMFAudioPolicyServer::CMMFAudioPolicyServer() :
33 CMmfIpcServer(EPriorityStandard)
37 void CMMFAudioPolicyServer::ConstructL()
39 // Create AudioPolicy singleton
40 iAudioPolicy = CAudioPolicy::NewL(this);
41 TCallBack callBack(SendNotification,this);
42 iNotificationTimer = CNotificationTimer::NewL(callBack);
43 // Call base class to Start server
47 CMMFAudioPolicyServer::~CMMFAudioPolicyServer()
49 if(iNotificationTimer != NULL)
51 StopNotificationTimer();
54 delete iNotificationTimer;
57 CMmfIpcSession* CMMFAudioPolicyServer::NewSessionL(const TVersion& aVersion) const
59 TVersion v(KMMFAudioPolicyVersion,KMMFAudioPolicyMinorVersionNumber,KMMFAudioPolicyBuildVersionNumber);
60 if(!User::QueryVersionSupported(v, aVersion))
61 User::Leave(KErrNotSupported);
63 CMMFAudioPolicySession* aAudioPolicySession = CMMFAudioPolicySession::NewL();
64 return aAudioPolicySession;
67 void CMMFAudioPolicyServer::IncrementSessionId()
72 void CMMFAudioPolicyServer::SendEventToClient(TInt aSessionToAlert, TInt /*aSessionToBeLaunched*/, TMMFAudioPolicyEvent& aEvent)
74 TMMFAudioPolicyEvent eventForClient;
75 eventForClient.iEventType = aEvent.iEventType;
76 eventForClient.iErrorCode = aEvent.iErrorCode;
77 eventForClient.iState = aEvent.iState;
79 // For the session requested, send event to client
80 iSessionIter.SetToFirst();
81 CMMFAudioPolicySession* session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
82 while (session != NULL)
84 if (session->PolicySessionId() == aSessionToAlert)
86 session->SendEventToClient(eventForClient);
89 session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
93 void CMMFAudioPolicyServer::LaunchRequest(TInt aSessionId, TMMFAudioPolicyEvent& aEvent)
95 iSessionIter.SetToFirst();
96 CMMFAudioPolicySession* session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
97 while (session != NULL)
99 if (session->PolicySessionId() == aSessionId)
101 session->SendEventToClient(aEvent);
104 session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
108 void CMMFAudioPolicyServer::IncrementSessionCount()
110 iPolicySessionCount++;
113 CMMFAudioPolicyServer::CNotificationTimer *CMMFAudioPolicyServer::CNotificationTimer::NewL(TCallBack aCallBack)
115 CNotificationTimer* self = new(ELeave) CNotificationTimer(aCallBack);
116 CleanupStack::PushL(self);
118 CleanupStack::Pop(); // self
122 CMMFAudioPolicyServer::CNotificationTimer::CNotificationTimer(TCallBack aCallBack)
123 : CTimer(EPriorityHigh),iCallBack(aCallBack)
125 CActiveScheduler::Add(this);
128 void CMMFAudioPolicyServer::CNotificationTimer::RunL()
130 iCallBack.CallBack();
133 void CMMFAudioPolicyServer::DecrementSessionCount()
135 iPolicySessionCount--;
138 TInt CMMFAudioPolicyServer::PolicySessionCount()
140 return iPolicySessionCount;
143 void CMMFAudioPolicyServer::StartNotificationTimer()
145 iNotificationTimer->After(KTimeOutInterval);
148 void CMMFAudioPolicyServer::StopNotificationTimer()
150 iNotificationTimer->Cancel();
153 TInt CMMFAudioPolicyServer::SendNotification(TAny* aAny)
155 CMMFAudioPolicyServer* policyServer = reinterpret_cast<CMMFAudioPolicyServer*>(aAny);
156 policyServer->iAudioPolicy->DoSendNotification();
160 TBool CMMFAudioPolicyServer::IsTimerActive() const
162 return iNotificationTimer->IsActive();