|
1 // Copyright (c) 1995-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "server.h" |
|
17 #include "WSGRAPHICDRAWERFACTORY.H" |
|
18 #include "panics.h" |
|
19 #include <s32mem.h> |
|
20 #include "wstop.h" |
|
21 |
|
22 TInt CWsGraphicDrawerObject::TransientSequence=1; |
|
23 TBool CWsGraphicDrawerObject::RollOver=EFalse; |
|
24 |
|
25 CWsGraphicDrawerObject* CWsGraphicDrawerObject::NewL(CWsClient* aClient,const TWsClCmdUnion &aParams) |
|
26 { |
|
27 if(!aClient) |
|
28 { |
|
29 WS_PANIC_DEBUG(EWsPanicWsGraphic); |
|
30 User::Leave(KErrGeneral); |
|
31 } |
|
32 TGraphicDrawerId id; |
|
33 id.iId = aParams.CreateGraphic->iId; |
|
34 id.iIsUid = !(EWsGraphicIdTransient & aParams.CreateGraphic->iFlags); |
|
35 // check for collision |
|
36 const CWsGraphicDrawer* dup = aClient->WindowServer().ResolveGraphic(id); |
|
37 // request-specific checks |
|
38 if(dup) |
|
39 { |
|
40 // must be exact same session |
|
41 if(&(dup->Owner()) != aClient) |
|
42 { |
|
43 /* Someone is squatting on someone else's uid, or trying to, |
|
44 but there is no good way to know which. */ |
|
45 __DEBUG_ONLY(aClient->PPanic(EWservPanicPermissionDenied);) |
|
46 User::Leave(KErrAlreadyExists); |
|
47 } |
|
48 // dupping or otherwise must be explicitly intended by the client |
|
49 if(!(EWsGraphicReplace & aParams.CreateGraphic->iFlags)) |
|
50 { |
|
51 aClient->PPanic(EWservPanicPermissionDenied); |
|
52 } |
|
53 } |
|
54 else |
|
55 { |
|
56 // dupping or otherwise must be explicitly intended by the client |
|
57 if(EWsGraphicReplace & aParams.CreateGraphic->iFlags) |
|
58 { |
|
59 aClient->PPanic(EWservPanicPermissionDenied); |
|
60 } |
|
61 if(id.iIsUid) |
|
62 { |
|
63 // police creation of artwork with UIDs |
|
64 _LIT_SECURITY_POLICY_C1(KSecurityPolicyCreateWithUid,ECapabilityProtServ); |
|
65 if(!KSecurityPolicyCreateWithUid.CheckPolicy(aClient->Client())) |
|
66 { |
|
67 __DEBUG_ONLY(aClient->PPanic(EWservPanicPermissionDenied);) |
|
68 User::Leave(KErrPermissionDenied); |
|
69 } |
|
70 } |
|
71 else |
|
72 { |
|
73 // allocate a new transient id |
|
74 // assumption: that there are more values of a TInt than there are possibly Transient objects |
|
75 do |
|
76 { |
|
77 id.iId = TransientSequence++; |
|
78 RollOver |= !TransientSequence; |
|
79 } |
|
80 while(RollOver && aClient->WindowServer().ResolveGraphic(id)); // until no collision |
|
81 } |
|
82 } |
|
83 // create the drawer object |
|
84 TPtrC8 data; |
|
85 HBufC8* dataBuf = NULL; |
|
86 if(aParams.CreateGraphic->iRemoteReadData) |
|
87 { |
|
88 const TInt len = aParams.CreateGraphic->iDataLen; |
|
89 if ((len >= KMaxTInt/4) || (len < 0)) |
|
90 aClient->PPanic(EWservPanicBuffer); |
|
91 dataBuf = HBufC8::NewLC(len); |
|
92 TPtr8 des = dataBuf->Des(); |
|
93 aClient->RemoteRead(des,0); |
|
94 if(des.Size() != len) |
|
95 { |
|
96 aClient->PPanic(EWservPanicBuffer); |
|
97 } |
|
98 data.Set(des); |
|
99 } |
|
100 else |
|
101 { |
|
102 data.Set(CWsClient::BufferTPtr8((TText8*)(aParams.CreateGraphic+1),aParams.CreateGraphic->iDataLen)); |
|
103 } |
|
104 |
|
105 CWsGraphicDrawerObject* drawer = new(ELeave) CWsGraphicDrawerObject(aClient); |
|
106 CleanupStack::PushL(drawer); |
|
107 drawer->ConstructL(aParams.CreateGraphic->iType,aClient->WindowServer(),id,data,aParams.CreateGraphic->iClientHandle); |
|
108 if(!dup) |
|
109 { |
|
110 User::LeaveIfError(aClient->WindowServer().AddGraphicDrawer(drawer->Drawer())); |
|
111 } |
|
112 else |
|
113 { |
|
114 User::LeaveIfError(aClient->WindowServer().SwapGraphicDrawer(drawer->Drawer())); |
|
115 } |
|
116 // take off cleanup stack |
|
117 CleanupStack::Pop(drawer); |
|
118 if(dataBuf) |
|
119 { |
|
120 CleanupStack::PopAndDestroy(dataBuf); |
|
121 } |
|
122 // delete dup, which means resolving the object that encapsulates it |
|
123 if(dup) |
|
124 { |
|
125 CWsGraphicDrawerObject* obj = aClient->DrawerObject(dup); |
|
126 WS_ASSERT_DEBUG(obj, EWsPanicWsGraphic); |
|
127 if(obj) |
|
128 { |
|
129 obj->CloseObject(); |
|
130 } |
|
131 } |
|
132 // trigger redraws if anyone is drawing this graphic before it exists |
|
133 if(id.iIsUid) |
|
134 { |
|
135 aClient->WindowServer().Invalidate(id); |
|
136 } |
|
137 // done |
|
138 return drawer; |
|
139 } |
|
140 |
|
141 CWsGraphicDrawerObject::CWsGraphicDrawerObject(CWsClient* aOwner): |
|
142 CWsObject(aOwner,WS_HANDLE_GRAPHIC_DRAWER) |
|
143 { |
|
144 } |
|
145 |
|
146 CWsGraphicDrawerObject::~CWsGraphicDrawerObject() |
|
147 { |
|
148 delete iDrawer; |
|
149 } |
|
150 |
|
151 void CWsGraphicDrawerObject::ConstructL(TUid aType,MWsGraphicDrawerEnvironment& aEnv,const TGraphicDrawerId& aId,const TDesC8& aData,TInt aClientHandle) |
|
152 { |
|
153 CWsGraphicDrawer* drawer = WsGraphicDrawer::CreateLC(aType,aEnv,aId,*WsOwner(),aData); |
|
154 NewObjL(); |
|
155 iClientHandle = aClientHandle; |
|
156 iDrawer=drawer; |
|
157 CleanupStack::Pop(iDrawer); |
|
158 } |
|
159 |
|
160 void CWsGraphicDrawerObject::CommandL(TInt aOpcode, const TAny *aCmdData) |
|
161 { |
|
162 WS_ASSERT_DEBUG(iDrawer, EWsPanicWsGraphic); |
|
163 |
|
164 if(iDrawer) |
|
165 { |
|
166 TWsClCmdUnion pData; |
|
167 pData.any = aCmdData; |
|
168 switch(aOpcode) |
|
169 { |
|
170 case EWsGdOpFree: |
|
171 WsOwner()->WindowServer().RemoveGraphicDrawer(iDrawer->Id()); |
|
172 CloseObject(); |
|
173 return; |
|
174 case EWsGdOpSendMsg: |
|
175 case EWsGdOpSendSynchronMsg: |
|
176 { |
|
177 const TWsClCmdGdSendMessage& cmd = *pData.GraphicSendMessage; |
|
178 __ASSERT_DEBUG(cmd.iDataLen,WsOwner()->PPanic(EWservPanicPermissionDenied)); |
|
179 if(cmd.iDataLen) |
|
180 { |
|
181 if(cmd.iRemoteReadData) |
|
182 { |
|
183 HBufC8* wsAlloc = NULL; |
|
184 TUint8* drawerAlloc = NULL; |
|
185 TPtr8 des(NULL,0); |
|
186 // try to get the drawer to allocate for us |
|
187 MWsGraphicDrawerMessageAlloc* drawerAllocator = iDrawer->ObjectInterface<MWsGraphicDrawerMessageAlloc>(); |
|
188 if(drawerAllocator) |
|
189 { |
|
190 drawerAlloc = reinterpret_cast<TUint8*>(drawerAllocator->Alloc(cmd.iDataLen)); |
|
191 if(drawerAlloc) |
|
192 des.Set(drawerAlloc,0,cmd.iDataLen); |
|
193 } |
|
194 // else use the normal WSERV default heap |
|
195 if(!drawerAlloc) |
|
196 { |
|
197 wsAlloc = HBufC8::NewLC(cmd.iDataLen); |
|
198 des.Set(wsAlloc->Des()); |
|
199 } |
|
200 // fetch |
|
201 WsOwner()->RemoteRead(des,0); |
|
202 TBool receivedOk = (des.Size() == cmd.iDataLen); |
|
203 // dispatch |
|
204 if(receivedOk) |
|
205 { |
|
206 if(aOpcode == EWsGdOpSendMsg) |
|
207 { |
|
208 iDrawer->HandleMessage(des); |
|
209 } |
|
210 else |
|
211 { |
|
212 MWsGraphicHandleSynchronMessage* obj = iDrawer->ObjectInterface<MWsGraphicHandleSynchronMessage>(); |
|
213 |
|
214 if(obj) |
|
215 SetReply(obj->HandleSynchronMessage(des)); |
|
216 else |
|
217 SetReply(KErrNotSupported); |
|
218 } |
|
219 } |
|
220 |
|
221 // dealloc |
|
222 if(drawerAlloc) |
|
223 { |
|
224 drawerAllocator->Free(drawerAlloc); |
|
225 } |
|
226 else |
|
227 { |
|
228 CleanupStack::PopAndDestroy(wsAlloc); |
|
229 } |
|
230 // defer panic until after dealloc |
|
231 if(!receivedOk) |
|
232 { |
|
233 WsOwner()->PPanic(EWservPanicBuffer); |
|
234 } |
|
235 } |
|
236 else |
|
237 { |
|
238 const TPtrC8 data = CWsClient::BufferTPtr8((TText8*)(pData.GraphicSendMessage+1),cmd.iDataLen); |
|
239 if(aOpcode == EWsGdOpSendMsg) |
|
240 { |
|
241 iDrawer->HandleMessage(data); |
|
242 } |
|
243 else |
|
244 { |
|
245 MWsGraphicHandleSynchronMessage* obj = iDrawer->ObjectInterface<MWsGraphicHandleSynchronMessage>(); |
|
246 if(obj) |
|
247 SetReply(obj->HandleSynchronMessage(data)); |
|
248 else |
|
249 SetReply(KErrNotSupported); |
|
250 } |
|
251 } |
|
252 } |
|
253 } |
|
254 break; |
|
255 case EWsGdOpGetGraphicId: |
|
256 { |
|
257 __ASSERT_COMPILE(sizeof(TWsClCmdGdGetId) == sizeof(TGraphicDrawerId)); |
|
258 const TGraphicDrawerId id = iDrawer->Id(); |
|
259 CWsClient::ReplyBuf(&id,sizeof(id)); |
|
260 } |
|
261 break; |
|
262 case EWsGdOpShareGlobally: |
|
263 SetReply(iDrawer->ShareGlobally()); |
|
264 break; |
|
265 case EWsGdOpUnShareGlobally: |
|
266 SetReply(iDrawer->UnShareGlobally()); |
|
267 break; |
|
268 case EWsGdOpShare: |
|
269 { |
|
270 const TSecureId& secid = *reinterpret_cast<const TSecureId*>(aCmdData); |
|
271 SetReply(iDrawer->Share(secid)); |
|
272 break; |
|
273 } |
|
274 case EWsGdOpUnShare: |
|
275 { |
|
276 const TSecureId& secid = *reinterpret_cast<const TSecureId*>(aCmdData); |
|
277 SetReply(iDrawer->UnShare(secid)); |
|
278 break; |
|
279 } |
|
280 default: |
|
281 WsOwner()->PPanic(EWservPanicOpcode); |
|
282 } |
|
283 } |
|
284 } |
|
285 |
|
286 CWsGraphicDrawer* CWsGraphicDrawerObject::Drawer() |
|
287 { |
|
288 return iDrawer; |
|
289 } |
|
290 |
|
291 const CWsGraphicDrawer* CWsGraphicDrawerObject::Drawer() const |
|
292 { |
|
293 return iDrawer; |
|
294 } |
|
295 |
|
296 // CWsGraphicMessageQueue \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
|
297 |
|
298 CWsGraphicMessageQueue::CMessage* CWsGraphicMessageQueue::CMessage::New(const TDesC8& aData) |
|
299 { |
|
300 return new(aData.Size()) CMessage(aData); |
|
301 } |
|
302 |
|
303 CWsGraphicMessageQueue::CMessage::CMessage(const TDesC8& aData): |
|
304 iData((reinterpret_cast<TUint8*>(this)+sizeof(*this)),aData.Size()) |
|
305 { |
|
306 iData = aData; |
|
307 } |
|
308 |
|
309 TPtrC8 CWsGraphicMessageQueue::CMessage::Data() const |
|
310 { |
|
311 return iData; |
|
312 } |
|
313 |
|
314 void CWsGraphicMessageQueue::CMessage::Release() |
|
315 { |
|
316 delete this; |
|
317 } |
|
318 |
|
319 CWsGraphicMessageQueue::CMessage::~CMessage() |
|
320 { |
|
321 } |
|
322 |
|
323 CWsGraphicMessageQueue::CWsGraphicMessageQueue(CWsClient *aOwner): |
|
324 CEventBase(aOwner) |
|
325 { |
|
326 } |
|
327 |
|
328 CWsGraphicMessageQueue::~CWsGraphicMessageQueue() |
|
329 { |
|
330 while(iHead) |
|
331 { |
|
332 CWsMessageData* msg = iHead; |
|
333 iHead = iHead->iNext; |
|
334 msg->Release(); |
|
335 } |
|
336 } |
|
337 |
|
338 TInt CWsGraphicMessageQueue::TopClientHandle() const |
|
339 { |
|
340 if(iHead) |
|
341 return iHead->iClientHandle; |
|
342 else |
|
343 return KErrNotFound; |
|
344 } |
|
345 |
|
346 /** |
|
347 same functionality as CEventBase::GetData, but this one also inserts the integer header in the reply. |
|
348 */ |
|
349 void CWsGraphicMessageQueue::GetDataWithHeader(TUint aHeader, const TDesC8& aData, TInt aDataLen) |
|
350 { |
|
351 TPckgBuf<TUint> hdr = aHeader | (EWsGraphMessageTypeUser & 0x03); |
|
352 CWsClient::ReplyBuf(hdr.Ptr(), sizeof(TUint)); |
|
353 GetData((void*)aData.Ptr(), aDataLen); |
|
354 } |
|
355 |
|
356 void CWsGraphicMessageQueue::GetGraphicMessage() |
|
357 { |
|
358 CWsMessageData* top = Pop(); |
|
359 WS_ASSERT_DEBUG(top && top->Data().Length(), EWsPanicWsGraphic); |
|
360 if(top) |
|
361 { |
|
362 GetDataWithHeader(top->iClientHandle, top->Data(), top->Data().Size()); |
|
363 CWsGraphicDrawerObject* obj = iWsOwner->DrawerObject(top->iDrawer); |
|
364 if(obj) |
|
365 { |
|
366 MWsGraphicMessageCallback* messageCallback = obj->Drawer()->ObjectInterface<MWsGraphicMessageCallback>(); |
|
367 if(messageCallback) |
|
368 { |
|
369 messageCallback->HandleMessageDelivery(top->iId, KErrNone); |
|
370 } |
|
371 } |
|
372 |
|
373 top->Release(); |
|
374 } |
|
375 } |
|
376 |
|
377 void CWsGraphicMessageQueue::AbortMessage(TInt aError) |
|
378 { |
|
379 CWsMessageData* top = Pop(); |
|
380 WS_ASSERT_DEBUG(top, EWsPanicWsGraphic); |
|
381 if(top) |
|
382 { |
|
383 CWsGraphicDrawerObject* obj = iWsOwner->DrawerObject(top->iDrawer); |
|
384 if(obj) |
|
385 { |
|
386 MWsGraphicMessageCallback* messageCallback = obj->Drawer()->ObjectInterface<MWsGraphicMessageCallback>(); |
|
387 if(messageCallback) |
|
388 { |
|
389 messageCallback->HandleMessageDelivery(top->iId, aError); |
|
390 } |
|
391 } |
|
392 top->Release(); |
|
393 } |
|
394 } |
|
395 |
|
396 void CWsGraphicMessageQueue::EventReady(const RMessagePtr2& aEventMsg) |
|
397 { |
|
398 CEventBase::EventReady(aEventMsg); |
|
399 if(iHead) |
|
400 { |
|
401 SignalEvent(sizeof(TInt) + iHead->Data().Size()); |
|
402 } |
|
403 } |
|
404 |
|
405 |
|
406 void CWsGraphicMessageQueue::Queue(CWsMessageData* aMessage) |
|
407 { |
|
408 WS_ASSERT_DEBUG(aMessage && !aMessage->iNext, EWsPanicWsGraphic); |
|
409 if(aMessage) |
|
410 { |
|
411 if(iHead) |
|
412 { |
|
413 iTail->iNext = aMessage; |
|
414 iTail = aMessage; |
|
415 } |
|
416 else |
|
417 { |
|
418 iHead = iTail = aMessage; |
|
419 if(!iEventMsg.IsNull()) |
|
420 SignalEvent(sizeof(TInt) + iHead->Data().Size()); |
|
421 } |
|
422 } |
|
423 } |
|
424 |
|
425 CWsMessageData* CWsGraphicMessageQueue::Pop() |
|
426 { |
|
427 CWsMessageData* ret = NULL; |
|
428 if(iHead) |
|
429 { |
|
430 ret = iHead; |
|
431 iHead = iHead->iNext; |
|
432 } |
|
433 return ret; |
|
434 } |