os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraserver/src/mmcameraserverpolicymanager.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraserver/src/mmcameraserverpolicymanager.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,247 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// mmcamerapolicymanager.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @internalComponent
1.24 +*/
1.25 +
1.26 +#include "mmcameraserversession.h"
1.27 +#include "mmcameraserverpolicymanager.h"
1.28 +#include "mmcameraservercontroller.h"
1.29 +
1.30 +
1.31 +CMMCameraServerPolicyManager* CMMCameraServerPolicyManager::NewL()
1.32 + {
1.33 + CMMCameraServerPolicyManager* self = new (ELeave) CMMCameraServerPolicyManager();
1.34 + CleanupStack::PushL(self);
1.35 + self->ConstructL();
1.36 + CleanupStack::Pop(self);
1.37 + return self;
1.38 + }
1.39 +
1.40 +CMMCameraServerPolicyManager::CMMCameraServerPolicyManager() : iReservedSessionQ(_FOFF(CMMCameraServerSession,iCamSessionLink)),
1.41 + iIter(iReservedSessionQ)
1.42 + {
1.43 + }
1.44 +
1.45 +void CMMCameraServerPolicyManager::ConstructL()
1.46 + {
1.47 + }
1.48 +
1.49 +CMMCameraServerPolicyManager::~CMMCameraServerPolicyManager()
1.50 + {
1.51 + }
1.52 +
1.53 +/**
1.54 + * Enforces client connection policies.
1.55 + *
1.56 + * Called by the server as the client connects
1.57 + */
1.58 +void CMMCameraServerPolicyManager::OnConnectL(const RMessage2& aMessage)
1.59 + {
1.60 + // All users must have UserEnvironment capability
1.61 + if (!KMMCameraServerPolicyUserEnvironment.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING("CMMCameraServerPolicyManager::OnConnectL KMMCameraServerPolicyUserEnvironment")))
1.62 + {
1.63 + User::Leave(KErrPermissionDenied);
1.64 + }
1.65 + }
1.66 +
1.67 +/**
1.68 + * Performs further MultimediaDD policy check on clients connecting to the server.
1.69 + *
1.70 + * Called at the start of the Sessions ServiceL routine
1.71 + */
1.72 +void CMMCameraServerPolicyManager::ServiceHandlerL(const RMessage2& aMessage)
1.73 + {
1.74 + // If client is connecting to the server, make sure correct capabilities are set
1.75 + if (aMessage.Function() == ECamOpenCamera)
1.76 + {
1.77 + // Insert MMCapability into message buffer
1.78 + TOpenCamera parameters;
1.79 + TOpenCameraPckg openCamBuf(parameters);
1.80 + aMessage.ReadL(TInt(0), openCamBuf);
1.81 +
1.82 + parameters = openCamBuf();
1.83 +
1.84 + if (KMMCameraServerPolicyMultimediaDD.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING ("CMMCameraServerPolicyManager::ServiceHandlerL KMMCameraServerPolicyMultimediaDD")))
1.85 + {
1.86 + parameters.iMMCapability = ETrue;
1.87 + }
1.88 + else
1.89 + {
1.90 + parameters.iMMCapability = EFalse;
1.91 + }
1.92 +
1.93 + TOpenCameraPckg buf(parameters);
1.94 +
1.95 + aMessage.WriteL(TInt(0), buf);
1.96 + }
1.97 +
1.98 + // Add code here if necessary to check
1.99 + // clients ability to access particular
1.100 + // functions
1.101 + }
1.102 +
1.103 +/**
1.104 + * Used by ReserveClient() to find first reserved client session.
1.105 + */
1.106 +CMMCameraServerSession* CMMCameraServerPolicyManager::FindFirstInQue(TInt aIndex)
1.107 + {
1.108 + CMMCameraServerSession* pS = NULL;
1.109 + iIter.SetToFirst();
1.110 +
1.111 + while ((pS = iIter++) != NULL)
1.112 + {
1.113 + if (pS->CameraIndex() == aIndex)
1.114 + {
1.115 + break;
1.116 + }
1.117 + }
1.118 +
1.119 + return pS;
1.120 + }
1.121 +
1.122 +/**
1.123 + * Used by CheckControlOvertaking() to find last client in queue that has reserved the camera.
1.124 + */
1.125 +CMMCameraServerSession* CMMCameraServerPolicyManager::FindLastInQue(TInt aIndex)
1.126 + {
1.127 + CMMCameraServerSession *pS, *ret = NULL;
1.128 + iIter.SetToFirst();
1.129 +
1.130 + while ((pS = iIter++) != NULL)
1.131 + {
1.132 + if (pS->CameraIndex() == aIndex)
1.133 + {
1.134 + ret = pS;
1.135 + }
1.136 + }
1.137 +
1.138 + return ret;
1.139 + }
1.140 +
1.141 +/**
1.142 + * Attempts to reserve the specific camera which the client requested.
1.143 + */
1.144 +TBool CMMCameraServerPolicyManager::ReserveClient(CMMCameraServerSession* aSession)
1.145 + {
1.146 + TInt camIndex = aSession->CameraIndex();
1.147 +
1.148 + // Check if this is the first client reserving the camera device
1.149 + if (FindFirstInQue(camIndex) == NULL)
1.150 + {
1.151 + ReserveUpdate(aSession);
1.152 + return ETrue;
1.153 + }
1.154 + else
1.155 + {
1.156 + // If not first client, check if it is a collaborative client with the one which has already reseved the camera
1.157 + if(aSession->CollaborativeClient())
1.158 + {
1.159 + // Get the First session in the queue
1.160 + // All collaborative clients require the same MMCapability
1.161 + CMMCameraServerSession* firstSession = FindFirstInQue(camIndex);
1.162 +
1.163 + if (aSession->MMCapability() == firstSession->MMCapability())
1.164 + {
1.165 + // Set the priority of the collaborative client to that of the first client
1.166 + aSession->SetPriority(firstSession->Priority());
1.167 + iReservedSessionQ.AddLast(*aSession);
1.168 + return ETrue;
1.169 + }
1.170 + }
1.171 +
1.172 + // See if new client has higher priority than current client
1.173 + if(CheckControlOvertaking(aSession))
1.174 + {
1.175 + CMMCameraServerSession* pS = NULL;
1.176 + iIter.SetToFirst();
1.177 +
1.178 + aSession->CameraController()->Reset();
1.179 +
1.180 + while ((pS = iIter++) != NULL)
1.181 + {
1.182 + // We Deque and overthrow those clients that
1.183 + // belong to the same camIndex as this client
1.184 + if (pS->CameraIndex() == camIndex)
1.185 + {
1.186 + // set reserve status of previously reserved client to EFalse.
1.187 + pS->SetReserved(EFalse);
1.188 + pS->CompleteOverthrow();
1.189 +
1.190 + //removes from controller's 'reserved session' queue
1.191 + pS->iCamSessionLink.Deque();
1.192 + pS->iCamSessionLink.iNext = NULL;
1.193 + }
1.194 + }
1.195 +
1.196 + // update details wrt new reserved client.
1.197 + ReserveUpdate(aSession);
1.198 + return ETrue;
1.199 + }
1.200 + }
1.201 +
1.202 + return EFalse;
1.203 + }
1.204 +
1.205 +/**
1.206 + * Updates reserve status of clients. Used by ReserveClient().
1.207 + */
1.208 +void CMMCameraServerPolicyManager::ReserveUpdate(CMMCameraServerSession* aSession)
1.209 + {
1.210 + aSession->SetHandle(aSession->CameraController()->CameraHandle());
1.211 +
1.212 + iReservedSessionQ.AddLast(*aSession);
1.213 + }
1.214 +
1.215 +/**
1.216 + * Determines whether overthrowing client has higher priority than current client.
1.217 + * Used by ReserveClient().
1.218 + */
1.219 +TBool CMMCameraServerPolicyManager::CheckControlOvertaking(CMMCameraServerSession* aSession)
1.220 + {
1.221 + TInt camIndex = aSession->CameraIndex();
1.222 + CMMCameraServerSession* lastSession = FindLastInQue(camIndex);
1.223 +
1.224 + if(aSession->MMCapability() && !(lastSession->MMCapability()))
1.225 + {
1.226 + return ETrue;
1.227 + }
1.228 +
1.229 + if(aSession->MMCapability() == lastSession->MMCapability())
1.230 + {
1.231 + if(aSession->Priority() > lastSession->Priority())
1.232 + {
1.233 + return ETrue;
1.234 + }
1.235 + }
1.236 +
1.237 + return EFalse;
1.238 + }
1.239 +
1.240 +/**
1.241 + * Releases the camera device.
1.242 + */
1.243 +void CMMCameraServerPolicyManager::ReleaseClient(CMMCameraServerSession* aSession)
1.244 + {
1.245 + if(!iReservedSessionQ.IsEmpty())
1.246 + {
1.247 + aSession->iCamSessionLink.Deque();
1.248 + aSession->iCamSessionLink.iNext = NULL;
1.249 + }
1.250 + }