sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // mmcamerapolicymanager.cpp sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: */ sl@0: sl@0: #include "mmcameraserversession.h" sl@0: #include "mmcameraserverpolicymanager.h" sl@0: #include "mmcameraservercontroller.h" sl@0: sl@0: sl@0: CMMCameraServerPolicyManager* CMMCameraServerPolicyManager::NewL() sl@0: { sl@0: CMMCameraServerPolicyManager* self = new (ELeave) CMMCameraServerPolicyManager(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CMMCameraServerPolicyManager::CMMCameraServerPolicyManager() : iReservedSessionQ(_FOFF(CMMCameraServerSession,iCamSessionLink)), sl@0: iIter(iReservedSessionQ) sl@0: { sl@0: } sl@0: sl@0: void CMMCameraServerPolicyManager::ConstructL() sl@0: { sl@0: } sl@0: sl@0: CMMCameraServerPolicyManager::~CMMCameraServerPolicyManager() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Enforces client connection policies. sl@0: * sl@0: * Called by the server as the client connects sl@0: */ sl@0: void CMMCameraServerPolicyManager::OnConnectL(const RMessage2& aMessage) sl@0: { sl@0: // All users must have UserEnvironment capability sl@0: if (!KMMCameraServerPolicyUserEnvironment.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING("CMMCameraServerPolicyManager::OnConnectL KMMCameraServerPolicyUserEnvironment"))) sl@0: { sl@0: User::Leave(KErrPermissionDenied); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Performs further MultimediaDD policy check on clients connecting to the server. sl@0: * sl@0: * Called at the start of the Sessions ServiceL routine sl@0: */ sl@0: void CMMCameraServerPolicyManager::ServiceHandlerL(const RMessage2& aMessage) sl@0: { sl@0: // If client is connecting to the server, make sure correct capabilities are set sl@0: if (aMessage.Function() == ECamOpenCamera) sl@0: { sl@0: // Insert MMCapability into message buffer sl@0: TOpenCamera parameters; sl@0: TOpenCameraPckg openCamBuf(parameters); sl@0: aMessage.ReadL(TInt(0), openCamBuf); sl@0: sl@0: parameters = openCamBuf(); sl@0: sl@0: if (KMMCameraServerPolicyMultimediaDD.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING ("CMMCameraServerPolicyManager::ServiceHandlerL KMMCameraServerPolicyMultimediaDD"))) sl@0: { sl@0: parameters.iMMCapability = ETrue; sl@0: } sl@0: else sl@0: { sl@0: parameters.iMMCapability = EFalse; sl@0: } sl@0: sl@0: TOpenCameraPckg buf(parameters); sl@0: sl@0: aMessage.WriteL(TInt(0), buf); sl@0: } sl@0: sl@0: // Add code here if necessary to check sl@0: // clients ability to access particular sl@0: // functions sl@0: } sl@0: sl@0: /** sl@0: * Used by ReserveClient() to find first reserved client session. sl@0: */ sl@0: CMMCameraServerSession* CMMCameraServerPolicyManager::FindFirstInQue(TInt aIndex) sl@0: { sl@0: CMMCameraServerSession* pS = NULL; sl@0: iIter.SetToFirst(); sl@0: sl@0: while ((pS = iIter++) != NULL) sl@0: { sl@0: if (pS->CameraIndex() == aIndex) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: sl@0: return pS; sl@0: } sl@0: sl@0: /** sl@0: * Used by CheckControlOvertaking() to find last client in queue that has reserved the camera. sl@0: */ sl@0: CMMCameraServerSession* CMMCameraServerPolicyManager::FindLastInQue(TInt aIndex) sl@0: { sl@0: CMMCameraServerSession *pS, *ret = NULL; sl@0: iIter.SetToFirst(); sl@0: sl@0: while ((pS = iIter++) != NULL) sl@0: { sl@0: if (pS->CameraIndex() == aIndex) sl@0: { sl@0: ret = pS; sl@0: } sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: * Attempts to reserve the specific camera which the client requested. sl@0: */ sl@0: TBool CMMCameraServerPolicyManager::ReserveClient(CMMCameraServerSession* aSession) sl@0: { sl@0: TInt camIndex = aSession->CameraIndex(); sl@0: sl@0: // Check if this is the first client reserving the camera device sl@0: if (FindFirstInQue(camIndex) == NULL) sl@0: { sl@0: ReserveUpdate(aSession); sl@0: return ETrue; sl@0: } sl@0: else sl@0: { sl@0: // If not first client, check if it is a collaborative client with the one which has already reseved the camera sl@0: if(aSession->CollaborativeClient()) sl@0: { sl@0: // Get the First session in the queue sl@0: // All collaborative clients require the same MMCapability sl@0: CMMCameraServerSession* firstSession = FindFirstInQue(camIndex); sl@0: sl@0: if (aSession->MMCapability() == firstSession->MMCapability()) sl@0: { sl@0: // Set the priority of the collaborative client to that of the first client sl@0: aSession->SetPriority(firstSession->Priority()); sl@0: iReservedSessionQ.AddLast(*aSession); sl@0: return ETrue; sl@0: } sl@0: } sl@0: sl@0: // See if new client has higher priority than current client sl@0: if(CheckControlOvertaking(aSession)) sl@0: { sl@0: CMMCameraServerSession* pS = NULL; sl@0: iIter.SetToFirst(); sl@0: sl@0: aSession->CameraController()->Reset(); sl@0: sl@0: while ((pS = iIter++) != NULL) sl@0: { sl@0: // We Deque and overthrow those clients that sl@0: // belong to the same camIndex as this client sl@0: if (pS->CameraIndex() == camIndex) sl@0: { sl@0: // set reserve status of previously reserved client to EFalse. sl@0: pS->SetReserved(EFalse); sl@0: pS->CompleteOverthrow(); sl@0: sl@0: //removes from controller's 'reserved session' queue sl@0: pS->iCamSessionLink.Deque(); sl@0: pS->iCamSessionLink.iNext = NULL; sl@0: } sl@0: } sl@0: sl@0: // update details wrt new reserved client. sl@0: ReserveUpdate(aSession); sl@0: return ETrue; sl@0: } sl@0: } sl@0: sl@0: return EFalse; sl@0: } sl@0: sl@0: /** sl@0: * Updates reserve status of clients. Used by ReserveClient(). sl@0: */ sl@0: void CMMCameraServerPolicyManager::ReserveUpdate(CMMCameraServerSession* aSession) sl@0: { sl@0: aSession->SetHandle(aSession->CameraController()->CameraHandle()); sl@0: sl@0: iReservedSessionQ.AddLast(*aSession); sl@0: } sl@0: sl@0: /** sl@0: * Determines whether overthrowing client has higher priority than current client. sl@0: * Used by ReserveClient(). sl@0: */ sl@0: TBool CMMCameraServerPolicyManager::CheckControlOvertaking(CMMCameraServerSession* aSession) sl@0: { sl@0: TInt camIndex = aSession->CameraIndex(); sl@0: CMMCameraServerSession* lastSession = FindLastInQue(camIndex); sl@0: sl@0: if(aSession->MMCapability() && !(lastSession->MMCapability())) sl@0: { sl@0: return ETrue; sl@0: } sl@0: sl@0: if(aSession->MMCapability() == lastSession->MMCapability()) sl@0: { sl@0: if(aSession->Priority() > lastSession->Priority()) sl@0: { sl@0: return ETrue; sl@0: } sl@0: } sl@0: sl@0: return EFalse; sl@0: } sl@0: sl@0: /** sl@0: * Releases the camera device. sl@0: */ sl@0: void CMMCameraServerPolicyManager::ReleaseClient(CMMCameraServerSession* aSession) sl@0: { sl@0: if(!iReservedSessionQ.IsEmpty()) sl@0: { sl@0: aSession->iCamSessionLink.Deque(); sl@0: aSession->iCamSessionLink.iNext = NULL; sl@0: } sl@0: }