Update contrib.
1 // Copyright (c) 2006-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 "mmfdevsoundserver.h"
18 #include "mmfdevsoundserverstart.h"
19 #include "mmfdevsoundsession.h"
20 #include "mmfdevsoundserverconsts.h"
22 const TInt KDevSoundShutDownDelay = 0; //no delay
23 _LIT(KMMFDevSoundServerName, "MMFDevSoundServer-");
25 // ======== LOCAL FUNCTIONS ========
26 void Panic(TInt aPanicCode)
28 _LIT(KDevSoundServerPanicCategory, "mmfdevsoundserver");
29 User::Panic(KDevSoundServerPanicCategory, aPanicCode);
33 CMMFDevSoundServer* CMMFDevSoundServer::NewL
34 Two-phased constructor.
36 EXPORT_C CMMFDevSoundServer* CMMFDevSoundServer::NewL(
37 MGlobalProperties* aGlobalProperties,
38 TProcessId& aClientPID)
40 CMMFDevSoundServer* self = new(ELeave) CMMFDevSoundServer(aGlobalProperties,
42 CleanupStack::PushL(self);
44 CleanupStack::Pop(self);
49 CMMFDevSoundServer::CMMFDevSoundServer
50 C++ default constructor can NOT contain any code, that might leave.
52 CMMFDevSoundServer::CMMFDevSoundServer(
53 MGlobalProperties* aGlobalProperties,
54 TProcessId& aClientPID) :
55 CMmfIpcServer(EPriorityStandard, EGlobalSharableSessions),
56 iClientPID(aClientPID),
57 iActualClientPID(aClientPID)
59 iGlobalProperties = aGlobalProperties;
63 CMMFDevSoundServer::ConstructL
64 Symbian 2nd phase constructor can leave.
66 void CMMFDevSoundServer::ConstructL()
69 User::LeaveIfError(client.Open(iClientPID));
74 iDelayDevSoundShutDown = CDelayDevSoundShutDown::NewL();
76 // Call base class to Start server
81 CMMFDevSoundServer::~CMMFDevSoundServer
84 CMMFDevSoundServer::~CMMFDevSoundServer()
86 if (iDelayDevSoundShutDown)
88 iDelayDevSoundShutDown->Cancel();
89 delete iDelayDevSoundShutDown;
94 CMMFDevSoundServer::NewSessionL
96 (other items were commented in a header).
98 CMmfIpcSession* CMMFDevSoundServer::NewSessionL(const TVersion& aVersion) const
100 CMmfIpcSession* devSoundSession = NULL;
102 TRAPD(error, devSoundSession = CreateNewSessionL(aVersion));
106 // session create failed, so flag for subsequent destruction of server
107 CMMFDevSoundServer* mutableThis = const_cast<CMMFDevSoundServer*>(this);
108 mutableThis->CheckForNoSessionsLeft();
111 return devSoundSession;
115 CMMFDevSoundServer::CreateNewSessionL
116 Guts of what would otherwise be in NewSessionL() itself
118 CMmfIpcSession* CMMFDevSoundServer::CreateNewSessionL(const TVersion& aVersion) const
120 TVersion version(KMMFDevSoundServerVersion,
121 KMMFDevSoundServerMinorVersionNumber,
122 KMMFDevSoundServerBuildVersionNumber);
124 if(!User::QueryVersionSupported(version, aVersion))
126 User::Leave(KErrNotSupported);
129 CMMFDevSoundSession* devSoundSession =
130 CMMFDevSoundSession::NewL(*iGlobalProperties);
131 return devSoundSession;
135 CMMFDevSoundServer::IncrementSessionId
136 Increments session count
137 (other items were commented in a header).
139 void CMMFDevSoundServer::IncrementSessionId()
141 iDevSoundSessionId++;
142 if (iDevSoundSessionId)
144 iDelayDevSoundShutDown->Cancel();
149 CMMFDevSoundServer::DecrementSessionId
150 Decrements session count
151 (other items were commented in a header).
153 void CMMFDevSoundServer::DecrementSessionId()
155 iDevSoundSessionId--;
156 CheckForNoSessionsLeft();
160 CMMFDevSoundServer::CheckForNoSessionsLeft
161 If no sessions are left, we kick off timer, which closes down server after timeout
162 really meaning the server closes asynchronously
164 void CMMFDevSoundServer::CheckForNoSessionsLeft()
166 if (iDevSoundSessionId == 0)
168 iDelayDevSoundShutDown->SetDelay(
169 TTimeIntervalMicroSeconds32(KDevSoundShutDownDelay));
174 CMMFDevSoundServer::SendEventToClient
175 For the session requested, send event to client
176 (other items were commented in a header).
178 void CMMFDevSoundServer::SendEventToClient(TInt aSessionToAlert,
179 TInt /*aSessionToBeLaunched*/)
181 iSessionIter.SetToFirst();
182 CMMFDevSoundSession* session =
183 static_cast<CMMFDevSoundSession*>(iSessionIter++);
185 while (session != NULL)
187 if (session->DevSoundSessionId() == aSessionToAlert)
191 session = static_cast<CMMFDevSoundSession*>(iSessionIter++);
196 CMMFDevSoundServer::LaunchRequest
197 Launches the DevSound servers waiting for Audio Policy.
198 (other items were commented in a header).
200 void CMMFDevSoundServer::LaunchRequest(TInt aSessionId)
202 iSessionIter.SetToFirst();
203 CMMFDevSoundSession* session =
204 static_cast<CMMFDevSoundSession*>(iSessionIter++);
206 while (session != NULL)
208 if (session->DevSoundSessionId() == aSessionId)
212 session = static_cast<CMMFDevSoundSession*>(iSessionIter++);
217 void CMMFDevSoundServer::RenamePrioritizeServer()
219 //Rename devsound server name
220 RThread devsoundServerThread;
223 name.Append(KMMFDevSoundServerName);
224 threadId = devsoundServerThread.Id();
225 name.AppendNum(threadId.Id(),EHex);
226 //We are ignoring the error code returned from User::RenameThread
227 //as it is not important here, may be for profiling
228 User::RenameThread(name);
230 //Set the devsound priority
231 TThreadPriority devsoundServerPriority = static_cast<TThreadPriority>(KDevsoundServerPriority);
232 devsoundServerThread.SetPriority(devsoundServerPriority);
236 CMMFDevSoundServer* CMMFDevSoundServer::NewL
237 Two-phased constructor.
239 CMMFDevSoundServer::CDelayDevSoundShutDown*
240 CMMFDevSoundServer::CDelayDevSoundShutDown::NewL()
242 CDelayDevSoundShutDown* self = new(ELeave) CDelayDevSoundShutDown;
243 CleanupStack::PushL(self);
245 CleanupStack::Pop(self);
250 CMMFDevSoundServer::CDelayDevSoundShutDown::CDelayDevSoundShutDown
252 (other items were commented in a header).
254 CMMFDevSoundServer::CDelayDevSoundShutDown::CDelayDevSoundShutDown()
260 CMMFDevSoundServer::CDelayDevSoundShutDown::ConstructL
261 Symbian 2nd phase constructor can leave.
263 void CMMFDevSoundServer::CDelayDevSoundShutDown::ConstructL()
265 User::LeaveIfError(iTimer.CreateLocal());
266 CActiveScheduler::Add(this);
270 CMMFDevSoundServer::CDelayDevSoundShutDown::~CDelayDevSoundShutDown
273 CMMFDevSoundServer::CDelayDevSoundShutDown::~CDelayDevSoundShutDown()
280 CMMFDevSoundServer::CDelayDevSoundShutDown::SetDelay
281 Request a timeout after aDelay
282 (other items were commented in a header).
284 void CMMFDevSoundServer::CDelayDevSoundShutDown::SetDelay(
285 TTimeIntervalMicroSeconds32 aDelay)
287 __ASSERT_ALWAYS(!IsActive(), Panic(EMMFDevSoundServerIsActive));
288 iTimer.After(iStatus, aDelay);
293 CMMFDevSoundServer::CDelayDevSoundShutDown::RunL
294 Called by Active object framework after timer expires
295 (other items were commented in a header).
297 void CMMFDevSoundServer::CDelayDevSoundShutDown::RunL()
299 CActiveScheduler::Stop();
303 CMMFDevSoundServer::CDelayDevSoundShutDown::DoCancel
304 Called by Active object framework when user cancels active object.
305 (other items were commented in a header).
307 void CMMFDevSoundServer::CDelayDevSoundShutDown::DoCancel()
313 CMMFDevSoundServer::SetClientProcessIdL
315 void CMMFDevSoundServer::SetClientProcessIdL(TThreadId aTid)
318 RThread clientThread;
319 User::LeaveIfError(clientThread.Open(aTid));
320 CleanupClosePushL(clientThread);
322 RProcess clientProcess;
323 User::LeaveIfError(clientThread.Process(clientProcess));
324 CleanupClosePushL(clientProcess);
326 iActualClientPID = clientProcess.Id();
327 CleanupStack::PopAndDestroy(2, &clientThread); // clientProcess, clientThread
332 This function raises a panic on the client of the DevSound Server
335 one of the several panic codes that may be raised by this dll on
338 @panic EMMFDevSoundPlayDataWithoutInitialize is raised when playdata is
339 called without initialization
340 @panic EMMFDevSoundRecordDataWithoutInitialize is raised when recorddata
341 is called without initialization
343 GLDEF_C void PanicClient(const RMmfIpcMessage& aMessage,
344 TMMFDevSoundClientPanicCodes aPanicCode)
346 aMessage.Panic(KMMFDevSoundClientPanicCategory, aPanicCode);