Update contrib.
1 // Copyright (c) 2007-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 <mmf/common/mmfcontrollerframework.h>
18 #include "MmfDrmPluginServer.h"
19 #include "MmfDrmPluginServerStart.h"
20 #include "MmfDrmPluginServerSession.h"
21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
22 #include <mmf/common/mmfcontrollerframeworkclasses.h>
25 CMMFDRMPluginServer* CMMFDRMPluginServer::NewL()
27 CMMFDRMPluginServer* s = new(ELeave) CMMFDRMPluginServer();
28 CleanupStack::PushL(s);
34 CMMFDRMPluginServer::CMMFDRMPluginServer() :
35 CMmfIpcServer(EPriorityStandard)
39 void CMMFDRMPluginServer::ConstructL()
41 iDelayServerShutDown = CDelayServerShutDown::NewL();
42 // Call base class to Start server
43 StartL(KDrmPluginServerName);
46 CMMFDRMPluginServer::~CMMFDRMPluginServer()
48 iControllerServList.ResetAndDestroy();
49 iControllerServList.Close();
50 delete iDelayServerShutDown;
53 CMmfIpcSession* CMMFDRMPluginServer::NewSessionL(const TVersion& aVersion) const
55 TVersion v(KMMFDRMPluginServerVersion,
56 KMMFDRMPluginServerMinorVersionNumber,
57 KMMFDRMPluginServerBuildVersionNumber);
58 if(!User::QueryVersionSupported(v, aVersion))
60 User::Leave(KErrNotSupported);
63 for(TInt i = 0; i < iControllerServList.Count(); i++)
65 CStartAndMonitorControllerThread* controllerMonThread
66 = iControllerServList[i];
67 if(!controllerMonThread->IsActive())
69 iControllerServList.Remove(i);
70 delete controllerMonThread;
73 iControllerServList.Compress();
75 CMMFDRMPluginServerSession* session = CMMFDRMPluginServerSession::NewL();
79 void CMMFDRMPluginServer::IncrementSessionId()
84 void CMMFDRMPluginServer::DecrementSessionId()
87 if(iSessionCount == 0 && iControllerCount == 0)
89 // Guarantee that server will be closed, after a period of time, even
90 // a session has been created without a controller thread initialized
91 if(!iDelayServerShutDown->IsActive())
93 // If shut down timer has been started previously, that setup has the piority
94 iDelayServerShutDown->SetDelay(TTimeIntervalMicroSeconds32(iServerTimeout));
99 void CMMFDRMPluginServer::IncrementControllerCount()
104 //In the case we started the shutdown due to no more controllers
105 iDelayServerShutDown->Cancel();
109 void CMMFDRMPluginServer::DecrementControllerCount()
112 if (iControllerCount == 0)
114 iDelayServerShutDown->SetDelay(TTimeIntervalMicroSeconds32(iServerTimeout));
118 TInt CMMFDRMPluginServer::StartControllerServer(const RThread& aClientThread, TUint aMaxHeapSize, TBool aUseSharedHeap,
119 RMMFControllerServerProxy& aControllerSessionHandle, TThreadId& aControllerTID, TUint aStackSize) const
121 CStartAndMonitorControllerThread* monitor = NULL;
124 CStartAndMonitorControllerThread::NewL(const_cast<CMMFDRMPluginServer*>(this)));
131 err = iControllerServList.Append(monitor);
138 return monitor->StartControllerServer(aClientThread, aMaxHeapSize, aUseSharedHeap,
139 aControllerSessionHandle, aControllerTID, aStackSize);
142 void CMMFDRMPluginServer::PanicControllerThread(TThreadId aTid, const TDesC& aCategory,TInt aReason)
144 for(TInt i = 0; i < iControllerServList.Count(); i++)
146 if(iControllerServList[i]->Thread().Id() == aTid)
148 iControllerServList[i]->Thread().Panic(aCategory, aReason);
154 void CMMFDRMPluginServer::KillControllerThread(TThreadId aTid, TInt aReason)
156 for(TInt i = 0; i < iControllerServList.Count(); i++)
158 if(iControllerServList[i]->Thread().Id() == aTid)
160 iControllerServList[i]->Thread().Kill(aReason);
166 TInt CMMFDRMPluginServer::SetThreadPriority(TThreadId aTid, TThreadPriority aPriority)
168 TBool threadFound = EFalse;
169 for(TInt i = 0; i < iControllerServList.Count(); i++)
171 const RThread& controllerThread = iControllerServList[i]->Thread();
172 if (controllerThread.Id() == aTid)
174 if (controllerThread.Priority() != aPriority)
176 controllerThread.Suspend();
177 controllerThread.SetPriority(aPriority);
178 controllerThread.Resume();
184 return threadFound? KErrNone: KErrNotFound;
187 CMMFDRMPluginServer::CDelayServerShutDown* CMMFDRMPluginServer::CDelayServerShutDown::NewL()
189 CDelayServerShutDown* self = new(ELeave) CDelayServerShutDown;
190 CleanupStack::PushL(self);
196 CMMFDRMPluginServer::CDelayServerShutDown::CDelayServerShutDown() : CActive(0)
200 void CMMFDRMPluginServer::CDelayServerShutDown::ConstructL()
202 User::LeaveIfError(iShutDownTimer.CreateLocal());
203 CActiveScheduler::Add(this);
206 CMMFDRMPluginServer::CDelayServerShutDown::~CDelayServerShutDown()
209 iShutDownTimer.Close();
212 void CMMFDRMPluginServer::CDelayServerShutDown::SetDelay(TTimeIntervalMicroSeconds32 aDelay)
214 __ASSERT_ALWAYS(!IsActive(), User::Panic(_L("CMMFDRMPluginServer"), 1));
215 iShutDownTimer.After(iStatus, aDelay);
219 void CMMFDRMPluginServer::CDelayServerShutDown::RunL()
221 CActiveScheduler::Stop();
225 void CMMFDRMPluginServer::CDelayServerShutDown::DoCancel()
227 iShutDownTimer.Cancel();
230 CStartAndMonitorControllerThread* CStartAndMonitorControllerThread::NewL(CMMFDRMPluginServer* aPluginServer)
232 CStartAndMonitorControllerThread* self = new(ELeave) CStartAndMonitorControllerThread(aPluginServer);
233 CleanupStack::PushL(self);
239 void CStartAndMonitorControllerThread::ConstructL()
241 CActiveScheduler::Add(this);
244 TInt CStartAndMonitorControllerThread::StartControllerServer(const RThread& /*aClientThread*/, TUint aMaxHeapSize, TBool aUseSharedHeap,
245 RMMFControllerServerProxy& aControllerSessionHandle, TThreadId& aControllerTID,TUint aStackSize)
250 RServer2 controllerServer;
251 TControllerProxyServerParams params;
252 params.iServer = &controllerServer;
253 params.iUsingSharedHeap = aUseSharedHeap;
256 name.Append(KMMFControllerProxyServerName);
258 // Threads create own heap (default behaviour)
259 if(aMaxHeapSize < static_cast<TUint>(KMinHeapSize))
261 aMaxHeapSize = KMinHeapSize; //else raises a USER 111 panic
263 else if(aMaxHeapSize > static_cast<TUint>(KMMFControllerProxyMaxHeapSize))
265 aMaxHeapSize = KMMFControllerProxyMaxHeapSize;
268 err = iServerThread.Create(name, &CMMFControllerProxyServer::StartThread,
269 aStackSize, KMinHeapSize, aMaxHeapSize,
270 ¶ms, EOwnerThread);
276 // Synchronise with the server
277 TRequestStatus reqStatus;
278 iServerThread.Rendezvous(reqStatus);
280 if (reqStatus!=KRequestPending)
282 iServerThread.Kill(0);
286 iServerThread.SetPriority(EPriorityNormal);
287 iServerThread.Resume();
288 // Server will call the reciprocal static synchronise call
291 User::WaitForRequest(reqStatus); // wait for start or death
292 if(reqStatus.Int() != KErrNone)
294 iServerThread.Close();
295 controllerServer.Close();
296 return reqStatus.Int();
299 err = aControllerSessionHandle.Open(controllerServer);
302 iServerThread.Close();
303 controllerServer.Close();
307 iStatus = KRequestPending;
308 iServerThread.Logon(iStatus);
309 if (iStatus != KRequestPending)
312 aControllerSessionHandle.Close();
313 iServerThread.Close();
314 controllerServer.Close();
315 return iStatus.Int();
322 aControllerSessionHandle.ShareProtected();
323 aControllerTID = iServerThread.Id();
324 iDrmPluginServer->IncrementControllerCount();
329 CStartAndMonitorControllerThread::CStartAndMonitorControllerThread(CMMFDRMPluginServer* aPluginServer)
330 : CActive(EPriorityStandard)
332 iDrmPluginServer = aPluginServer;
335 CStartAndMonitorControllerThread::~CStartAndMonitorControllerThread()
340 void CStartAndMonitorControllerThread::RunL()
342 iServerThread.Close();
343 iDrmPluginServer->DecrementControllerCount();
346 void CStartAndMonitorControllerThread::DoCancel()
348 iServerThread.LogonCancel(iStatus);
349 iServerThread.Kill(0);
350 iServerThread.Close();
351 iDrmPluginServer->DecrementControllerCount();
354 TInt RMMFControllerServerProxy::Open(RServer2& aControllerServerHandle)
356 TInt err = CreateSession(aControllerServerHandle, KMMFControllerProxyVersion,
357 -1, EIpcSession_GlobalSharable);