|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Definitions for the client side handle class RATStorageServer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "atstorageserverclnt.h" |
|
22 #include "atstorageserver.h" |
|
23 #include "atlog.h" |
|
24 #include "atstorageservercommon.h" |
|
25 |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // RATStorageServer::RATStorageServer |
|
33 // C++ default constructor. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 EXPORT_C RATStorageServer::RATStorageServer() : |
|
37 RSessionBase(), iStackBuf( NULL ) |
|
38 { |
|
39 LOGSTR1( "STSE RATStorageServer::RATStorageServer()" ); |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // RATStorageServer::Connect |
|
44 // A function for connecting to the server |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 EXPORT_C TInt RATStorageServer::Connect() |
|
48 { |
|
49 LOGSTR1( "STSE TInt RATStorageServer::Connect()" ); |
|
50 |
|
51 TInt errorCode( KErrNone ); |
|
52 errorCode = CreateProcess(); |
|
53 |
|
54 // If process's creation failed, return the error code |
|
55 if ( errorCode != KErrNone ) |
|
56 { |
|
57 return errorCode; |
|
58 } |
|
59 |
|
60 // Otherwise create a new session |
|
61 errorCode = CreateSession( KStorageServerName, Version() ); |
|
62 |
|
63 // If creation of a new session failed, return the error code |
|
64 if ( errorCode != KErrNone ) |
|
65 { |
|
66 return errorCode; |
|
67 } |
|
68 |
|
69 // Construct a buffer for call stack's memory addresses. If the function leaves, |
|
70 // the leave code is put in "errorCode". |
|
71 TRAP( errorCode, ConstructBuffersL() ); |
|
72 |
|
73 return errorCode; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // RATStorageServer::Close |
|
78 // Destroys all memory reserved by this class, and calls RSessionBase::Close() |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C void RATStorageServer::Close() |
|
82 { |
|
83 LOGSTR1( "STSE void RATStorageServer::Close()" ); |
|
84 |
|
85 // Delete iStackBuf |
|
86 delete iStackBuf; |
|
87 iStackBuf = NULL; |
|
88 |
|
89 // Call the base class' Close() |
|
90 RSessionBase::Close(); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // RATStorageServer::LogProcessStarted |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 EXPORT_C TInt RATStorageServer::LogProcessStarted( const TDesC& aFileName, |
|
98 const TDesC8& aProcessName, |
|
99 TUint aProcessId, |
|
100 TUint32 aLogOption, TUint32 aIsDebug ) |
|
101 { |
|
102 LOGSTR1( "STSE TInt RATStorageServer::LogProcessStarted()" ); |
|
103 |
|
104 // Panic always if aFileName or aProcessName are longer than allowed. |
|
105 __ASSERT_ALWAYS( aFileName.Length() <= KMaxFileName && |
|
106 aProcessName.Length() <= KMaxProcessName, |
|
107 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
108 |
|
109 // Panic (in debug builds) if aProcessId is KNullProcessId |
|
110 __ASSERT_DEBUG( aProcessId != KNullProcessId, |
|
111 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
112 |
|
113 // This information is optional -> ignoring error |
|
114 // Must be before EProcessStarted in order to append udeb/urel |
|
115 // information to LogProcessStarted |
|
116 TIpcArgs ipcArgs2( aIsDebug ); |
|
117 SendReceive( CATStorageServer::EProcessUdeb, ipcArgs2 ); |
|
118 |
|
119 TIpcArgs ipcArgs( &aFileName, &aProcessName, aProcessId, aLogOption ); |
|
120 TInt error( 0 ); |
|
121 |
|
122 error = SendReceive( CATStorageServer::EProcessStarted, ipcArgs ); |
|
123 |
|
124 // Return, if error is not KErrNone. |
|
125 if ( error != KErrNone ) |
|
126 { |
|
127 return error; |
|
128 } |
|
129 |
|
130 return KErrNone; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // RATStorageServer::LogDllLoaded |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 EXPORT_C TInt RATStorageServer::LogDllLoaded( const TDesC8& aDllName, |
|
138 TUint32 aStartAddress, |
|
139 TUint32 aEndAddress ) |
|
140 { |
|
141 LOGSTR1( "STSE TInt RATStorageServer::LogDllLoaded()" ); |
|
142 |
|
143 // Panic always if aDllName is longer than allowed. |
|
144 __ASSERT_ALWAYS( aDllName.Length() <= KMaxLibraryName, |
|
145 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
146 |
|
147 // Panic (in debug builds) if aStartAddress is greater than aEndAddress |
|
148 __ASSERT_DEBUG( aStartAddress <= aEndAddress, |
|
149 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
150 |
|
151 TIpcArgs ipcArgs( &aDllName, aStartAddress, aEndAddress ); |
|
152 |
|
153 return SendReceive( CATStorageServer::EDllLoaded, ipcArgs ); |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // RATStorageServer::LogDllUnloaded |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 EXPORT_C TInt RATStorageServer::LogDllUnloaded( const TDesC8& aDllName, |
|
161 TUint32 aStartAddress, |
|
162 TUint32 aEndAddress ) |
|
163 { |
|
164 LOGSTR1( "STSE TInt RATStorageServer::LogDllUnloaded()" ); |
|
165 |
|
166 // Panic always if aDllName is longer than allowed. |
|
167 __ASSERT_ALWAYS( aDllName.Length() <= KMaxLibraryName, |
|
168 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
169 |
|
170 // Panic (in debug builds) if aStartAddress is greater than aEndAddress |
|
171 __ASSERT_DEBUG( aStartAddress <= aEndAddress, |
|
172 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
173 |
|
174 TIpcArgs ipcArgs( &aDllName, aStartAddress, aEndAddress ); |
|
175 |
|
176 return SendReceive( CATStorageServer::EDllUnloaded, ipcArgs ); |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // RATStorageServer::LogMemoryAllocated |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 EXPORT_C TInt RATStorageServer::LogMemoryAllocated( TUint32 aMemAddress, |
|
184 TFixedArray<TUint32, KATMaxCallstackLength>& aCallstack, |
|
185 TInt aSize ) |
|
186 { |
|
187 LOGSTR1( "STSE TInt RATStorageServer::LogMemoryAllocated()" ); |
|
188 |
|
189 TInt count=0; |
|
190 // The number of memory addresses in aCallstack |
|
191 for ( TInt i = 0; i < KATMaxCallstackLength; i++ ) |
|
192 { |
|
193 if( aCallstack[i] == 0 ) |
|
194 { |
|
195 break; |
|
196 } |
|
197 count++; |
|
198 } |
|
199 |
|
200 LOGSTR2( "STSE The number of memory addresses in the current call stack: %d", count ); |
|
201 |
|
202 // The maximum number of call stack's memory addresses this server can handle |
|
203 // is KMaxCallstackLength |
|
204 if ( count > KATMaxCallstackLength ) |
|
205 { |
|
206 count = KATMaxCallstackLength; |
|
207 } |
|
208 |
|
209 // Panic (in debug builds) if the parameters are faulty |
|
210 __ASSERT_DEBUG( aMemAddress != 0 && count >= 0 && aSize >= 0, |
|
211 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
212 |
|
213 // Buffer position |
|
214 TInt pos = 0; |
|
215 TUint32 callStackAddr; |
|
216 |
|
217 // Write the number of memory addresses of aCallstack (one word) into |
|
218 // the beginning of the call stack buffer |
|
219 iStackBuf->Write( pos, &count, KWordSize ); |
|
220 |
|
221 // Increase the position by one word |
|
222 pos += KWordSize; |
|
223 |
|
224 // Write all the memory addresses of aCallStack into the buffer |
|
225 for ( TInt i = 0; i < count; i++ ) |
|
226 { |
|
227 callStackAddr = aCallstack[i]; |
|
228 |
|
229 // Write the current memory address (the length of an address is one word) |
|
230 iStackBuf->Write( pos, &callStackAddr, KWordSize ); |
|
231 |
|
232 // Move the pos variable one word (4 bytes) onwards. |
|
233 pos += KWordSize; |
|
234 } |
|
235 |
|
236 TPtr8 bufPtr( iStackBuf->Ptr(0) ); |
|
237 |
|
238 TIpcArgs ipcArgs( aMemAddress, &bufPtr, aSize ); |
|
239 |
|
240 return SendReceive( CATStorageServer::EMemoryAllocated, ipcArgs ); |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // RATStorageServer::LogMemoryFreed |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 EXPORT_C TInt RATStorageServer::LogMemoryFreed( TUint32 aMemAddress, |
|
248 TFixedArray<TUint32, KATMaxFreeCallstackLength>& aFreeCallstack ) |
|
249 { |
|
250 LOGSTR1( "STSE TInt RATStorageServer::LogMemoryFreed()" ); |
|
251 |
|
252 TInt count=0; |
|
253 // The number of memory addresses in aFreeCallstack |
|
254 for ( TInt i = 0; i < KATMaxCallstackLength; i++ ) |
|
255 { |
|
256 if( aFreeCallstack[i] == 0 ) |
|
257 { |
|
258 break; |
|
259 } |
|
260 count++; |
|
261 } |
|
262 LOGSTR3( "STSE > aFreeCallstack.Count() ( %i ), address( %x )", |
|
263 count, aMemAddress ); |
|
264 |
|
265 // The maximum number of call stack's memory addresses this server can handle |
|
266 // is KMaxCallstackLength |
|
267 if ( count > KATMaxFreeCallstackLength ) |
|
268 { |
|
269 count = KATMaxFreeCallstackLength; |
|
270 } |
|
271 |
|
272 // Buffer position |
|
273 TInt pos = 0; |
|
274 TUint32 callStackAddr; |
|
275 |
|
276 // Write the number of memory addresses of aFreeCallstack (one word) into |
|
277 // the beginning of the call stack buffer |
|
278 iStackBuf->Write( pos, &count, KWordSize ); |
|
279 |
|
280 // Increase the position by one word |
|
281 pos += KWordSize; |
|
282 |
|
283 // Write all the memory addresses of aFreeCallstack into the buffer |
|
284 for ( TInt i = 0; i < count; i++ ) |
|
285 { |
|
286 callStackAddr = aFreeCallstack[i]; |
|
287 |
|
288 // Write the current memory address (the length of an address is one word) |
|
289 iStackBuf->Write( pos, &callStackAddr, KWordSize ); |
|
290 |
|
291 // Move the pos variable one word (4 bytes) onwards. |
|
292 pos += KWordSize; |
|
293 } |
|
294 |
|
295 TPtr8 bufPtr( iStackBuf->Ptr( 0 ) ); |
|
296 TIpcArgs ipcArgs( aMemAddress, &bufPtr ); |
|
297 |
|
298 return SendReceive( CATStorageServer::EMemoryFreed, ipcArgs ); |
|
299 } |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // RATStorageServer::LogProcessEnded |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 EXPORT_C TInt RATStorageServer::LogProcessEnded( TUint aProcessId, |
|
306 TUint aHandleLeaks ) |
|
307 { |
|
308 LOGSTR1( "STSE TInt RATStorageServer::LogProcessEnded()" ); |
|
309 |
|
310 // Panic (in debug builds) if the parameters are faulty |
|
311 __ASSERT_DEBUG( aProcessId != KNullProcessId, |
|
312 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
313 |
|
314 TIpcArgs ipcArgs( aProcessId, aHandleLeaks ); |
|
315 |
|
316 return SendReceive( CATStorageServer::EProcessEnded, ipcArgs ); |
|
317 } |
|
318 |
|
319 //----------------------------------------------------------------------------- |
|
320 // RATStorageServer::Version() |
|
321 // Returns the version number. |
|
322 //----------------------------------------------------------------------------- |
|
323 // |
|
324 EXPORT_C TVersion RATStorageServer::Version() const |
|
325 { |
|
326 LOGSTR1( "STSE TInt RATStorageServer::Version()" ); |
|
327 |
|
328 return TVersion(KLowestVersionNumberMaj, KLowestVersionNumberMin, |
|
329 KLowestVersionNumberBld); |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // RATStorageServer::CheckMemoryAddress |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 EXPORT_C TInt RATStorageServer::CheckMemoryAddress( TUint32 aMemAddress ) const |
|
337 { |
|
338 LOGSTR1( "STSE TInt RATStorageServer::CheckMemoryAddress()" ); |
|
339 |
|
340 // Panic (in debug builds) if the parameters are faulty |
|
341 __ASSERT_DEBUG( aMemAddress != 0, |
|
342 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
343 |
|
344 TIpcArgs ipcArgs( aMemAddress ); |
|
345 |
|
346 return SendReceive( CATStorageServer::EMemoryCheck, ipcArgs ); |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // RATStorageServer::GetProcessesL |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 EXPORT_C TInt RATStorageServer::GetProcessesL( RArray<TATProcessInfo>& aProcesses ) |
|
354 { |
|
355 LOGSTR1( "STSE TInt RATStorageServer::GetProcessesL()" ); |
|
356 |
|
357 TInt error( KErrNone ); |
|
358 TInt sizeOfProcessInfo = sizeof( TATProcessInfo ); |
|
359 |
|
360 // Reset the sent array |
|
361 aProcesses.Reset(); |
|
362 |
|
363 // Calculate the length of the buffer to be constructed for processes. |
|
364 // One word will be reserved for the length of the array. |
|
365 TInt bufferLength = KWordSize + KATMaxProcesses * sizeOfProcessInfo; |
|
366 |
|
367 CBufFlat* processBuf; |
|
368 // Construct processBuf and expand it before the beginning (index 0) |
|
369 processBuf = CBufFlat::NewL( bufferLength ); |
|
370 CleanupStack::PushL( processBuf ); |
|
371 processBuf->ExpandL( 0, bufferLength ); |
|
372 |
|
373 TPtr8 bufPtr( processBuf->Ptr(0) ); |
|
374 |
|
375 // Send the buffer to the server, which will fill it. |
|
376 TIpcArgs ipcArgs( &bufPtr ); |
|
377 error = SendReceive( CATStorageServer::EGetProcesses, ipcArgs ); |
|
378 // Return with the error code if the operation failed |
|
379 if ( error != KErrNone ) |
|
380 { |
|
381 CleanupStack::PopAndDestroy( processBuf ); |
|
382 return error; |
|
383 } |
|
384 |
|
385 // A variable for the number of TATProcessInfo objects |
|
386 TInt count( 0 ); |
|
387 // A variable for the position |
|
388 TInt pos( 0 ); |
|
389 |
|
390 // Read the value for count |
|
391 processBuf->Read( pos, &count, KWordSize ); |
|
392 |
|
393 // Return if we got an illegal value for count |
|
394 if ( count < 0 || count > KATMaxProcesses ) |
|
395 { |
|
396 CleanupStack::PopAndDestroy( processBuf ); |
|
397 return KErrGeneral; |
|
398 } |
|
399 |
|
400 // Move the position one word onwards. |
|
401 pos += KWordSize; |
|
402 |
|
403 TATProcessInfo processInfo; |
|
404 |
|
405 // Go through all TATProcessInfo objects sent to the server |
|
406 for ( TInt j = 0; j < count; j++ ) |
|
407 { |
|
408 // Read one of the TATProcessInfo objects stored in the buffer. |
|
409 processBuf->Read( pos, &processInfo, sizeOfProcessInfo ); |
|
410 |
|
411 // Append this processInfo to the array |
|
412 error = aProcesses.Append( processInfo ); |
|
413 |
|
414 if ( error != KErrNone ) |
|
415 { |
|
416 CleanupStack::PopAndDestroy( processBuf ); |
|
417 return error; |
|
418 } |
|
419 |
|
420 // Move the pos variable one word onwards. |
|
421 pos += sizeOfProcessInfo; |
|
422 } |
|
423 |
|
424 CleanupStack::PopAndDestroy( processBuf ); |
|
425 return error; |
|
426 } |
|
427 |
|
428 // ----------------------------------------------------------------------------- |
|
429 // RATStorageServer::GetLoadedDllsL |
|
430 // ----------------------------------------------------------------------------- |
|
431 // |
|
432 EXPORT_C TInt RATStorageServer::GetLoadedDllsL( TUint aProcessId, |
|
433 RArray< TBuf8<KMaxLibraryName> >& aDlls ) |
|
434 { |
|
435 LOGSTR1( "STSE TInt RATStorageServer::GetLoadedDllsL()" ); |
|
436 |
|
437 // Panic (in debug builds) if aProcessId is faulty |
|
438 __ASSERT_DEBUG( aProcessId != KNullProcessId, |
|
439 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
440 |
|
441 TInt error( KErrNone ); |
|
442 |
|
443 // Size of a DLL descriptor |
|
444 TInt sizeOfDllDesc = sizeof( TBuf8<KMaxLibraryName> ); |
|
445 |
|
446 // Reset the sent array |
|
447 aDlls.Reset(); |
|
448 |
|
449 // Calculate the length of the buffer to be constructed for DLL names. |
|
450 // One word will be reserved for the length of the array. |
|
451 TInt bufferLength = KWordSize + KATMaxDlls * sizeOfDllDesc; |
|
452 |
|
453 CBufFlat* dllBuf; |
|
454 // Construct dllBuf and expand it before the beginning (index 0) |
|
455 dllBuf = CBufFlat::NewL( bufferLength ); |
|
456 CleanupStack::PushL( dllBuf ); |
|
457 dllBuf->ExpandL( 0, bufferLength ); |
|
458 |
|
459 TPtr8 bufPtr( dllBuf->Ptr(0) ); |
|
460 |
|
461 // Call the server with the given arguments |
|
462 TIpcArgs ipcArgs( aProcessId, &bufPtr ); |
|
463 error = SendReceive( CATStorageServer::EGetDlls, ipcArgs ); |
|
464 |
|
465 // Return, if error is not KErrNone. |
|
466 if ( error != KErrNone ) |
|
467 { |
|
468 CleanupStack::PopAndDestroy( dllBuf ); |
|
469 return error; |
|
470 } |
|
471 |
|
472 // A variable for the number of objects in the buffer |
|
473 TInt count( 0 ); |
|
474 |
|
475 // A variable for the position |
|
476 TInt pos( 0 ); |
|
477 |
|
478 // Read the value for count |
|
479 dllBuf->Read( pos, &count, KWordSize ); |
|
480 |
|
481 // Return if we got an illegal value for count |
|
482 if ( count < 0 || count > KATMaxDlls ) |
|
483 { |
|
484 CleanupStack::PopAndDestroy( dllBuf ); |
|
485 return KErrGeneral; |
|
486 } |
|
487 |
|
488 // Move the position one word onwards. |
|
489 pos += KWordSize; |
|
490 |
|
491 TBuf8<KMaxLibraryName> dllName; |
|
492 |
|
493 // Go through all DLL names objects sent to the server |
|
494 for ( TInt j = 0; j < count; j++ ) |
|
495 { |
|
496 // Read one of the DLL names stored in the buffer. |
|
497 dllBuf->Read( pos, &dllName, sizeOfDllDesc ); |
|
498 |
|
499 // Append this DLL name to the array |
|
500 error = aDlls.Append( dllName ); |
|
501 |
|
502 if ( error != KErrNone ) |
|
503 { |
|
504 return error; |
|
505 } |
|
506 |
|
507 // Move the pos variable one word onwards. |
|
508 pos += sizeOfDllDesc; |
|
509 } |
|
510 |
|
511 CleanupStack::PopAndDestroy( dllBuf ); |
|
512 return error; |
|
513 } |
|
514 |
|
515 // ----------------------------------------------------------------------------- |
|
516 // RATStorageServer::GetLoggingModeL |
|
517 // ----------------------------------------------------------------------------- |
|
518 // |
|
519 EXPORT_C TInt RATStorageServer::GetLoggingModeL( TUint aProcessId, |
|
520 TATLogOption& aLoggingMode ) |
|
521 { |
|
522 LOGSTR1( "STSE TInt RATStorageServer::GetLoggingModeL()" ); |
|
523 |
|
524 // Panic (in debug builds) if aProcessId is illegal |
|
525 __ASSERT_DEBUG( aProcessId != KNullProcessId, |
|
526 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
527 |
|
528 TInt error(0); |
|
529 |
|
530 // The length of the buffer to be constructed for logging mode |
|
531 TInt bufferLength = KWordSize; |
|
532 |
|
533 CBufFlat* loggingModeBuf; |
|
534 // Construct allocInfoBuf and expand it before the beginning (index 0) |
|
535 loggingModeBuf = CBufFlat::NewL( bufferLength ); |
|
536 CleanupStack::PushL( loggingModeBuf ); |
|
537 loggingModeBuf->ExpandL( 0, bufferLength ); |
|
538 |
|
539 TPtr8 bufPtr( loggingModeBuf->Ptr(0) ); |
|
540 |
|
541 // Call the server |
|
542 TIpcArgs ipcArgs( aProcessId, &bufPtr ); |
|
543 error = SendReceive( CATStorageServer::EGetLoggingMode, ipcArgs ); |
|
544 |
|
545 // Return if an error occured. |
|
546 if ( error ) |
|
547 { |
|
548 CleanupStack::PopAndDestroy( loggingModeBuf ); |
|
549 return error; |
|
550 } |
|
551 |
|
552 // A variable for the position |
|
553 TInt pos( 0 ); |
|
554 |
|
555 // Read the value for aNumber |
|
556 loggingModeBuf->Read( pos, &aLoggingMode, KWordSize ); |
|
557 |
|
558 CleanupStack::PopAndDestroy( loggingModeBuf ); |
|
559 |
|
560 return KErrNone; |
|
561 } |
|
562 |
|
563 // ----------------------------------------------------------------------------- |
|
564 // RATStorageServer::StartSubTest |
|
565 // ----------------------------------------------------------------------------- |
|
566 // |
|
567 EXPORT_C TInt RATStorageServer::StartSubTest( TUint aProcessId, |
|
568 const TDesC8& aSubtestId, TInt aHandleCount ) |
|
569 { |
|
570 LOGSTR1( "STSE TInt RATStorageServer::StartSubTest()" ); |
|
571 |
|
572 // Panic if the parameters are faulty |
|
573 __ASSERT_ALWAYS( aSubtestId.Length() <= KATMaxSubtestIdLength, |
|
574 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
575 |
|
576 // Panic (in debug builds) if the parameters are faulty |
|
577 __ASSERT_DEBUG( aProcessId != KNullProcessId, |
|
578 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
579 |
|
580 TIpcArgs ipcArgs( aProcessId, &aSubtestId, aHandleCount ); |
|
581 |
|
582 return SendReceive( CATStorageServer::ESubtestStart, ipcArgs ); |
|
583 } |
|
584 |
|
585 // ----------------------------------------------------------------------------- |
|
586 // RATStorageServer::StopSubTest |
|
587 // ----------------------------------------------------------------------------- |
|
588 // |
|
589 EXPORT_C TInt RATStorageServer::StopSubTest( TUint aProcessId, |
|
590 const TDesC8& aSubtestId, TInt aHandleCount ) |
|
591 { |
|
592 LOGSTR1( "STSE TInt RATStorageServer::StopSubTest()" ); |
|
593 |
|
594 // Panic if the parameters are faulty |
|
595 __ASSERT_ALWAYS( aSubtestId.Length() <= KATMaxSubtestIdLength, |
|
596 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
597 |
|
598 // Panic (in debug builds) if the parameters are faulty |
|
599 __ASSERT_DEBUG( aProcessId != KNullProcessId, |
|
600 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
601 |
|
602 TIpcArgs ipcArgs( aProcessId, &aSubtestId, aHandleCount ); |
|
603 |
|
604 return SendReceive( CATStorageServer::ESubtestStop, ipcArgs ); |
|
605 } |
|
606 |
|
607 // ----------------------------------------------------------------------------- |
|
608 // RATStorageServer::GetCurrentAllocsL |
|
609 // ----------------------------------------------------------------------------- |
|
610 // |
|
611 EXPORT_C TInt RATStorageServer::GetCurrentAllocsL( TUint aProcessId, |
|
612 TUint32& aNumber, |
|
613 TUint32& aSize ) |
|
614 { |
|
615 LOGSTR1( "STSE TInt RATStorageServer::GetCurrentAllocsL()" ); |
|
616 |
|
617 // Panic (in debug builds) if aProcessId is illegal |
|
618 __ASSERT_DEBUG( aProcessId != KNullProcessId, |
|
619 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
620 |
|
621 TInt error(0); |
|
622 |
|
623 // The length of the buffer to be constructed for allocation number and size |
|
624 TInt bufferLength = KWordSize + KWordSize; |
|
625 |
|
626 CBufFlat* allocInfoBuf; |
|
627 // Construct allocInfoBuf and expand it before the beginning (index 0) |
|
628 allocInfoBuf = CBufFlat::NewL( bufferLength ); |
|
629 CleanupStack::PushL( allocInfoBuf ); |
|
630 allocInfoBuf->ExpandL( 0, bufferLength ); |
|
631 |
|
632 TPtr8 bufPtr( allocInfoBuf->Ptr(0) ); |
|
633 |
|
634 // Call the server |
|
635 TIpcArgs ipcArgs( aProcessId, &bufPtr ); |
|
636 error = SendReceive( CATStorageServer::EGetCurrentAllocs, ipcArgs ); |
|
637 |
|
638 // Return if error is not KErrNone. |
|
639 if ( error != KErrNone ) |
|
640 { |
|
641 CleanupStack::PopAndDestroy( allocInfoBuf ); |
|
642 return error; |
|
643 } |
|
644 |
|
645 // A variable for the position |
|
646 TInt pos( 0 ); |
|
647 |
|
648 // Read the value for aNumber |
|
649 allocInfoBuf->Read( pos, &aNumber, KWordSize ); |
|
650 |
|
651 pos += KWordSize; |
|
652 |
|
653 // Read the value for aSize |
|
654 allocInfoBuf->Read( pos, &aSize, KWordSize ); |
|
655 |
|
656 CleanupStack::PopAndDestroy( allocInfoBuf ); |
|
657 |
|
658 return KErrNone; |
|
659 } |
|
660 |
|
661 // ----------------------------------------------------------------------------- |
|
662 // RATStorageServer::GetMaxAllocsL |
|
663 // ----------------------------------------------------------------------------- |
|
664 // |
|
665 EXPORT_C TInt RATStorageServer::GetMaxAllocsL( TUint aProcessId, |
|
666 TUint32& aNumber, |
|
667 TUint32& aSize ) |
|
668 { |
|
669 LOGSTR1( "STSE TInt RATStorageServer::GetMaxAllocsL()" ); |
|
670 |
|
671 // Panic (in debug builds) if aProcessId is illegal |
|
672 __ASSERT_DEBUG( aProcessId != KNullProcessId, |
|
673 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
674 |
|
675 TInt error(0); |
|
676 |
|
677 // The length of the buffer to be constructed for allocation number and size |
|
678 TInt bufferLength = KWordSize + KWordSize; |
|
679 |
|
680 CBufFlat* allocInfoBuf; |
|
681 // Construct allocInfoBuf and expand it before the beginning (index 0) |
|
682 allocInfoBuf = CBufFlat::NewL( bufferLength ); |
|
683 CleanupStack::PushL( allocInfoBuf ); |
|
684 allocInfoBuf->ExpandL( 0, bufferLength ); |
|
685 |
|
686 TPtr8 bufPtr( allocInfoBuf->Ptr(0) ); |
|
687 |
|
688 // Call the server |
|
689 TIpcArgs ipcArgs( aProcessId, &bufPtr ); |
|
690 error = SendReceive( CATStorageServer::EGetMaxAllocs, ipcArgs ); |
|
691 |
|
692 // Return, if error is not KErrNone. |
|
693 if ( error != KErrNone ) |
|
694 { |
|
695 CleanupStack::PopAndDestroy( allocInfoBuf ); |
|
696 return error; |
|
697 } |
|
698 |
|
699 // A variable for the position |
|
700 TInt pos( 0 ); |
|
701 |
|
702 // Read the value for aNumber |
|
703 allocInfoBuf->Read( pos, &aNumber, KWordSize ); |
|
704 |
|
705 pos += KWordSize; |
|
706 |
|
707 // Read the value for aSize |
|
708 allocInfoBuf->Read( pos, &aSize, KWordSize ); |
|
709 |
|
710 CleanupStack::PopAndDestroy( allocInfoBuf ); |
|
711 |
|
712 return KErrNone; |
|
713 } |
|
714 |
|
715 // ----------------------------------------------------------------------------- |
|
716 // RATStorageServer::StartSubTest |
|
717 // An overloaded version without a PID parameter |
|
718 // ----------------------------------------------------------------------------- |
|
719 // |
|
720 EXPORT_C TInt RATStorageServer::StartSubTest( const TDesC8& aSubtestId ) |
|
721 { |
|
722 LOGSTR1( "STSE TInt RATStorageServer::StartSubTest()" ); |
|
723 |
|
724 // Panic if the parameters are faulty |
|
725 __ASSERT_ALWAYS( aSubtestId.Length() <= KATMaxSubtestIdLength, |
|
726 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
727 |
|
728 TIpcArgs ipcArgs( &aSubtestId ); |
|
729 |
|
730 return SendReceive( CATStorageServer::ESubtestStart2, ipcArgs ); |
|
731 } |
|
732 |
|
733 // ----------------------------------------------------------------------------- |
|
734 // RATStorageServer::StopSubTest |
|
735 // An overloaded version without a PID parameter |
|
736 // ----------------------------------------------------------------------------- |
|
737 // |
|
738 EXPORT_C TInt RATStorageServer::StopSubTest( const TDesC8& aSubtestId ) |
|
739 { |
|
740 LOGSTR1( "STSE TInt RATStorageServer::StopSubTest()" ); |
|
741 |
|
742 // Panic if the parameters are faulty |
|
743 __ASSERT_ALWAYS( aSubtestId.Length() <= KATMaxSubtestIdLength, |
|
744 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
745 |
|
746 TIpcArgs ipcArgs( &aSubtestId ); |
|
747 |
|
748 return SendReceive( CATStorageServer::ESubtestStop2, ipcArgs ); |
|
749 } |
|
750 |
|
751 // ----------------------------------------------------------------------------- |
|
752 // RATStorageServer::CancelLogging |
|
753 // ----------------------------------------------------------------------------- |
|
754 // |
|
755 EXPORT_C TInt RATStorageServer::CancelLogging( TUint aProcessId ) |
|
756 { |
|
757 LOGSTR1( "STSE TInt RATStorageServer::CancelLogging()" ); |
|
758 |
|
759 // Panic (in debug builds) if aProcessId is illegal |
|
760 __ASSERT_DEBUG( aProcessId != KNullProcessId, |
|
761 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
762 |
|
763 TIpcArgs ipcArgs( aProcessId ); |
|
764 |
|
765 return SendReceive( CATStorageServer::ECancelLogging, ipcArgs ); |
|
766 } |
|
767 |
|
768 // ----------------------------------------------------------------------------- |
|
769 // RATStorageServer::CreateProcess |
|
770 // Checks if the server already exists. If it doesn't, creates a new process |
|
771 // for it. |
|
772 // ----------------------------------------------------------------------------- |
|
773 // |
|
774 TInt RATStorageServer::CreateProcess() |
|
775 { |
|
776 LOGSTR1( "STSE TInt RATStorageServer::CreateProcess()" ); |
|
777 |
|
778 TInt errorCode( KErrNone ); |
|
779 |
|
780 // Check if the server already exists |
|
781 TFindServer findServer( KStorageServerName ); |
|
782 TFullName fullName; |
|
783 |
|
784 errorCode = findServer.Next( fullName ); |
|
785 |
|
786 // Return KErrNone if the server is already running |
|
787 if ( errorCode == KErrNone ) |
|
788 { |
|
789 return KErrNone; |
|
790 } |
|
791 |
|
792 // Otherwise initiate starting the server by creating first a new process for it. |
|
793 // The second argument of the Create() method call is an empty descriptor, because |
|
794 // we don't need to pass any data to the thread function of the new process's main |
|
795 // thread. |
|
796 RProcess process; |
|
797 errorCode = process.Create( KStorageServerFile, KNullDesC ); |
|
798 |
|
799 // Return the error code if the creation of the process failed |
|
800 if ( errorCode != KErrNone ) |
|
801 { |
|
802 return errorCode; |
|
803 } |
|
804 |
|
805 TRequestStatus status; |
|
806 process.Rendezvous( status ); |
|
807 |
|
808 // If the status is not KRequestPending, abort the project creation |
|
809 // and return KErrGeneral |
|
810 if ( status != KRequestPending ) |
|
811 { |
|
812 process.RendezvousCancel( status ); |
|
813 process.Kill( KErrGeneral ); |
|
814 process.Close(); |
|
815 return KErrGeneral; |
|
816 } |
|
817 |
|
818 // Otherwise make the first thread of the new process eligible for execution |
|
819 process.Resume(); |
|
820 |
|
821 // Wait for a signal from the server |
|
822 User::WaitForRequest( status ); |
|
823 |
|
824 // Close the process handle |
|
825 process.Close(); |
|
826 |
|
827 // Return the error code |
|
828 return status.Int(); |
|
829 } |
|
830 |
|
831 // ----------------------------------------------------------------------------- |
|
832 // RATStorageServer::ConstructBuffersL |
|
833 // Allocates buffers from heap. Called when connecting to the server |
|
834 // ----------------------------------------------------------------------------- |
|
835 // |
|
836 void RATStorageServer::ConstructBuffersL() |
|
837 { |
|
838 LOGSTR1( "STSE void RATStorageServer::ConstructBuffersL()" ); |
|
839 |
|
840 // Calculate the length of the buffer to be constructed for call stack. |
|
841 // One word will be reserved for the length of the array |
|
842 TInt bufferLength = ( (1 + KATMaxCallstackLength) * KWordSize ); |
|
843 |
|
844 // Construct iStackBuf and expand it before the beginning (index 0) |
|
845 iStackBuf = CBufFlat::NewL( bufferLength ); |
|
846 iStackBuf->ExpandL( 0, bufferLength ); |
|
847 } |
|
848 |
|
849 // ----------------------------------------------------------------------------- |
|
850 // RATStorageServer::GetLoggingFileL |
|
851 // ----------------------------------------------------------------------------- |
|
852 // |
|
853 EXPORT_C TInt RATStorageServer::GetLoggingFileL( TUint aProcessId, |
|
854 TDes8& aFileName ) |
|
855 { |
|
856 LOGSTR1( "STSE TInt RATStorageServer::GetLoggingFileL()" ); |
|
857 |
|
858 // Panic (in debug builds) if aProcessId is illegal |
|
859 __ASSERT_DEBUG( aProcessId != KNullProcessId, |
|
860 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
861 |
|
862 TInt error(0); |
|
863 |
|
864 TBuf8<KMaxFileName> fileBuf; |
|
865 // Call the server |
|
866 TIpcArgs ipcArgs( aProcessId, &fileBuf ); |
|
867 error = SendReceive( CATStorageServer::EGetLoggingFile, ipcArgs ); |
|
868 |
|
869 // Return, if an error occured. |
|
870 if ( error ) |
|
871 { |
|
872 return error; |
|
873 } |
|
874 |
|
875 aFileName.Copy( fileBuf ); |
|
876 return KErrNone; |
|
877 } |
|
878 |
|
879 // ----------------------------------------------------------------------------- |
|
880 // RATStorageServer::GetUdebL |
|
881 // ----------------------------------------------------------------------------- |
|
882 // |
|
883 EXPORT_C TInt RATStorageServer::GetUdebL( TUint aProcessId, TUint32& aIsUdeb ) |
|
884 { |
|
885 LOGSTR1( "STSE TInt RATStorageServer::GetUdebL()" ); |
|
886 |
|
887 // Panic (in debug builds) if aProcessId is illegal |
|
888 __ASSERT_DEBUG( aProcessId != KNullProcessId, |
|
889 StorageServerPanic( KCategoryClient, EAToolBadArgument ) ); |
|
890 |
|
891 TInt error(0); |
|
892 TBuf8<KMaxVersionName> isUdeb; |
|
893 _LIT8( KUdeb, "UDEB" ); |
|
894 // Call the server |
|
895 TIpcArgs ipcArgs( aProcessId, &isUdeb ); |
|
896 error = SendReceive( CATStorageServer::EGetUdeb, ipcArgs ); |
|
897 |
|
898 // Return, if an error occured. |
|
899 if ( error != KErrNone ) |
|
900 { |
|
901 return error; |
|
902 } |
|
903 |
|
904 if ( isUdeb.Compare( KUdeb() ) == 0 ) |
|
905 { |
|
906 LOGSTR1( "STSE TInt RATStorageServer::GetUdebL() - Is UDEB" ); |
|
907 aIsUdeb = 1; |
|
908 } |
|
909 else |
|
910 { |
|
911 LOGSTR1( "STSE TInt RATStorageServer::GetUdebL() - Is UREL" ); |
|
912 aIsUdeb = 0; |
|
913 } |
|
914 |
|
915 return KErrNone; |
|
916 } |
|
917 |
|
918 // ----------------------------------------------------------------------------- |
|
919 // RATStorageServer::IsMemoryAdded |
|
920 // ----------------------------------------------------------------------------- |
|
921 // |
|
922 EXPORT_C TInt RATStorageServer::IsMemoryAdded( TUint32 aMemAddress ) |
|
923 { |
|
924 LOGSTR1( "STSE TInt RATStorageServer::IsMemoryAdded()" ); |
|
925 |
|
926 TIpcArgs ipcArgs( aMemAddress ); |
|
927 return SendReceive( CATStorageServer::EIsMemoryAdded, ipcArgs ); |
|
928 } |
|
929 |
|
930 // End of File |