os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraserver/src/mmcameraserverpolicymanager.cpp
Update contrib.
1 // Copyright (c) 2008-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.
14 // mmcamerapolicymanager.cpp
23 #include "mmcameraserversession.h"
24 #include "mmcameraserverpolicymanager.h"
25 #include "mmcameraservercontroller.h"
28 CMMCameraServerPolicyManager* CMMCameraServerPolicyManager::NewL()
30 CMMCameraServerPolicyManager* self = new (ELeave) CMMCameraServerPolicyManager();
31 CleanupStack::PushL(self);
33 CleanupStack::Pop(self);
37 CMMCameraServerPolicyManager::CMMCameraServerPolicyManager() : iReservedSessionQ(_FOFF(CMMCameraServerSession,iCamSessionLink)),
38 iIter(iReservedSessionQ)
42 void CMMCameraServerPolicyManager::ConstructL()
46 CMMCameraServerPolicyManager::~CMMCameraServerPolicyManager()
51 * Enforces client connection policies.
53 * Called by the server as the client connects
55 void CMMCameraServerPolicyManager::OnConnectL(const RMessage2& aMessage)
57 // All users must have UserEnvironment capability
58 if (!KMMCameraServerPolicyUserEnvironment.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING("CMMCameraServerPolicyManager::OnConnectL KMMCameraServerPolicyUserEnvironment")))
60 User::Leave(KErrPermissionDenied);
65 * Performs further MultimediaDD policy check on clients connecting to the server.
67 * Called at the start of the Sessions ServiceL routine
69 void CMMCameraServerPolicyManager::ServiceHandlerL(const RMessage2& aMessage)
71 // If client is connecting to the server, make sure correct capabilities are set
72 if (aMessage.Function() == ECamOpenCamera)
74 // Insert MMCapability into message buffer
75 TOpenCamera parameters;
76 TOpenCameraPckg openCamBuf(parameters);
77 aMessage.ReadL(TInt(0), openCamBuf);
79 parameters = openCamBuf();
81 if (KMMCameraServerPolicyMultimediaDD.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING ("CMMCameraServerPolicyManager::ServiceHandlerL KMMCameraServerPolicyMultimediaDD")))
83 parameters.iMMCapability = ETrue;
87 parameters.iMMCapability = EFalse;
90 TOpenCameraPckg buf(parameters);
92 aMessage.WriteL(TInt(0), buf);
95 // Add code here if necessary to check
96 // clients ability to access particular
101 * Used by ReserveClient() to find first reserved client session.
103 CMMCameraServerSession* CMMCameraServerPolicyManager::FindFirstInQue(TInt aIndex)
105 CMMCameraServerSession* pS = NULL;
108 while ((pS = iIter++) != NULL)
110 if (pS->CameraIndex() == aIndex)
120 * Used by CheckControlOvertaking() to find last client in queue that has reserved the camera.
122 CMMCameraServerSession* CMMCameraServerPolicyManager::FindLastInQue(TInt aIndex)
124 CMMCameraServerSession *pS, *ret = NULL;
127 while ((pS = iIter++) != NULL)
129 if (pS->CameraIndex() == aIndex)
139 * Attempts to reserve the specific camera which the client requested.
141 TBool CMMCameraServerPolicyManager::ReserveClient(CMMCameraServerSession* aSession)
143 TInt camIndex = aSession->CameraIndex();
145 // Check if this is the first client reserving the camera device
146 if (FindFirstInQue(camIndex) == NULL)
148 ReserveUpdate(aSession);
153 // If not first client, check if it is a collaborative client with the one which has already reseved the camera
154 if(aSession->CollaborativeClient())
156 // Get the First session in the queue
157 // All collaborative clients require the same MMCapability
158 CMMCameraServerSession* firstSession = FindFirstInQue(camIndex);
160 if (aSession->MMCapability() == firstSession->MMCapability())
162 // Set the priority of the collaborative client to that of the first client
163 aSession->SetPriority(firstSession->Priority());
164 iReservedSessionQ.AddLast(*aSession);
169 // See if new client has higher priority than current client
170 if(CheckControlOvertaking(aSession))
172 CMMCameraServerSession* pS = NULL;
175 aSession->CameraController()->Reset();
177 while ((pS = iIter++) != NULL)
179 // We Deque and overthrow those clients that
180 // belong to the same camIndex as this client
181 if (pS->CameraIndex() == camIndex)
183 // set reserve status of previously reserved client to EFalse.
184 pS->SetReserved(EFalse);
185 pS->CompleteOverthrow();
187 //removes from controller's 'reserved session' queue
188 pS->iCamSessionLink.Deque();
189 pS->iCamSessionLink.iNext = NULL;
193 // update details wrt new reserved client.
194 ReserveUpdate(aSession);
203 * Updates reserve status of clients. Used by ReserveClient().
205 void CMMCameraServerPolicyManager::ReserveUpdate(CMMCameraServerSession* aSession)
207 aSession->SetHandle(aSession->CameraController()->CameraHandle());
209 iReservedSessionQ.AddLast(*aSession);
213 * Determines whether overthrowing client has higher priority than current client.
214 * Used by ReserveClient().
216 TBool CMMCameraServerPolicyManager::CheckControlOvertaking(CMMCameraServerSession* aSession)
218 TInt camIndex = aSession->CameraIndex();
219 CMMCameraServerSession* lastSession = FindLastInQue(camIndex);
221 if(aSession->MMCapability() && !(lastSession->MMCapability()))
226 if(aSession->MMCapability() == lastSession->MMCapability())
228 if(aSession->Priority() > lastSession->Priority())
238 * Releases the camera device.
240 void CMMCameraServerPolicyManager::ReleaseClient(CMMCameraServerSession* aSession)
242 if(!iReservedSessionQ.IsEmpty())
244 aSession->iCamSessionLink.Deque();
245 aSession->iCamSessionLink.iNext = NULL;