|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32math.h> |
|
17 #include "MmfAudioPolicyServer.h" |
|
18 #include "MmfAudioPolicyStart.h" |
|
19 #include "MmfAudioPolicySession.h" |
|
20 |
|
21 |
|
22 #if defined(_DEBUG) && defined(__WINS__) |
|
23 const TInt KTimeOutInterval =2*1000000; // 2 seconds |
|
24 #else |
|
25 const TInt KTimeOutInterval =1000000; // 1 second |
|
26 #endif |
|
27 |
|
28 CMMFAudioPolicyServer* CMMFAudioPolicyServer::NewL() |
|
29 { |
|
30 CMMFAudioPolicyServer* s = new(ELeave) CMMFAudioPolicyServer(); |
|
31 CleanupStack::PushL(s); |
|
32 s->ConstructL(); |
|
33 CleanupStack::Pop(); |
|
34 return s; |
|
35 } |
|
36 |
|
37 CMMFAudioPolicyServer::CMMFAudioPolicyServer() : |
|
38 CMmfIpcServer(EPriorityStandard) |
|
39 { |
|
40 } |
|
41 |
|
42 void CMMFAudioPolicyServer::ConstructL() |
|
43 { |
|
44 // Create AudioPolicy singleton |
|
45 iAudioPolicy = CAudioPolicy::NewL(this); |
|
46 TCallBack callBack(SendNotification,this); |
|
47 iNotificationTimer = CNotificationTimer::NewL(callBack); |
|
48 // Call base class to Start server |
|
49 StartL(KNullDesC); |
|
50 } |
|
51 |
|
52 CMMFAudioPolicyServer::~CMMFAudioPolicyServer() |
|
53 { |
|
54 if(iNotificationTimer != NULL) |
|
55 { |
|
56 StopNotificationTimer(); |
|
57 } |
|
58 delete iAudioPolicy; |
|
59 delete iNotificationTimer; |
|
60 } |
|
61 |
|
62 CMmfIpcSession* CMMFAudioPolicyServer::NewSessionL(const TVersion& aVersion) const |
|
63 { |
|
64 TVersion v(KMMFAudioPolicyVersion,KMMFAudioPolicyMinorVersionNumber,KMMFAudioPolicyBuildVersionNumber); |
|
65 if(!User::QueryVersionSupported(v, aVersion)) |
|
66 User::Leave(KErrNotSupported); |
|
67 |
|
68 CMMFAudioPolicySession* aAudioPolicySession = CMMFAudioPolicySession::NewL(); |
|
69 return aAudioPolicySession; |
|
70 } |
|
71 |
|
72 void CMMFAudioPolicyServer::IncrementSessionId() |
|
73 { |
|
74 iPolicySessionId++; |
|
75 } |
|
76 |
|
77 void CMMFAudioPolicyServer::SendEventToClient(TInt aSessionToAlert, const TMMFAudioPolicyEvent& aEvent) |
|
78 { |
|
79 // For the session requested, send event to client |
|
80 iSessionIter.SetToFirst(); |
|
81 CMMFAudioPolicySession* session = static_cast<CMMFAudioPolicySession*>(iSessionIter++); |
|
82 ASSERT(session != NULL); |
|
83 do |
|
84 { |
|
85 if (session->PolicySessionId() == aSessionToAlert) |
|
86 { |
|
87 session->SendEventToClient(aEvent); |
|
88 return; // Finished |
|
89 } |
|
90 session = static_cast<CMMFAudioPolicySession*>(iSessionIter++); |
|
91 } while (session != NULL); |
|
92 ASSERT(EFalse); // invalid session Id |
|
93 } |
|
94 |
|
95 void CMMFAudioPolicyServer::LaunchRequest(TInt aSessionId,const TMMFAudioPolicyEvent& aEvent) |
|
96 { |
|
97 SendEventToClient(aSessionId, aEvent); |
|
98 } |
|
99 |
|
100 void CMMFAudioPolicyServer::IncrementSessionCount() |
|
101 { |
|
102 iPolicySessionCount++; |
|
103 } |
|
104 |
|
105 CMMFAudioPolicyServer::CNotificationTimer *CMMFAudioPolicyServer::CNotificationTimer::NewL(TCallBack aCallBack) |
|
106 { |
|
107 CNotificationTimer* self = new(ELeave) CNotificationTimer(aCallBack); |
|
108 CleanupStack::PushL(self); |
|
109 self->ConstructL(); |
|
110 CleanupStack::Pop(); // self |
|
111 return self; |
|
112 } |
|
113 |
|
114 CMMFAudioPolicyServer::CNotificationTimer::CNotificationTimer(TCallBack aCallBack) |
|
115 : CTimer(EPriorityHigh),iCallBack(aCallBack) |
|
116 { |
|
117 CActiveScheduler::Add(this); |
|
118 } |
|
119 |
|
120 void CMMFAudioPolicyServer::CNotificationTimer::RunL() |
|
121 { |
|
122 iCallBack.CallBack(); |
|
123 } |
|
124 |
|
125 void CMMFAudioPolicyServer::DecrementSessionCount() |
|
126 { |
|
127 iPolicySessionCount--; |
|
128 } |
|
129 |
|
130 TInt CMMFAudioPolicyServer::PolicySessionCount() |
|
131 { |
|
132 return iPolicySessionCount; |
|
133 } |
|
134 |
|
135 void CMMFAudioPolicyServer::StartNotificationTimer(TBool aZeroDelay) |
|
136 { |
|
137 iNotificationTimer->After(aZeroDelay? 0 : KTimeOutInterval); |
|
138 } |
|
139 |
|
140 void CMMFAudioPolicyServer::StopNotificationTimer() |
|
141 { |
|
142 iNotificationTimer->Cancel(); |
|
143 } |
|
144 |
|
145 TInt CMMFAudioPolicyServer::SendNotification(TAny* aAny) |
|
146 { |
|
147 CMMFAudioPolicyServer* policyServer = reinterpret_cast<CMMFAudioPolicyServer*>(aAny); |
|
148 policyServer->iAudioPolicy->NotifyNextClient(); |
|
149 return KErrNone; |
|
150 } |
|
151 |
|
152 TBool CMMFAudioPolicyServer::IsTimerActive() const |
|
153 { |
|
154 return iNotificationTimer->IsActive(); |
|
155 } |