sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// mmcamerapolicymanager.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@file
|
sl@0
|
20 |
@internalComponent
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "mmcameraserversession.h"
|
sl@0
|
24 |
#include "mmcameraserverpolicymanager.h"
|
sl@0
|
25 |
#include "mmcameraservercontroller.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
|
sl@0
|
28 |
CMMCameraServerPolicyManager* CMMCameraServerPolicyManager::NewL()
|
sl@0
|
29 |
{
|
sl@0
|
30 |
CMMCameraServerPolicyManager* self = new (ELeave) CMMCameraServerPolicyManager();
|
sl@0
|
31 |
CleanupStack::PushL(self);
|
sl@0
|
32 |
self->ConstructL();
|
sl@0
|
33 |
CleanupStack::Pop(self);
|
sl@0
|
34 |
return self;
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
CMMCameraServerPolicyManager::CMMCameraServerPolicyManager() : iReservedSessionQ(_FOFF(CMMCameraServerSession,iCamSessionLink)),
|
sl@0
|
38 |
iIter(iReservedSessionQ)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
void CMMCameraServerPolicyManager::ConstructL()
|
sl@0
|
43 |
{
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
CMMCameraServerPolicyManager::~CMMCameraServerPolicyManager()
|
sl@0
|
47 |
{
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
/**
|
sl@0
|
51 |
* Enforces client connection policies.
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* Called by the server as the client connects
|
sl@0
|
54 |
*/
|
sl@0
|
55 |
void CMMCameraServerPolicyManager::OnConnectL(const RMessage2& aMessage)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
// All users must have UserEnvironment capability
|
sl@0
|
58 |
if (!KMMCameraServerPolicyUserEnvironment.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING("CMMCameraServerPolicyManager::OnConnectL KMMCameraServerPolicyUserEnvironment")))
|
sl@0
|
59 |
{
|
sl@0
|
60 |
User::Leave(KErrPermissionDenied);
|
sl@0
|
61 |
}
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
/**
|
sl@0
|
65 |
* Performs further MultimediaDD policy check on clients connecting to the server.
|
sl@0
|
66 |
*
|
sl@0
|
67 |
* Called at the start of the Sessions ServiceL routine
|
sl@0
|
68 |
*/
|
sl@0
|
69 |
void CMMCameraServerPolicyManager::ServiceHandlerL(const RMessage2& aMessage)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
// If client is connecting to the server, make sure correct capabilities are set
|
sl@0
|
72 |
if (aMessage.Function() == ECamOpenCamera)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
// Insert MMCapability into message buffer
|
sl@0
|
75 |
TOpenCamera parameters;
|
sl@0
|
76 |
TOpenCameraPckg openCamBuf(parameters);
|
sl@0
|
77 |
aMessage.ReadL(TInt(0), openCamBuf);
|
sl@0
|
78 |
|
sl@0
|
79 |
parameters = openCamBuf();
|
sl@0
|
80 |
|
sl@0
|
81 |
if (KMMCameraServerPolicyMultimediaDD.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING ("CMMCameraServerPolicyManager::ServiceHandlerL KMMCameraServerPolicyMultimediaDD")))
|
sl@0
|
82 |
{
|
sl@0
|
83 |
parameters.iMMCapability = ETrue;
|
sl@0
|
84 |
}
|
sl@0
|
85 |
else
|
sl@0
|
86 |
{
|
sl@0
|
87 |
parameters.iMMCapability = EFalse;
|
sl@0
|
88 |
}
|
sl@0
|
89 |
|
sl@0
|
90 |
TOpenCameraPckg buf(parameters);
|
sl@0
|
91 |
|
sl@0
|
92 |
aMessage.WriteL(TInt(0), buf);
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
// Add code here if necessary to check
|
sl@0
|
96 |
// clients ability to access particular
|
sl@0
|
97 |
// functions
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
/**
|
sl@0
|
101 |
* Used by ReserveClient() to find first reserved client session.
|
sl@0
|
102 |
*/
|
sl@0
|
103 |
CMMCameraServerSession* CMMCameraServerPolicyManager::FindFirstInQue(TInt aIndex)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
CMMCameraServerSession* pS = NULL;
|
sl@0
|
106 |
iIter.SetToFirst();
|
sl@0
|
107 |
|
sl@0
|
108 |
while ((pS = iIter++) != NULL)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
if (pS->CameraIndex() == aIndex)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
break;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
return pS;
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
/**
|
sl@0
|
120 |
* Used by CheckControlOvertaking() to find last client in queue that has reserved the camera.
|
sl@0
|
121 |
*/
|
sl@0
|
122 |
CMMCameraServerSession* CMMCameraServerPolicyManager::FindLastInQue(TInt aIndex)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
CMMCameraServerSession *pS, *ret = NULL;
|
sl@0
|
125 |
iIter.SetToFirst();
|
sl@0
|
126 |
|
sl@0
|
127 |
while ((pS = iIter++) != NULL)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
if (pS->CameraIndex() == aIndex)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
ret = pS;
|
sl@0
|
132 |
}
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
return ret;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
/**
|
sl@0
|
139 |
* Attempts to reserve the specific camera which the client requested.
|
sl@0
|
140 |
*/
|
sl@0
|
141 |
TBool CMMCameraServerPolicyManager::ReserveClient(CMMCameraServerSession* aSession)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
TInt camIndex = aSession->CameraIndex();
|
sl@0
|
144 |
|
sl@0
|
145 |
// Check if this is the first client reserving the camera device
|
sl@0
|
146 |
if (FindFirstInQue(camIndex) == NULL)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
ReserveUpdate(aSession);
|
sl@0
|
149 |
return ETrue;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
else
|
sl@0
|
152 |
{
|
sl@0
|
153 |
// If not first client, check if it is a collaborative client with the one which has already reseved the camera
|
sl@0
|
154 |
if(aSession->CollaborativeClient())
|
sl@0
|
155 |
{
|
sl@0
|
156 |
// Get the First session in the queue
|
sl@0
|
157 |
// All collaborative clients require the same MMCapability
|
sl@0
|
158 |
CMMCameraServerSession* firstSession = FindFirstInQue(camIndex);
|
sl@0
|
159 |
|
sl@0
|
160 |
if (aSession->MMCapability() == firstSession->MMCapability())
|
sl@0
|
161 |
{
|
sl@0
|
162 |
// Set the priority of the collaborative client to that of the first client
|
sl@0
|
163 |
aSession->SetPriority(firstSession->Priority());
|
sl@0
|
164 |
iReservedSessionQ.AddLast(*aSession);
|
sl@0
|
165 |
return ETrue;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
// See if new client has higher priority than current client
|
sl@0
|
170 |
if(CheckControlOvertaking(aSession))
|
sl@0
|
171 |
{
|
sl@0
|
172 |
CMMCameraServerSession* pS = NULL;
|
sl@0
|
173 |
iIter.SetToFirst();
|
sl@0
|
174 |
|
sl@0
|
175 |
aSession->CameraController()->Reset();
|
sl@0
|
176 |
|
sl@0
|
177 |
while ((pS = iIter++) != NULL)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
// We Deque and overthrow those clients that
|
sl@0
|
180 |
// belong to the same camIndex as this client
|
sl@0
|
181 |
if (pS->CameraIndex() == camIndex)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
// set reserve status of previously reserved client to EFalse.
|
sl@0
|
184 |
pS->SetReserved(EFalse);
|
sl@0
|
185 |
pS->CompleteOverthrow();
|
sl@0
|
186 |
|
sl@0
|
187 |
//removes from controller's 'reserved session' queue
|
sl@0
|
188 |
pS->iCamSessionLink.Deque();
|
sl@0
|
189 |
pS->iCamSessionLink.iNext = NULL;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
// update details wrt new reserved client.
|
sl@0
|
194 |
ReserveUpdate(aSession);
|
sl@0
|
195 |
return ETrue;
|
sl@0
|
196 |
}
|
sl@0
|
197 |
}
|
sl@0
|
198 |
|
sl@0
|
199 |
return EFalse;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
/**
|
sl@0
|
203 |
* Updates reserve status of clients. Used by ReserveClient().
|
sl@0
|
204 |
*/
|
sl@0
|
205 |
void CMMCameraServerPolicyManager::ReserveUpdate(CMMCameraServerSession* aSession)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
aSession->SetHandle(aSession->CameraController()->CameraHandle());
|
sl@0
|
208 |
|
sl@0
|
209 |
iReservedSessionQ.AddLast(*aSession);
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
/**
|
sl@0
|
213 |
* Determines whether overthrowing client has higher priority than current client.
|
sl@0
|
214 |
* Used by ReserveClient().
|
sl@0
|
215 |
*/
|
sl@0
|
216 |
TBool CMMCameraServerPolicyManager::CheckControlOvertaking(CMMCameraServerSession* aSession)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
TInt camIndex = aSession->CameraIndex();
|
sl@0
|
219 |
CMMCameraServerSession* lastSession = FindLastInQue(camIndex);
|
sl@0
|
220 |
|
sl@0
|
221 |
if(aSession->MMCapability() && !(lastSession->MMCapability()))
|
sl@0
|
222 |
{
|
sl@0
|
223 |
return ETrue;
|
sl@0
|
224 |
}
|
sl@0
|
225 |
|
sl@0
|
226 |
if(aSession->MMCapability() == lastSession->MMCapability())
|
sl@0
|
227 |
{
|
sl@0
|
228 |
if(aSession->Priority() > lastSession->Priority())
|
sl@0
|
229 |
{
|
sl@0
|
230 |
return ETrue;
|
sl@0
|
231 |
}
|
sl@0
|
232 |
}
|
sl@0
|
233 |
|
sl@0
|
234 |
return EFalse;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
/**
|
sl@0
|
238 |
* Releases the camera device.
|
sl@0
|
239 |
*/
|
sl@0
|
240 |
void CMMCameraServerPolicyManager::ReleaseClient(CMMCameraServerSession* aSession)
|
sl@0
|
241 |
{
|
sl@0
|
242 |
if(!iReservedSessionQ.IsEmpty())
|
sl@0
|
243 |
{
|
sl@0
|
244 |
aSession->iCamSessionLink.Deque();
|
sl@0
|
245 |
aSession->iCamSessionLink.iNext = NULL;
|
sl@0
|
246 |
}
|
sl@0
|
247 |
}
|