|
1 // session.cpp |
|
2 // |
|
3 // Copyright (c) 2006 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include "server.h" |
|
14 #include "pipe.h" |
|
15 #include "console.h" |
|
16 #include "file.h" |
|
17 #include "null.h" |
|
18 #include "persistentconsole.h" |
|
19 #include "readwrite.h" |
|
20 #include "clientserver.h" |
|
21 #include "session.h" |
|
22 |
|
23 |
|
24 CIoSession::CIoSession() |
|
25 { |
|
26 } |
|
27 |
|
28 CIoServer& CIoSession::Server() |
|
29 { |
|
30 #ifdef EKA2 |
|
31 return *static_cast<CIoServer*>(const_cast<CServer2*>(CSession2::Server())); |
|
32 #else |
|
33 return *static_cast<CIoServer*>(const_cast<CServer*>(CSharableSession::Server())); |
|
34 #endif |
|
35 } |
|
36 |
|
37 #ifdef EKA2 |
|
38 void CIoSession::CreateL() |
|
39 #else |
|
40 void CIoSession::CreateL(const CServer& aServer) |
|
41 #endif |
|
42 { |
|
43 #ifndef EKA2 |
|
44 CSharableSession::CreateL(aServer); // does not leave |
|
45 #endif |
|
46 iHandles = CObjectIx::NewL(); |
|
47 Server().AddSession(); |
|
48 } |
|
49 |
|
50 CIoSession::~CIoSession() |
|
51 { |
|
52 delete iFindByNameMatch; |
|
53 const TInt maxNumObjects = iHandles->Count(); |
|
54 for (TInt i = 0; i < maxNumObjects; ++i) |
|
55 { |
|
56 CIoObject* obj = static_cast<CIoObject*>((*iHandles)[i]); |
|
57 if (obj != NULL) |
|
58 { |
|
59 obj->SessionClosed(*this); |
|
60 } |
|
61 } |
|
62 Server().DropSession(); |
|
63 delete iHandles; |
|
64 LOG(CIoLog::Printf(_L("CIoSession 0x%08x destroyed\r\n"), this)); |
|
65 } |
|
66 |
|
67 void CIoSession::ServiceL(const RMsg& aMessage) |
|
68 { |
|
69 LOG(CIoLog::StartServiceLC(aMessage)); |
|
70 |
|
71 switch (aMessage.Function()) |
|
72 { |
|
73 case EIoHandleSetOwner: |
|
74 { |
|
75 TThreadId owningThread(aMessage.Int0()); |
|
76 FindReadWriteObjectL(aMessage.Int3(), aMessage).SetOwnerL(owningThread); |
|
77 Complete(aMessage, KErrNone); |
|
78 break; |
|
79 } |
|
80 case EIoHandleSetUnderlyingConsole: |
|
81 { |
|
82 FindReadWriteObjectL(aMessage.Int3(), aMessage).SetConsole(FindConsoleL(aMessage.Int0(), aMessage)); |
|
83 Complete(aMessage, KErrNone); |
|
84 break; |
|
85 } |
|
86 case EIoHandleAttachedToConsole: |
|
87 { |
|
88 CIoReadWriteObject& obj = FindReadWriteObjectL(aMessage.Int3(), aMessage); |
|
89 if (obj.IsType(RIoHandle::EReadObject)) |
|
90 { |
|
91 Complete(aMessage, MIoReadEndPoint::AttachedToConsole((MIoReadEndPoint*)obj.EndPoint())); |
|
92 } |
|
93 else |
|
94 { |
|
95 Complete(aMessage, MIoWriteEndPoint::AttachedToConsole((MIoWriteEndPoint*)obj.EndPoint())); |
|
96 } |
|
97 break; |
|
98 } |
|
99 case EIoCreateReader: |
|
100 { |
|
101 CIoReadObject& readObj = Server().CreateReadObjLC(); |
|
102 LOG(CIoLog::Printf(_L("id: %d"), readObj.Id())); |
|
103 CreateHandleL(readObj, ETrue, aMessage); |
|
104 break; |
|
105 } |
|
106 case EIoOpenReaderByThreadId: |
|
107 { |
|
108 TThreadId clientThreadId(ClientThreadIdL(aMessage)); |
|
109 CIoReadObject* readObj = Server().NextReadObj(clientThreadId); |
|
110 if (readObj == NULL) |
|
111 { |
|
112 Complete(aMessage, KErrNotFound); |
|
113 } |
|
114 else |
|
115 { |
|
116 #ifdef EKA2 |
|
117 LOG(CIoLog::Printf(_L("thread id: %Lu"), clientThreadId.Id())); |
|
118 #else |
|
119 LOG(CIoLog::Printf(_L("thread id: %u"), clientThreadId)); |
|
120 #endif |
|
121 OBJ_NAME(*readObj); |
|
122 LOG(CIoLog::Printf(_L("name: \"%S\""), &objName)); |
|
123 User::LeaveIfError(readObj->Open(clientThreadId)); |
|
124 CleanupClosePushL(*readObj); |
|
125 CreateHandleL(*readObj, EFalse, aMessage); |
|
126 CleanupStack::Pop(); |
|
127 } |
|
128 break; |
|
129 } |
|
130 case EIoOpenReaderByExplicitThreadId: |
|
131 { |
|
132 TThreadId clientThreadId; |
|
133 TPckg<TThreadId> clientThreadIdPckg(clientThreadId); |
|
134 MessageReadL(aMessage, 0, clientThreadIdPckg); |
|
135 CIoReadObject* readObj = Server().NextReadObj(clientThreadId); |
|
136 if (readObj == NULL) |
|
137 { |
|
138 Complete(aMessage, KErrNotFound); |
|
139 } |
|
140 else |
|
141 { |
|
142 #ifdef EKA2 |
|
143 LOG(CIoLog::Printf(_L("thread id: %Lu"), clientThreadId.Id())); |
|
144 #else |
|
145 LOG(CIoLog::Printf(_L("thread id: %u"), clientThreadId)); |
|
146 #endif |
|
147 OBJ_NAME(*readObj); |
|
148 LOG(CIoLog::Printf(_L("name: \"%S\""), &objName)); |
|
149 User::LeaveIfError(readObj->Open(clientThreadId)); |
|
150 CleanupClosePushL(*readObj); |
|
151 CreateHandleL(*readObj, EFalse, aMessage); |
|
152 CleanupStack::Pop(); |
|
153 } |
|
154 break; |
|
155 } |
|
156 case EIoDuplicateReader: |
|
157 { |
|
158 CIoReadObject& readObj = FindReadObjectL(aMessage.Int3(), aMessage); |
|
159 CIoReadObject& duplicateReadObj = FindReadObjectL(aMessage.Int0(), aMessage); |
|
160 readObj.DuplicateL(duplicateReadObj); |
|
161 LOG(CIoLog::Printf(_L("Duplicating read object 0x%08x (id: %d) from 0x%08x (id: %d)"), &readObj, readObj.Id(), &duplicateReadObj, duplicateReadObj.Id())); |
|
162 Complete(aMessage, KErrNone); |
|
163 break; |
|
164 } |
|
165 case EIoDuplicateReaderHandleFromThread: |
|
166 { |
|
167 TThreadId threadId(aMessage.Int0()); |
|
168 CIoReadObject& readObj = FindReadObjectL(aMessage.Int3(), aMessage); |
|
169 CIoReadObject* otherThreadObj = Server().LastOpenedReadObj(threadId); |
|
170 if (otherThreadObj) |
|
171 { |
|
172 LOG(CIoLog::Printf(_L("Duplicating read object 0x%08x (id: %d) from 0x%08x (id: %d)"), &readObj, readObj.Id(), otherThreadObj, otherThreadObj->Id())); |
|
173 readObj.DuplicateL(*otherThreadObj); |
|
174 } |
|
175 else |
|
176 { |
|
177 User::Leave(KErrNotFound); |
|
178 } |
|
179 Complete(aMessage, KErrNone); |
|
180 break; |
|
181 } |
|
182 case EIoCreateWriter: |
|
183 { |
|
184 CIoWriteObject& writeObj = Server().CreateWriteObjLC(); |
|
185 LOG(CIoLog::Printf(_L("id: %d"), writeObj.Id())); |
|
186 CreateHandleL(writeObj, ETrue, aMessage); |
|
187 break; |
|
188 } |
|
189 case EIoOpenWriterByThreadId: |
|
190 { |
|
191 TThreadId clientThreadId(ClientThreadIdL(aMessage)); |
|
192 CIoWriteObject* writeObj = Server().NextWriteObj(clientThreadId); |
|
193 if (writeObj == NULL) |
|
194 { |
|
195 Complete(aMessage, KErrNotFound); |
|
196 } |
|
197 else |
|
198 { |
|
199 LOG(CIoLog::Printf(_L("thread id: %u"), TUint(clientThreadId))); |
|
200 OBJ_NAME(*writeObj); |
|
201 LOG(CIoLog::Printf(_L("name: \"%S\""), &objName)); |
|
202 User::LeaveIfError(writeObj->Open(clientThreadId)); |
|
203 CleanupClosePushL(*writeObj); |
|
204 CreateHandleL(*writeObj, EFalse, aMessage); |
|
205 CleanupStack::Pop(); |
|
206 } |
|
207 break; |
|
208 } |
|
209 case EIoOpenWriterByExplicitThreadId: |
|
210 { |
|
211 TThreadId clientThreadId; |
|
212 TPckg<TThreadId> clientThreadIdPckg(clientThreadId); |
|
213 MessageReadL(aMessage, 0, clientThreadIdPckg); |
|
214 CIoWriteObject* writeObj = Server().NextWriteObj(clientThreadId); |
|
215 if (writeObj == NULL) |
|
216 { |
|
217 Complete(aMessage, KErrNotFound); |
|
218 } |
|
219 else |
|
220 { |
|
221 LOG(CIoLog::Printf(_L("thread id: %u"), TUint(clientThreadId))); |
|
222 OBJ_NAME(*writeObj); |
|
223 LOG(CIoLog::Printf(_L("name: \"%S\""), &objName)); |
|
224 User::LeaveIfError(writeObj->Open(clientThreadId)); |
|
225 CleanupClosePushL(*writeObj); |
|
226 CreateHandleL(*writeObj, EFalse, aMessage); |
|
227 CleanupStack::Pop(); |
|
228 } |
|
229 break; |
|
230 } |
|
231 case EIoDuplicateWriter: |
|
232 { |
|
233 CIoWriteObject& writeObj = FindWriteObjectL(aMessage.Int3(), aMessage); |
|
234 CIoWriteObject& duplicateWriteObj = FindWriteObjectL(aMessage.Int0(), aMessage); |
|
235 writeObj.DuplicateL(duplicateWriteObj); |
|
236 LOG(CIoLog::Printf(_L("Duplicating write object 0x%08x (id: %d) from 0x%08x (id: %d)"), &writeObj, writeObj.Id(), &duplicateWriteObj, duplicateWriteObj.Id())); |
|
237 Complete(aMessage, KErrNone); |
|
238 break; |
|
239 } |
|
240 case EIoDuplicateWriterHandleFromThread: |
|
241 { |
|
242 TThreadId threadId(aMessage.Int0()); |
|
243 CIoWriteObject& writeObj = FindWriteObjectL(aMessage.Int3(), aMessage); |
|
244 CIoWriteObject* otherThreadObj = Server().LastOpenedWriteObj(threadId); |
|
245 if (otherThreadObj) |
|
246 { |
|
247 LOG(CIoLog::Printf(_L("Duplicating write object 0x%08x (id: %d) from 0x%08x (id: %d)"), &writeObj, writeObj.Id(), otherThreadObj, otherThreadObj->Id())); |
|
248 writeObj.DuplicateL(*otherThreadObj); |
|
249 } |
|
250 else |
|
251 { |
|
252 User::Leave(KErrNotFound); |
|
253 } |
|
254 Complete(aMessage, KErrNone); |
|
255 break; |
|
256 } |
|
257 case EIoSetReadWriteMode: |
|
258 { |
|
259 FindReadWriteObjectL(aMessage.Int3(), aMessage).SetModeL(aMessage); |
|
260 break; |
|
261 } |
|
262 case EIoSetReadMode: |
|
263 { |
|
264 TInt mode(aMessage.Int0()); |
|
265 if ((mode >= RIoReadHandle::EFull) && (mode <= RIoReadHandle::EOneOrMore)) |
|
266 { |
|
267 FindReadObjectL(aMessage.Int3(), aMessage).SetReadMode((RIoReadHandle::TReadMode)mode); |
|
268 Complete(aMessage, KErrNone); |
|
269 } |
|
270 else |
|
271 { |
|
272 Complete(aMessage, KErrNotSupported); |
|
273 } |
|
274 break; |
|
275 } |
|
276 case EIoSetReaderToForeground: |
|
277 { |
|
278 FindReadObjectL(aMessage.Int3(), aMessage).SetToForegroundL(); |
|
279 Complete(aMessage, KErrNone); |
|
280 break; |
|
281 } |
|
282 case EIoRead: |
|
283 { |
|
284 FindReadObjectL(aMessage.Int3(), aMessage).ReadL(aMessage); |
|
285 break; |
|
286 } |
|
287 case EIoReadCancel: |
|
288 { |
|
289 FindReadObjectL(aMessage.Int3(), aMessage).ReadCancel(*this); |
|
290 Complete(aMessage, KErrNone); |
|
291 break; |
|
292 } |
|
293 case EIoSetLineSeparator: |
|
294 { |
|
295 FindReadObjectL(aMessage.Int3(), aMessage).SetLineSeparatorL(aMessage); |
|
296 break; |
|
297 } |
|
298 case EIoWrite: |
|
299 { |
|
300 FindWriteObjectL(aMessage.Int3(), aMessage).WriteL(aMessage); |
|
301 break; |
|
302 } |
|
303 case EIoWriteCancel: |
|
304 { |
|
305 FindWriteObjectL(aMessage.Int3(), aMessage).WriteCancel(*this); |
|
306 Complete(aMessage, KErrNone); |
|
307 break; |
|
308 } |
|
309 case EIoIsForegroundReader: |
|
310 { |
|
311 Complete(aMessage, FindReadObjectL(aMessage.Int3(), aMessage).IsForegroundL()); |
|
312 break; |
|
313 } |
|
314 case EIoConsoleWaitForKey: |
|
315 { |
|
316 FindReadObjectL(aMessage.Int3(), aMessage).ReadKeyL(aMessage); |
|
317 break; |
|
318 } |
|
319 case EIoConsoleWaitForKeyCancel: |
|
320 { |
|
321 FindReadObjectL(aMessage.Int3(), aMessage).ReadKeyCancel(*this); |
|
322 Complete(aMessage, KErrNone); |
|
323 break; |
|
324 } |
|
325 case EIoConsoleCaptureKey: |
|
326 { |
|
327 FindReadObjectL(aMessage.Int3(), aMessage).CaptureKeyL(aMessage); |
|
328 break; |
|
329 } |
|
330 case EIoConsoleCancelCaptureKey: |
|
331 { |
|
332 FindReadObjectL(aMessage.Int3(), aMessage).CancelCaptureKey(aMessage); |
|
333 break; |
|
334 } |
|
335 case EIoConsoleCaptureAllKeys: |
|
336 { |
|
337 FindReadObjectL(aMessage.Int3(), aMessage).CaptureAllKeys(aMessage); |
|
338 break; |
|
339 } |
|
340 case EIoConsoleCancelCaptureAllKeys: |
|
341 { |
|
342 FindReadObjectL(aMessage.Int3(), aMessage).CancelCaptureAllKeys(aMessage); |
|
343 break; |
|
344 } |
|
345 case EIoConsoleCursorPos: |
|
346 { |
|
347 FindWriteObjectL(aMessage.Int3(), aMessage).CursorPosL(aMessage); |
|
348 break; |
|
349 } |
|
350 case EIoConsoleSetCursorPosAbs: |
|
351 { |
|
352 FindWriteObjectL(aMessage.Int3(), aMessage).SetCursorPosAbsL(aMessage); |
|
353 break; |
|
354 } |
|
355 case EIoConsoleSetCursorPosRel: |
|
356 { |
|
357 FindWriteObjectL(aMessage.Int3(), aMessage).SetCursorPosRelL(aMessage); |
|
358 break; |
|
359 } |
|
360 case EIoConsoleSetCursorHeight: |
|
361 { |
|
362 FindWriteObjectL(aMessage.Int3(), aMessage).SetCursorHeightL(aMessage); |
|
363 break; |
|
364 } |
|
365 case EIoConsoleSetTitle: |
|
366 { |
|
367 FindWriteObjectL(aMessage.Int3(), aMessage).SetTitleL(aMessage); |
|
368 break; |
|
369 } |
|
370 case EIoConsoleClearScreen: |
|
371 { |
|
372 FindWriteObjectL(aMessage.Int3(), aMessage).ClearScreen(aMessage); |
|
373 break; |
|
374 } |
|
375 case EIoConsoleClearToEndOfLine: |
|
376 { |
|
377 FindWriteObjectL(aMessage.Int3(), aMessage).ClearToEndOfLine(aMessage); |
|
378 break; |
|
379 } |
|
380 case EIoConsoleScreenSize: |
|
381 { |
|
382 FindWriteObjectL(aMessage.Int3(), aMessage).ScreenSizeL(aMessage); |
|
383 break; |
|
384 } |
|
385 case EIoConsoleSetAttributes: |
|
386 { |
|
387 FindWriteObjectL(aMessage.Int3(), aMessage).SetAttributesL(aMessage); |
|
388 break; |
|
389 } |
|
390 case EIoCreatePipe: |
|
391 { |
|
392 CIoPipe& pipe = Server().CreatePipeLC(); |
|
393 CreateHandleL(pipe, ETrue, aMessage); |
|
394 break; |
|
395 } |
|
396 case EIoHandleClose: |
|
397 { |
|
398 const TInt handle = aMessage.Int3(); |
|
399 LOG(CIoLog::Printf(_L("handle: %d"), handle)); |
|
400 CIoObject* obj = (CIoObject*)iHandles->AtL(handle); // Leaves with KErrBadHandle if not found, which will result in client getting panic'd. |
|
401 obj->ClosedBy(*this); |
|
402 iHandles->Remove(handle); |
|
403 Complete(aMessage, KErrNone); |
|
404 break; |
|
405 } |
|
406 case EIoEndPointAttachReader: |
|
407 { |
|
408 CIoEndPoint& endPoint = FindEndPointL(aMessage.Int3(), aMessage); |
|
409 CIoReadObject& readObj = FindReadObjectL(aMessage.Int0(), aMessage); |
|
410 RIoEndPoint::TReadMode mode = (RIoEndPoint::TReadMode)aMessage.Int1(); |
|
411 LOG(CIoLog::Printf(_L("read obj id: %d, address: 0x%08x"), readObj.Id(), &readObj)); |
|
412 LOG(CIoLog::Printf(_L("end point handle: %d, address: 0x%08x"), aMessage.Int3(), &endPoint)); |
|
413 readObj.AttachL(endPoint, mode); |
|
414 Complete(aMessage, KErrNone); |
|
415 break; |
|
416 } |
|
417 case EIoEndPointAttachWriter: |
|
418 { |
|
419 CIoEndPoint& endPoint = FindEndPointL(aMessage.Int3(), aMessage); |
|
420 CIoWriteObject& writeObj = FindWriteObjectL(aMessage.Int0(), aMessage); |
|
421 LOG(CIoLog::Printf(_L("write obj id: %d, address: 0x%08x"), writeObj.Id(), &writeObj)); |
|
422 LOG(CIoLog::Printf(_L("end point handle: %d, address: 0x%08x"), aMessage.Int3(), &endPoint)); |
|
423 writeObj.AttachL(endPoint); |
|
424 Complete(aMessage, KErrNone); |
|
425 break; |
|
426 } |
|
427 case EIoEndPointSetForegroundReadHandle: |
|
428 { |
|
429 CIoEndPoint& endPoint = FindEndPointL(aMessage.Int3(), aMessage); |
|
430 CIoReadObject& readObj = FindReadObjectL(aMessage.Int0(), aMessage); |
|
431 LOG(CIoLog::Printf(_L("read obj id: %d, address: 0x%08x"), readObj.Id(), &readObj)); |
|
432 LOG(CIoLog::Printf(_L("end point handle: %d, address: 0x%08x"), aMessage.Int3(), &endPoint)); |
|
433 endPoint.IorepSetForegroundReaderL(readObj); |
|
434 Complete(aMessage, KErrNone); |
|
435 break; |
|
436 } |
|
437 case EIoCreateConsole: |
|
438 { |
|
439 HBufC* titleBuf = HBufC::NewLC(DesLengthL(aMessage, 0)); |
|
440 TPtr titlePtr(titleBuf->Des()); |
|
441 MessageReadL(aMessage, 0, titlePtr); |
|
442 TPckgBuf<TConsoleCreateParams> paramsPckg; |
|
443 MessageReadL(aMessage, 1, paramsPckg); |
|
444 HBufC* implBuf = HBufC::NewLC(DesLengthL(aMessage, 2)); |
|
445 TPtr implPtr(implBuf->Des()); |
|
446 MessageReadL(aMessage, 2, implPtr); |
|
447 CIoConsole* underlyingCons = NULL; |
|
448 if (paramsPckg().iUnderlyingConsoleHandle != KNullHandle) |
|
449 { |
|
450 underlyingCons = &FindConsoleL(paramsPckg().iUnderlyingConsoleHandle, aMessage); |
|
451 } |
|
452 CIoConsole& console = Server().CreateConsoleLC(*implBuf, *titleBuf, paramsPckg().iSize, underlyingCons, paramsPckg().iOptions); |
|
453 CreateHandleL(console, ETrue, aMessage); //pops console |
|
454 CleanupStack::PopAndDestroy(2, titleBuf); |
|
455 break; |
|
456 } |
|
457 case EIoOpenConsole: |
|
458 { |
|
459 CIoConsole* console = FindReadWriteObjectL(aMessage.Int0(), aMessage).Console(); |
|
460 if (console) |
|
461 { |
|
462 User::LeaveIfError(console->Open()); |
|
463 CleanupClosePushL(*console); |
|
464 CreateHandleL(*console, EFalse, aMessage); |
|
465 CleanupStack::Pop(); |
|
466 } |
|
467 else |
|
468 { |
|
469 Complete(aMessage, KErrNotFound); |
|
470 } |
|
471 break; |
|
472 } |
|
473 case EIoConsoleImplementation: |
|
474 { |
|
475 TInt clientDesLen = MaxDesLengthL(aMessage, 0); |
|
476 const TDesC& impl(FindConsoleL(aMessage.Int3(), aMessage).Implementation()); |
|
477 MessageWriteL(aMessage, 0, impl.Left(clientDesLen)); |
|
478 Complete(aMessage, impl.Length() > clientDesLen ? KErrOverflow : KErrNone); |
|
479 break; |
|
480 } |
|
481 case EIoCreateFile: |
|
482 { |
|
483 HBufC* fileNameBuf = HBufC::NewLC(DesLengthL(aMessage, 0)); |
|
484 TPtr fileNamePtr(fileNameBuf->Des()); |
|
485 MessageReadL(aMessage, 0, fileNamePtr); |
|
486 CIoFile& file = Server().CreateFileLC(*fileNameBuf, (RIoFile::TMode)aMessage.Int1()); |
|
487 CreateHandleL(file, ETrue, aMessage); |
|
488 CleanupStack::PopAndDestroy(fileNameBuf); |
|
489 break; |
|
490 } |
|
491 case EIoCreateNull: |
|
492 { |
|
493 CIoNull& null = Server().CreateNullLC(); |
|
494 CreateHandleL(null, ETrue, aMessage); |
|
495 break; |
|
496 } |
|
497 case EIoSetObjectName: |
|
498 { |
|
499 CObject* obj = iHandles->AtL(aMessage.Int0()); |
|
500 HBufC* name = HBufC::NewLC(DesLengthL(aMessage, 1)); |
|
501 TPtr namePtr(name->Des()); |
|
502 MessageReadL(aMessage, 1, namePtr); |
|
503 LOG(CIoLog::Printf(_L("Setting object (handle: %d, address: 0x%08x) to \"%S\""), aMessage.Int0(), &obj, name)); |
|
504 TPtrC truncatedName(name->Left(KMaxName)); |
|
505 obj->SetName(&truncatedName); |
|
506 CleanupStack::PopAndDestroy(name); |
|
507 Complete(aMessage, KErrNone); |
|
508 break; |
|
509 } |
|
510 case EIoCreatePersistentConsole: |
|
511 { |
|
512 HBufC* nameBuf = HBufC::NewLC(DesLengthL(aMessage, 1)); |
|
513 TPtr namePtr(nameBuf->Des()); |
|
514 MessageReadL(aMessage, 0, namePtr); |
|
515 |
|
516 HBufC* titleBuf = HBufC::NewLC(DesLengthL(aMessage, 0)); |
|
517 TPtr titlePtr(titleBuf->Des()); |
|
518 MessageReadL(aMessage, 1, titlePtr); |
|
519 |
|
520 CIoPersistentConsole& pcons = Server().CreatePersistentConsoleLC(*nameBuf, *titleBuf, aMessage); |
|
521 CreateHandleL(pcons, ETrue, aMessage); |
|
522 CleanupStack::PopAndDestroy(2, nameBuf); |
|
523 break; |
|
524 } |
|
525 case EIoOpenPersistentConsoleByName: |
|
526 { |
|
527 HBufC* nameBuf = HBufC::NewLC(DesLengthL(aMessage, 0)); |
|
528 TPtr namePtr(nameBuf->Des()); |
|
529 MessageReadL(aMessage, 0, namePtr); |
|
530 |
|
531 CIoPersistentConsole& pcons = Server().FindPersistentConsoleL(*nameBuf); |
|
532 User::LeaveIfError(pcons.Open()); |
|
533 CleanupClosePushL(pcons); |
|
534 CreateHandleL(pcons, EFalse, aMessage); |
|
535 CleanupStack::Pop(&pcons); |
|
536 CleanupStack::PopAndDestroy(nameBuf); |
|
537 break; |
|
538 }; |
|
539 case EIoPersistentConsoleAttachReadEndPoint: |
|
540 { |
|
541 CIoPersistentConsole& pcons = FindPersistentConsoleL(aMessage.Int3(), aMessage); |
|
542 CIoEndPoint& endPoint = FindEndPointL(aMessage.Int0(), aMessage); |
|
543 RIoPersistentConsole::TCloseBehaviour onClose = (RIoPersistentConsole::TCloseBehaviour)aMessage.Int1(); |
|
544 pcons.AttachTransientReaderL(endPoint, onClose == RIoPersistentConsole::EDetachOnHandleClose ? this : NULL); |
|
545 Complete(aMessage, KErrNone); |
|
546 break; |
|
547 } |
|
548 case EIoPersistentConsoleAttachWriteEndPoint: |
|
549 { |
|
550 CIoPersistentConsole& pcons = FindPersistentConsoleL(aMessage.Int3(), aMessage); |
|
551 CIoEndPoint& endPoint = FindEndPointL(aMessage.Int0(), aMessage); |
|
552 RIoPersistentConsole::TCloseBehaviour onClose = (RIoPersistentConsole::TCloseBehaviour)aMessage.Int1(); |
|
553 pcons.AttachTransientWriterL(endPoint, onClose == RIoPersistentConsole::EDetachOnHandleClose ? this : NULL); |
|
554 Complete(aMessage, KErrNone); |
|
555 break; |
|
556 } |
|
557 case EIoPersistentConsoleDetachReadEndPoint: |
|
558 { |
|
559 CIoPersistentConsole& pcons = FindPersistentConsoleL(aMessage.Int3(), aMessage); |
|
560 pcons.DetachTransientReader(); |
|
561 Complete(aMessage, KErrNone); |
|
562 break; |
|
563 } |
|
564 case EIoPersistentConsoleDetachWriteEndPoint: |
|
565 { |
|
566 CIoPersistentConsole& pcons = FindPersistentConsoleL(aMessage.Int3(), aMessage); |
|
567 pcons.DetachTransientWriter(); |
|
568 Complete(aMessage, KErrNone); |
|
569 break; |
|
570 } |
|
571 case EIoPersistentConsoleNotifyReadDetach: |
|
572 { |
|
573 CIoPersistentConsole& pcons = FindPersistentConsoleL(aMessage.Int3(), aMessage); |
|
574 pcons.NotifyReadDetachL(aMessage); |
|
575 break; |
|
576 } |
|
577 case EIoPersistentConsoleNotifyWriteDetach: |
|
578 { |
|
579 CIoPersistentConsole& pcons = FindPersistentConsoleL(aMessage.Int3(), aMessage); |
|
580 pcons.NotifyWriteDetachL(aMessage); |
|
581 break; |
|
582 } |
|
583 case EIoPersistentConsoleCancelNotifyReadDetach: |
|
584 { |
|
585 CIoPersistentConsole& pcons = FindPersistentConsoleL(aMessage.Int3(), aMessage); |
|
586 pcons.CancelNotifyReadDetach((TRequestStatus*)aMessage.Int0()); |
|
587 break; |
|
588 } |
|
589 case EIoPersistentConsoleCancelNotifyWriteDetach: |
|
590 { |
|
591 CIoPersistentConsole& pcons = FindPersistentConsoleL(aMessage.Int3(), aMessage); |
|
592 pcons.CancelNotifyWriteDetach((TRequestStatus*)aMessage.Int0()); |
|
593 break; |
|
594 } |
|
595 case EIoPersistentConsoleGetAttachedNames: |
|
596 { |
|
597 CIoPersistentConsole& pcons = FindPersistentConsoleL(aMessage.Int3(), aMessage); |
|
598 MessageWriteL(aMessage, 0, pcons.TransientReaderName()); |
|
599 MessageWriteL(aMessage, 1, pcons.TransientWriterName()); |
|
600 Complete(aMessage, KErrNone); |
|
601 break; |
|
602 } |
|
603 case EIoPersistentConsoleGetCreatorThreadId: |
|
604 { |
|
605 CIoPersistentConsole& pcons = FindPersistentConsoleL(aMessage.Int3(), aMessage); |
|
606 MessageWriteL(aMessage, 0, TPckg<TThreadId>(pcons.Creator())); |
|
607 Complete(aMessage, KErrNone); |
|
608 break; |
|
609 } |
|
610 case EIoHandleIsType: |
|
611 { |
|
612 CIoObject& obj = FindObjectL(aMessage.Int3()); |
|
613 Complete(aMessage, obj.IsType((RIoHandle::TType)aMessage.Int0())); |
|
614 break; |
|
615 } |
|
616 case EIoFindFirstHandle: |
|
617 { |
|
618 iFindByNameType = (RIoHandle::TType)aMessage.Int0(); |
|
619 |
|
620 delete iFindByNameMatch; |
|
621 iFindByNameMatch = NULL; |
|
622 iFindByNameMatch = HBufC::NewL(DesLengthL(aMessage, 1)); |
|
623 TPtr matchPtr(iFindByNameMatch->Des()); |
|
624 MessageReadL(aMessage, 1, matchPtr); |
|
625 |
|
626 TName foundName; |
|
627 iFindByNameHandle = 0; |
|
628 CIoObject* obj = Server().FindObjectByName(iFindByNameType, iFindByNameHandle, *iFindByNameMatch, foundName); |
|
629 if (obj) |
|
630 { |
|
631 MessageWriteL(aMessage, 2, TPckg<TInt>(iFindByNameHandle)); |
|
632 MessageWriteL(aMessage, 3, foundName); |
|
633 Complete(aMessage, KErrNone); |
|
634 } |
|
635 else |
|
636 { |
|
637 Complete(aMessage, KErrNotFound); |
|
638 } |
|
639 break; |
|
640 } |
|
641 case EIoFindNextHandle: |
|
642 { |
|
643 if (!(iFindByNameMatch && iFindByNameHandle)) |
|
644 { |
|
645 PanicClient(aMessage, EPanicFindNextWithNoFindFirst); |
|
646 break; |
|
647 } |
|
648 |
|
649 TName foundName; |
|
650 CIoObject* obj = Server().FindObjectByName(iFindByNameType, iFindByNameHandle, *iFindByNameMatch, foundName); |
|
651 if (obj) |
|
652 { |
|
653 MessageWriteL(aMessage, 0, TPckg<TInt>(iFindByNameHandle)); |
|
654 MessageWriteL(aMessage, 1, foundName); |
|
655 Complete(aMessage, KErrNone); |
|
656 } |
|
657 else |
|
658 { |
|
659 Complete(aMessage, KErrNotFound); |
|
660 } |
|
661 break; |
|
662 } |
|
663 case EIoOpenFoundHandle: |
|
664 { |
|
665 if (!(iFindByNameMatch && iFindByNameHandle)) |
|
666 { |
|
667 PanicClient(aMessage, EPanicOpenFoundWithNoFind); |
|
668 break; |
|
669 } |
|
670 |
|
671 CIoObject& obj = Server().OpenObjectLC(aMessage.Int0()); |
|
672 CreateHandleL(obj, EFalse, aMessage); |
|
673 CleanupStack::Pop(&obj); |
|
674 break; |
|
675 } |
|
676 case EIoHandleGetName: |
|
677 { |
|
678 CIoObject& obj = FindObjectL(aMessage.Int3()); |
|
679 TName name(obj.Name()); |
|
680 MessageWriteL(aMessage, 0, name.Left(MaxDesLengthL(aMessage, 0))); |
|
681 Complete(aMessage, MaxDesLengthL(aMessage, 0) < name.Length() ? KErrOverflow : KErrNone); |
|
682 break; |
|
683 }; |
|
684 case EIoHandleEquals: |
|
685 { |
|
686 CIoObject& tweedledee = FindObjectL(aMessage.Int3()); |
|
687 CIoObject& tweedledum = FindObjectL(aMessage.Int0()); |
|
688 Complete(aMessage, &tweedledee == &tweedledum); |
|
689 break; |
|
690 }; |
|
691 case EIoReadHandleNotifyChange: |
|
692 { |
|
693 CIoReadObject& readObj = FindReadObjectL(aMessage.Int3(), aMessage); |
|
694 readObj.NotifyChange(aMessage); |
|
695 break; |
|
696 } |
|
697 case EIoReadHandleCancelNotifyChange: |
|
698 { |
|
699 CIoReadObject& readObj = FindReadObjectL(aMessage.Int3(), aMessage); |
|
700 readObj.CancelNotifyChange(*this); |
|
701 Complete(aMessage, KErrNone); |
|
702 break; |
|
703 } |
|
704 case EIoSetIsStdErr: |
|
705 { |
|
706 FindWriteObjectL(aMessage.Int3(), aMessage).SetIsStdErr((TBool)aMessage.Int0()); |
|
707 Complete(aMessage, KErrNone); |
|
708 break; |
|
709 } |
|
710 default: |
|
711 { |
|
712 PanicClient(aMessage, EPanicUnknownOpcode); |
|
713 break; |
|
714 } |
|
715 } |
|
716 |
|
717 LOG(CleanupStack::PopAndDestroy()); |
|
718 } |
|
719 |
|
720 void CIoSession::CreateHandleL(CObject& aObject, TBool aDoPop, const RMsg& aMessage) |
|
721 { |
|
722 const TInt handle = iHandles->AddL(&aObject); |
|
723 if (aDoPop) |
|
724 { |
|
725 CleanupStack::Pop(&aObject); |
|
726 } |
|
727 TPckgC<TInt> handlePckg(handle); |
|
728 TRAPD(err, MessageWriteL(aMessage, 3, handlePckg)); |
|
729 if (err) |
|
730 { |
|
731 iHandles->Remove(handle); |
|
732 User::Leave(err); |
|
733 } |
|
734 LOG(CIoLog::Printf(_L("Created handle %d"), handle)); |
|
735 Complete(aMessage, err); |
|
736 } |
|
737 |
|
738 CIoObject& CIoSession::FindObjectL(TInt aHandle) |
|
739 { |
|
740 CIoObject* obj = static_cast<CIoObject*>(iHandles->AtL(aHandle)); |
|
741 return *obj; |
|
742 } |
|
743 |
|
744 CIoEndPoint& CIoSession::FindEndPointL(TInt aHandle, const RMsg& aMessage) |
|
745 { |
|
746 CIoObject* obj = static_cast<CIoObject*>(iHandles->AtL(aHandle)); |
|
747 __ASSERT_ALWAYS(obj->IsType(RIoHandle::EEndPoint), PanicClient(aMessage, EPanicNotAnEndPoint)); |
|
748 return *static_cast<CIoEndPoint*>(obj); |
|
749 } |
|
750 |
|
751 CIoPipe& CIoSession::FindPipeL(TInt aHandle, const RMsg& aMessage) |
|
752 { |
|
753 CIoObject* obj = static_cast<CIoObject*>(iHandles->AtL(aHandle)); |
|
754 __ASSERT_ALWAYS(obj->IsType(RIoHandle::EPipe), PanicClient(aMessage, EPanicNotAPipe)); |
|
755 return *static_cast<CIoPipe*>(obj); |
|
756 } |
|
757 |
|
758 CIoConsole& CIoSession::FindConsoleL(TInt aHandle, const RMsg& aMessage) |
|
759 { |
|
760 CIoObject* obj = static_cast<CIoObject*>(iHandles->AtL(aHandle)); |
|
761 __ASSERT_ALWAYS(obj->IsType(RIoHandle::EConsole), PanicClient(aMessage, EPanicNotAConsole)); |
|
762 return *static_cast<CIoConsole*>(obj); |
|
763 } |
|
764 |
|
765 CIoPersistentConsole& CIoSession::FindPersistentConsoleL(TInt aHandle, const RMsg& aMessage) |
|
766 { |
|
767 CIoObject* obj = static_cast<CIoObject*>(iHandles->AtL(aHandle)); |
|
768 __ASSERT_ALWAYS(obj->IsType(RIoHandle::EPersistentConsole), PanicClient(aMessage, EPanicNotAPersistentConsole)); |
|
769 return *static_cast<CIoPersistentConsole*>(obj); |
|
770 } |
|
771 |
|
772 CIoReadWriteObject& CIoSession::FindReadWriteObjectL(TInt aHandle, const RMsg& aMessage) |
|
773 { |
|
774 CIoObject* obj = static_cast<CIoObject*>(iHandles->AtL(aHandle)); |
|
775 __ASSERT_ALWAYS(obj->IsType(RIoHandle::EReadWriteObject), PanicClient(aMessage, EPanicNotAReadWriteObject)); |
|
776 return *static_cast<CIoReadWriteObject*>(obj); |
|
777 } |
|
778 |
|
779 CIoReadObject& CIoSession::FindReadObjectL(TInt aHandle, const RMsg& aMessage) |
|
780 { |
|
781 CIoObject* obj = static_cast<CIoObject*>(iHandles->AtL(aHandle)); |
|
782 __ASSERT_ALWAYS(obj->IsType(RIoHandle::EReadObject), PanicClient(aMessage, EPanicNotAReadObject)); |
|
783 return *static_cast<CIoReadObject*>(obj); |
|
784 } |
|
785 |
|
786 CIoWriteObject& CIoSession::FindWriteObjectL(TInt aHandle, const RMsg& aMessage) |
|
787 { |
|
788 CIoObject* obj = static_cast<CIoObject*>(iHandles->AtL(aHandle)); |
|
789 __ASSERT_ALWAYS(obj->IsType(RIoHandle::EWriteObject), PanicClient(aMessage, EPanicNotAWriteObject)); |
|
790 return *static_cast<CIoWriteObject*>(obj); |
|
791 } |
|
792 |
|
793 void CIoSession::Complete(const RMsg& aMessage, TInt aError) |
|
794 { |
|
795 LOG(CIoLog::LogCompletion(aMessage, aError)); |
|
796 aMessage.Complete(aError); |
|
797 } |