memspy/MemSpyClient/src/memspysession.cpp
branchRCL_3
changeset 21 52e343bb8f80
parent 20 ca8a1b6995f6
child 22 e26895079d7c
equal deleted inserted replaced
20:ca8a1b6995f6 21:52e343bb8f80
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "memspysession.h"
       
    20 
       
    21 #include <memspyengineclientinterface.h>
       
    22 // API
       
    23 #include <memspy/engine/memspyprocessdata.h>
       
    24 #include <memspy/engine/memspythreaddata.h> 
       
    25 #include <memspy/engine/memspykernelobjectdata.h>
       
    26 #include <memspy/engine/memspyheapdata.h>
       
    27 #include <memspy/engine/memspymemorytrackingcycledata.h>
       
    28 //KernelObjects
       
    29 #include <memspy/driver/memspydriverenumerationsshared.h>
       
    30 // IMPLEMENTATION
       
    31 
       
    32 EXPORT_C RMemSpySession::RMemSpySession()
       
    33     {
       
    34     }
       
    35 
       
    36 
       
    37 EXPORT_C TInt RMemSpySession::Connect()
       
    38     {
       
    39 	TInt error(KErrNone);
       
    40 	
       
    41 	for (TInt i=0; i<2; i++) // Two retries max
       
    42 		{
       
    43 		TInt error = CreateSession(KMemSpyServerName, TVersion(KMemSpyVersion, 0, 0));
       
    44 		
       
    45 		if (error != KErrNotFound && error != KErrServerTerminated)
       
    46 			return error;
       
    47 		
       
    48 		error = StartServer();
       
    49 		
       
    50 		if (error != KErrNone && error != KErrAlreadyExists)
       
    51 			return error;
       
    52 		}
       
    53 	
       
    54 	return error;	
       
    55     }
       
    56 
       
    57 TInt RMemSpySession::StartServer()
       
    58 	{
       
    59 	RProcess server;
       
    60 	_LIT(KCommand, "start");
       
    61 	const TUid KServerUid3 = {0xE5883BC2};
       
    62 	TInt error = server.Create(KMemSpyServerName, KCommand);//, KServerUid3);
       
    63 	
       
    64 	if (error != KErrNone)
       
    65 		return error;
       
    66 	
       
    67 	TRequestStatus startStatus, stopStatus;
       
    68 	server.Logon(stopStatus);
       
    69 	if (stopStatus != KRequestPending)
       
    70 		{
       
    71 		User::WaitForRequest(stopStatus);
       
    72 		server.Kill(0);
       
    73 		server.Close();
       
    74 		return stopStatus.Int();
       
    75 		}
       
    76 	
       
    77 	server.Rendezvous(startStatus);
       
    78 	server.Resume();
       
    79 	User::WaitForRequest(startStatus, stopStatus);
       
    80 	if (startStatus == KRequestPending)
       
    81 		{
       
    82 		// not started yet, i.e. stopStatus was signaled
       
    83 		server.Close();
       
    84 		return stopStatus.Int();
       
    85 		}
       
    86 	
       
    87 	// Rendezvous was called - the server is ready
       
    88 	
       
    89 	// We first need to cancel Logon
       
    90 	server.LogonCancel(stopStatus);
       
    91 	// We don't need this anymore
       
    92 	server.Close();
       
    93 	// Wait for LogonCancel to complete
       
    94 	User::WaitForRequest(stopStatus);
       
    95 
       
    96 	// Everything went OK
       
    97 	return KErrNone;
       
    98 	}
       
    99 
       
   100 EXPORT_C void RMemSpySession::GetProcessesL(RArray<CMemSpyApiProcess*> &aProcesses, TSortType aSortType)
       
   101 	{
       
   102 	TPckgBuf<TInt> count;
       
   103 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetProcessCount, TIpcArgs(&count)));
       
   104 	
       
   105 	TInt requestedCount = count();
       
   106 	HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyProcessData));
       
   107 	TPtr8 bufferPtr(buffer->Des());
       
   108 	
       
   109 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetProcesses, TIpcArgs(&count, &bufferPtr)));
       
   110 	aProcesses.Reset();
       
   111 	
       
   112 	TInt receivedCount = Min(count(), requestedCount);
       
   113 	for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyProcessData))
       
   114 		{
       
   115 		TPckgBuf<TMemSpyProcessData> data;
       
   116 		data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyProcessData));
       
   117 		aProcesses.AppendL(CMemSpyApiProcess::NewLC(data()));
       
   118 		}
       
   119 	CleanupStack::Pop(aProcesses.Count());
       
   120 	CleanupStack::PopAndDestroy(buffer);
       
   121 	}
       
   122 
       
   123 EXPORT_C TProcessId RMemSpySession::GetProcessIdByNameL(const TDesC& aProcessName)
       
   124 	{
       
   125 	TPckgBuf<TProcessId> procId;
       
   126 	User::LeaveIfError(SendReceive(EMemSpyClienServerOpGetProcessIdByName, 
       
   127 			TIpcArgs(&aProcessName, &procId)));
       
   128 	
       
   129 	return procId();
       
   130 	}
       
   131 
       
   132 EXPORT_C TInt RMemSpySession::ProcessSystemPermanentOrCritical( TProcessId aId, TBool aValue )
       
   133 	{
       
   134 	TPckgBuf<TProcessId> arg1( aId );
       
   135 	TPckgBuf<TBool> arg2( aValue );
       
   136 	TIpcArgs args( &arg1, &arg2 );
       
   137 		
       
   138 	TInt error = SendReceive( EMemSpyClientServerOpProcessSystemPermanentOrCritical, args );
       
   139 	
       
   140 	return error;
       
   141 	}
       
   142 
       
   143 EXPORT_C TInt RMemSpySession::EndProcess( TProcessId aId, TMemSpyEndType aType )
       
   144 	{
       
   145 	TPckgBuf<TProcessId> arg1( aId );
       
   146 	TPckgBuf<TMemSpyEndType> arg2( aType );
       
   147 	TIpcArgs args( &arg1, &arg2 );
       
   148 	
       
   149 	TInt error = SendReceive( EMemSpyClientServerOpEndProcess, args );
       
   150 	
       
   151 	return error;
       
   152 	}
       
   153 
       
   154 EXPORT_C TInt RMemSpySession::SwitchToProcess( TProcessId aId, TBool aBrought )
       
   155 	{
       
   156 	TPckgBuf<TProcessId> arg1( aId );
       
   157 	TPckgBuf<TBool> arg2( aBrought );
       
   158 	TIpcArgs args( &arg1, &arg2 );
       
   159 	
       
   160 	TInt error = SendReceive( EMemSpyClientServerOpSwitchToProcess, args );
       
   161 	
       
   162 	return error;	
       
   163 	}
       
   164 
       
   165 EXPORT_C void RMemSpySession::GetThreadsL(TProcessId aProcessId, RArray<CMemSpyApiThread*> &aThreads, TSortType aSortType)
       
   166 	{
       
   167 	TPckgBuf<TInt> count;
       
   168 	TPckgBuf<TProcessId> pid(aProcessId);
       
   169 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetThreadCount, TIpcArgs(&count, &pid)));
       
   170 	
       
   171 	TInt requestedCount = count();
       
   172 	HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyThreadData));
       
   173 	TPtr8 bufferPtr(buffer->Des());
       
   174 	
       
   175 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetThreads, TIpcArgs(&count, &bufferPtr, &pid)));
       
   176 	aThreads.Reset();
       
   177 	
       
   178 	TInt receivedCount = Min(count(), requestedCount);
       
   179 	for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyThreadData))
       
   180 		{
       
   181 		TPckgBuf<TMemSpyThreadData> data;
       
   182 		data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyThreadData));
       
   183 		aThreads.AppendL(CMemSpyApiThread::NewLC(data()));
       
   184 		}
       
   185 	CleanupStack::Pop(aThreads.Count());
       
   186 	CleanupStack::PopAndDestroy(buffer);
       
   187 	}
       
   188 
       
   189 EXPORT_C void RMemSpySession::SetThreadPriorityL(TThreadId aId, TInt aPriority)
       
   190 	{
       
   191 	TPckgBuf<TThreadId> arg1( aId );
       
   192 	TPckgBuf<TInt> arg2( aPriority );
       
   193 	
       
   194 	User::LeaveIfError(SendReceive( EMemSpyClientServerOpSetThreadPriority, TIpcArgs(&arg1, &arg2)));
       
   195 	}
       
   196 
       
   197 EXPORT_C TInt RMemSpySession::ThreadSystemPermanentOrCritical( TThreadId aId, TBool aValue )
       
   198 	{
       
   199 	TPckgBuf<TThreadId> arg1( aId );
       
   200 	TPckgBuf<TBool> arg2( aValue );
       
   201 	TIpcArgs args( &arg1, &arg2 );
       
   202 	
       
   203 	TInt error = SendReceive( EMemSpyClientServerOpThreadSystemPermanentOrCritical, args );
       
   204 	
       
   205 	return error;
       
   206 	}
       
   207 
       
   208 EXPORT_C TInt RMemSpySession::EndThread( TThreadId aId, TMemSpyEndType aType )
       
   209 	{
       
   210 	TPckgBuf<TThreadId> arg1( aId );
       
   211 	TPckgBuf<TMemSpyEndType> arg2( aType );
       
   212 	TIpcArgs args( &arg1, &arg2 );
       
   213 	
       
   214 	TInt error = SendReceive( EMemSpyClientServerOpEndThread, args );
       
   215 	
       
   216 	return error;
       
   217 	}
       
   218 
       
   219 EXPORT_C TInt RMemSpySession::SwitchToThread( TThreadId aId, TBool aBrought )
       
   220 	{
       
   221 	TPckgBuf<TThreadId> arg1( aId );
       
   222 	TPckgBuf<TBool> arg2( aBrought );
       
   223 	TIpcArgs args( &arg1, &arg2 );
       
   224 	
       
   225 	TInt error = SendReceive( EMemSpyClientServerOpSwitchToThread, args );
       
   226 	
       
   227 	return error;	
       
   228 	}
       
   229 
       
   230 EXPORT_C TInt RMemSpySession::GetInfoItemType( TInt aIndex, TThreadId aId, TMemSpyThreadInfoItemType &aType )
       
   231 	{
       
   232 	TPckgBuf<TInt> arg1( aIndex );
       
   233 	TPckgBuf<TThreadId> arg2( aId );
       
   234 	TPckgBuf<TMemSpyThreadInfoItemType> arg3;
       
   235 	TIpcArgs args( &arg1, &arg2, &arg3 );
       
   236 		
       
   237 	TInt error = SendReceive( EMemSpyClientServerOpGetInfoItemType, args );
       
   238 	
       
   239 	aType = arg3();
       
   240 	
       
   241 	return error;
       
   242 	}
       
   243 
       
   244 EXPORT_C void RMemSpySession::GetThreadInfoItemsL( RArray<CMemSpyApiThreadInfoItem*> &aInfoItems, TThreadId aId, TMemSpyThreadInfoItemType aType )
       
   245 	{
       
   246 	TPckgBuf<TThreadId> id( aId );	
       
   247 	TPckgBuf<TMemSpyThreadInfoItemType> type( aType );
       
   248 	TPckgBuf<TInt> count;	
       
   249 	
       
   250 	TInt error = SendReceive( EMemSpyClientServerOpGetThreadInfoItemsCount, TIpcArgs( &id, &type, &count ) );
       
   251 	TInt itemCount = count();
       
   252 	
       
   253 	if( error == KErrNone )
       
   254 		{		
       
   255 		if( itemCount == 0 )
       
   256 			{
       
   257 			aInfoItems.Reset();
       
   258 			}
       
   259 		else
       
   260 			{
       
   261 			HBufC8* buffer = HBufC8::NewLC( itemCount * sizeof(TMemSpyThreadInfoItemData) );
       
   262 			TPtr8 bufferPtr(buffer->Des());
       
   263 			
       
   264 			TPckgBuf<TInt> requestedCount( itemCount );
       
   265 			
       
   266 			TIpcArgs args( &requestedCount, &id, &type, &bufferPtr );
       
   267 			TInt error = SendReceive( EMemSpyClientServerOpGetThreadInfoItems, args );
       
   268 			
       
   269 			aInfoItems.Reset();
       
   270 		
       
   271 			for(TInt i=0, offset = 0; i < itemCount; i++, offset+=sizeof(TMemSpyThreadInfoItemData))
       
   272 				{
       
   273 				TPckgBuf<TMemSpyThreadInfoItemData> data;
       
   274 				data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyThreadInfoItemData));
       
   275 				aInfoItems.AppendL(CMemSpyApiThreadInfoItem::NewLC(data()));
       
   276 				}
       
   277 			
       
   278 			CleanupStack::Pop(aInfoItems.Count());
       
   279 			CleanupStack::PopAndDestroy(buffer);
       
   280 			}
       
   281 		}
       
   282 	
       
   283 	User::LeaveIfError(error);
       
   284 	}
       
   285 
       
   286 EXPORT_C TInt RMemSpySession::GetThreadInfoItems( RArray<CMemSpyApiThreadInfoItem*> &aInfoItems, TThreadId aId, TMemSpyThreadInfoItemType aType )
       
   287 	{
       
   288 	TRAPD(error, GetThreadInfoItemsL(aInfoItems, aId, aType));
       
   289 	return error;
       
   290 	}
       
   291 
       
   292 //Kernel Objects specific operations
       
   293 EXPORT_C void RMemSpySession::GetKernelObjectsL( RArray<CMemSpyApiKernelObject*> &aKernelObjects )
       
   294 	{		
       
   295 	TPckgBuf<TInt> count;
       
   296 	User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetKernelObjectCount, TIpcArgs(&count) ));
       
   297 	
       
   298 	TInt requestedCount = count();
       
   299 	HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyKernelObjectData));
       
   300 	TPtr8 bufferPtr(buffer->Des());
       
   301 		
       
   302 	TIpcArgs args( &count, &bufferPtr );
       
   303 	User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetKernelObjects, args ));
       
   304 	
       
   305 	aKernelObjects.Reset();
       
   306 	
       
   307 	for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyKernelObjectData))
       
   308 		{
       
   309 		TPckgBuf<TMemSpyKernelObjectData> data;
       
   310 		data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyKernelObjectData));
       
   311 		aKernelObjects.AppendL(CMemSpyApiKernelObject::NewLC(data()));
       
   312 		}
       
   313 	
       
   314 	CleanupStack::Pop(aKernelObjects.Count());
       
   315 	CleanupStack::PopAndDestroy(buffer);
       
   316 	}
       
   317 
       
   318 EXPORT_C TInt RMemSpySession::GetKernelObjects( RArray<CMemSpyApiKernelObject*> &aKernelObjects )
       
   319 	{
       
   320 	TRAPD(error, GetKernelObjectsL(aKernelObjects));
       
   321 	return error;
       
   322 	}
       
   323 
       
   324 EXPORT_C void RMemSpySession::GetKernelObjectItemsL( RArray<CMemSpyApiKernelObjectItem*> &aKernelObjectItems, TMemSpyDriverContainerType aForContainer )
       
   325 	{
       
   326 	TPckgBuf<TInt> count;
       
   327 	TPckgBuf<TMemSpyDriverContainerType> type(aForContainer);
       
   328 	User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetKernelObjectItemCount, TIpcArgs(&count, &type) ));
       
   329 
       
   330 	TInt requestedCount = count();
       
   331 	HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyDriverHandleInfoGeneric));
       
   332 	TPtr8 bufferPtr(buffer->Des());
       
   333 	
       
   334 	TIpcArgs args( &count, &type, &bufferPtr );
       
   335 	User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetKernelObjectItems, args ));
       
   336 	
       
   337 	aKernelObjectItems.Reset();
       
   338 	
       
   339 	for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyDriverHandleInfoGeneric))
       
   340 		{
       
   341 		TPckgBuf<TMemSpyDriverHandleInfoGeneric> data;
       
   342 		data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyDriverHandleInfoGeneric));
       
   343 		aKernelObjectItems.AppendL( CMemSpyApiKernelObjectItem::NewLC( data() ) );
       
   344 		}
       
   345 	CleanupStack::Pop(aKernelObjectItems.Count());
       
   346 	CleanupStack::PopAndDestroy(buffer);
       
   347 	}
       
   348 
       
   349 EXPORT_C TInt RMemSpySession::GetKernelObjectItems( RArray<CMemSpyApiKernelObjectItem*> &aKernelObjectItems, TMemSpyDriverContainerType aForContainer )
       
   350 	{
       
   351 	TRAPD(error, GetKernelObjectItemsL(aKernelObjectItems, aForContainer));
       
   352 	return error;
       
   353 	}
       
   354 
       
   355 EXPORT_C void RMemSpySession::GetMemoryTrackingCyclesL(RArray<CMemSpyApiMemoryTrackingCycle*>& aCycles)
       
   356 	{
       
   357 	TPckgBuf<TInt> count;
       
   358 	User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetMemoryTrackingCycleCount, TIpcArgs(&count) ));
       
   359 	
       
   360 	TInt requestedCount = count();
       
   361 	HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyMemoryTrackingCycleData));
       
   362 	TPtr8 bufferPtr(buffer->Des());
       
   363 		
       
   364 	TIpcArgs args( &count, &bufferPtr );
       
   365 	User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetMemoryTrackingCycles, args ));
       
   366 	
       
   367 	aCycles.Reset();
       
   368 	
       
   369 	for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyMemoryTrackingCycleData))
       
   370 		{
       
   371 		TPckgBuf<TMemSpyMemoryTrackingCycleData> data;
       
   372 		data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyMemoryTrackingCycleData));
       
   373 		aCycles.AppendL(CMemSpyApiMemoryTrackingCycle::NewLC(data()));
       
   374 		}
       
   375 	
       
   376 	CleanupStack::Pop(aCycles.Count());
       
   377 	CleanupStack::PopAndDestroy(buffer);
       
   378 	}
       
   379 
       
   380 EXPORT_C void RMemSpySession::OutputAllContainerContents()
       
   381 	{
       
   382 	SendReceive( EMemSpyClientServerOpOutputAllContainerContents );
       
   383 	}
       
   384 
       
   385 
       
   386 //Heap specific operations
       
   387 
       
   388 EXPORT_C CMemSpyApiHeap* RMemSpySession::GetHeapL()
       
   389 	{
       
   390 	CMemSpyApiHeap* aHeap;
       
   391 	
       
   392 	HBufC8* buffer = HBufC8::NewLC( sizeof(TMemSpyHeapData) );
       
   393 	TPtr8 bufferPtr(buffer->Des());
       
   394 	TIpcArgs args( &bufferPtr );
       
   395 	
       
   396 	User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetHeap, args ));
       
   397 	
       
   398 	TPckgBuf<TMemSpyHeapData> data;
       
   399 	data.Copy(bufferPtr.Ptr(), sizeof(TMemSpyHeapData));		
       
   400 	aHeap = CMemSpyApiHeap::NewL( data() );
       
   401 	
       
   402 	CleanupStack::PopAndDestroy(buffer);
       
   403 		
       
   404 	return aHeap;
       
   405 	}
       
   406 
       
   407 EXPORT_C CMemSpyApiHeap* RMemSpySession::GetHeap()
       
   408 	{
       
   409 	CMemSpyApiHeap *result = NULL;
       
   410 	TRAPD(error, result = GetHeapL());
       
   411 	return error == KErrNone ? result : NULL;
       
   412 	}
       
   413 
       
   414 EXPORT_C void RMemSpySession::DumpKernelHeap()
       
   415 	{
       
   416 	SendReceive( EMemSpyClientServerOpDumpKernelHeap );
       
   417 	}
       
   418 
       
   419 EXPORT_C void RMemSpySession::OutputKernelHeapDataL()
       
   420 	{		
       
   421 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpHeapData | KMemSpyOpFlagsIncludesThreadId,
       
   422 			TIpcArgs(KMemSpyClientServerThreadIdKernel)));
       
   423 	
       
   424 	}
       
   425 
       
   426 EXPORT_C void RMemSpySession::OutputKernelHeapData(TRequestStatus& aStatus)
       
   427 	{
       
   428 	SendReceive(EMemSpyClientServerOpHeapData,
       
   429 		TIpcArgs(KMemSpyClientServerThreadIdKernel),
       
   430 		aStatus);
       
   431 	}
       
   432 
       
   433 EXPORT_C void RMemSpySession::OutputThreadHeapDataL( TThreadId aThreadId)
       
   434 	{			
       
   435 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpHeapData | KMemSpyOpFlagsIncludesThreadId,
       
   436 			TIpcArgs(aThreadId)));
       
   437 	}
       
   438 
       
   439 EXPORT_C void RMemSpySession::OutputThreadHeapDataL(const TDesC& aThreadName)
       
   440 	{	
       
   441 	const TIpcArgs args( &aThreadName );
       
   442 	        
       
   443 	User::LeaveIfError( SendReceive( EMemSpyClientServerOpHeapData | KMemSpyOpFlagsIncludesThreadName, args ));	
       
   444 	}
       
   445 
       
   446 EXPORT_C void RMemSpySession::OutputThreadCellListL(TThreadId aThreadId)
       
   447 	{	
       
   448 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpHeapCellListing | KMemSpyOpFlagsIncludesThreadId,
       
   449 			TIpcArgs(aThreadId)));
       
   450 	}
       
   451 
       
   452 EXPORT_C void RMemSpySession::OutputHeapInfoUserL(TThreadId aThreadId)
       
   453 	{
       
   454 	User::LeaveIfError(SendReceive( EMemSpyClientServerOpHeapInfo | KMemSpyOpFlagsIncludesThreadId,
       
   455 			TIpcArgs(aThreadId)));
       
   456 	}
       
   457 
       
   458 EXPORT_C void RMemSpySession::SwitchOutputSinkL( TMemSpySinkType aType )
       
   459 	{
       
   460 	TInt op;
       
   461 	if( aType == ESinkTypeFile )
       
   462 		op = EMemSpyClientServerOpSwitchOutputSinkFile;
       
   463 	else
       
   464 		op = EMemSpyClientServerOpSwitchOutputSinkTrace;
       
   465 			
       
   466 	User::LeaveIfError(SendReceive( op ));
       
   467 	}
       
   468 
       
   469 EXPORT_C void RMemSpySession::SwitchOutputToTraceL()
       
   470 	{
       
   471 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpSwitchOutputSinkTrace));
       
   472 	}
       
   473     
       
   474 EXPORT_C void RMemSpySession::SwitchOutputToFileL(const TDesC& aRootFolder)
       
   475 	{
       
   476 	TIpcArgs args;
       
   477 	if (aRootFolder.Length())
       
   478 		{
       
   479 		args.Set(0, &aRootFolder);
       
   480 		}
       
   481 	
       
   482 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpSwitchOutputSinkFile, args));
       
   483 	}
       
   484 
       
   485 EXPORT_C void RMemSpySession::OutputStackInfoL(TThreadId aThreadId)
       
   486 	{
       
   487 	User::LeaveIfError(SendReceive( EMemSpyClientServerOpStackInfo | KMemSpyOpFlagsIncludesThreadId,
       
   488 			TIpcArgs(aThreadId)));
       
   489 	}
       
   490 
       
   491 EXPORT_C void RMemSpySession::OutputStackDataL(TThreadId aThreadId, TMemSpyDriverDomainType aType )
       
   492 	{
       
   493 	TInt op;
       
   494 	if( aType == EMemSpyDriverDomainUser )
       
   495 		op = EMemSpyClientServerOpStackDataUser;
       
   496 	else
       
   497 		op = EMemSpyClientServerOpStackDataKernel;
       
   498 	
       
   499 	User::LeaveIfError(SendReceive( op | KMemSpyOpFlagsIncludesThreadId,
       
   500 			TIpcArgs(aThreadId, aType)));
       
   501 		
       
   502 	}
       
   503 
       
   504 EXPORT_C void RMemSpySession::OutputThreadInfoHandlesL(TThreadId aThreadId)
       
   505 	{
       
   506 	TPckgBuf<TThreadId> id(aThreadId);
       
   507 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpOutputInfoHandles, TIpcArgs( &id )));	
       
   508 	}
       
   509 
       
   510 EXPORT_C void RMemSpySession::OutputAOListL(TThreadId aId, TMemSpyThreadInfoItemType aType)
       
   511 	{
       
   512 	TPckgBuf<TThreadId> id(aId);
       
   513 	TPckgBuf<TMemSpyThreadInfoItemType> type(aType);
       
   514 	
       
   515 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpOutputAOList, TIpcArgs( &id, &type )));
       
   516 	}
       
   517 
       
   518 EXPORT_C void RMemSpySession::OutputKernelObjectsL()
       
   519 	{
       
   520 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpEnumerateKernelContainerAll));
       
   521 	}
       
   522 
       
   523 EXPORT_C void RMemSpySession::OutputCompactStackInfoL()
       
   524 	{
       
   525 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpStackInfoCompact)); 
       
   526 	}
       
   527 
       
   528 EXPORT_C void RMemSpySession::OutputCompactHeapInfoL()
       
   529 	{
       
   530 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpHeapInfoCompact)); 
       
   531 	}
       
   532 // Asynchronous operations
       
   533 EXPORT_C void RMemSpySession::OutputPhoneInfo(TRequestStatus& aStatus)
       
   534 	{	
       
   535 	SendReceive(EMemSpyClientServerOpSummaryInfo | KMemSpyOpFlagsAsyncOperation, TIpcArgs(), aStatus);
       
   536 	}
       
   537 
       
   538 EXPORT_C void RMemSpySession::OutputDetailedPhoneInfo(TRequestStatus& aStatus)
       
   539 	{	
       
   540 	SendReceive(EMemSpyClientServerOpSummaryInfoDetailed | KMemSpyOpFlagsAsyncOperation, TIpcArgs(), aStatus);
       
   541 	}
       
   542 
       
   543 EXPORT_C void RMemSpySession::OutputHeapInfo(TRequestStatus& aStatus)
       
   544 	{	
       
   545 	SendReceive(EMemSpyClientServerOpHeapInfo | KMemSpyOpFlagsAsyncOperation, TIpcArgs(), aStatus);
       
   546 	}
       
   547 
       
   548 EXPORT_C void RMemSpySession::OutputCompactHeapInfo(TRequestStatus& aStatus)
       
   549 	{	
       
   550 	SendReceive(EMemSpyClientServerOpHeapInfoCompact | KMemSpyOpFlagsAsyncOperation, TIpcArgs(), aStatus);
       
   551 	}
       
   552 
       
   553 EXPORT_C void RMemSpySession::OutputHeapCellListing(TRequestStatus& aStatus)
       
   554 	{	
       
   555 	SendReceive(EMemSpyClientServerOpHeapCellListing | KMemSpyOpFlagsAsyncOperation, TIpcArgs(), aStatus);
       
   556 	}
       
   557 
       
   558 EXPORT_C void RMemSpySession::OutputHeapData(TRequestStatus& aStatus)
       
   559 	{	
       
   560 	SendReceive(EMemSpyClientServerOpHeapData | KMemSpyOpFlagsAsyncOperation, TIpcArgs(), aStatus);
       
   561 	}
       
   562 
       
   563 // synchronous version of the operation - for CLI
       
   564 EXPORT_C void RMemSpySession::OutputHeapData()
       
   565 	{
       
   566 	SendReceive(EMemSpyClientServerOpHeapData);
       
   567 	}
       
   568 
       
   569 EXPORT_C void RMemSpySession::OutputStackInfo(TRequestStatus& aStatus)
       
   570 	{	
       
   571 	SendReceive(EMemSpyClientServerOpStackInfo | KMemSpyOpFlagsAsyncOperation, TIpcArgs(), aStatus);
       
   572 	}
       
   573 
       
   574 EXPORT_C void RMemSpySession::OutputCompactStackInfo(TRequestStatus& aStatus)
       
   575 	{	
       
   576 	SendReceive(EMemSpyClientServerOpStackInfoCompact | KMemSpyOpFlagsAsyncOperation, TIpcArgs(), aStatus);
       
   577 	}
       
   578 
       
   579 EXPORT_C void RMemSpySession::OutputUserStackData(TRequestStatus& aStatus)
       
   580 	{	
       
   581 	SendReceive(EMemSpyClientServerOpStackDataUser | KMemSpyOpFlagsAsyncOperation, TIpcArgs(), aStatus);
       
   582 	}
       
   583 
       
   584 EXPORT_C void RMemSpySession::OutputKernelStackData(TRequestStatus& aStatus)
       
   585 	{	
       
   586 	SendReceive(EMemSpyClientServerOpStackDataKernel | KMemSpyOpFlagsAsyncOperation, TIpcArgs(), aStatus);
       
   587 	}
       
   588 
       
   589 // Synchronous operations
       
   590 EXPORT_C void RMemSpySession::OutputPhoneInfo()
       
   591 	{	
       
   592 	SendReceive( EMemSpyClientServerOpSummaryInfo , TIpcArgs() );
       
   593 	}
       
   594 
       
   595 EXPORT_C void RMemSpySession::SetSwmtConfig( TMemSpyEngineHelperSysMemTrackerConfig aConfig )
       
   596 	{
       
   597 	TPckgBuf<TMemSpyEngineHelperSysMemTrackerConfig> config(aConfig);
       
   598 	TIpcArgs args( &config );
       
   599 	
       
   600 	SendReceive( EMemSpyClientServerOpSetSwmtConfig, args) ;
       
   601 	}
       
   602 
       
   603 EXPORT_C void RMemSpySession::SetSwmtAutoStartProcessList( CArrayFixFlat<TUid>* aList )
       
   604 	{
       
   605 	TInt count = aList->Count();
       
   606 	TIpcArgs args( &aList, &count );
       
   607 	
       
   608 	SendReceive( EMemSpyClientServerOpSetSwmtAutoStartProcessList, args );
       
   609 	}
       
   610 
       
   611 EXPORT_C void RMemSpySession::SwmtResetTracking()
       
   612 	{
       
   613 	SendReceive( EMemSpyClientServerOpSystemWideMemoryTrackingReset );
       
   614 	}
       
   615 
       
   616 EXPORT_C void RMemSpySession::GetOutputSink( TMemSpySinkType aType )
       
   617 	{
       
   618 	TPckgBuf<TMemSpySinkType> type( aType );
       
   619 	TIpcArgs args( &type );
       
   620 	
       
   621 	SendReceive( EMemSpyClientServerOpGetOutputSink, args );
       
   622 	}
       
   623 
       
   624 EXPORT_C void RMemSpySession::NotifyDeviceWideOperationProgress(TMemSpyDeviceWideOperationProgress &aProgress, TRequestStatus &aStatus)
       
   625 	{
       
   626 	SendReceive(EMemSpyClientServerOpNotifyDeviceWideOperationProgress | KMemSpyOpFlagsAsyncOperation,
       
   627 			TIpcArgs(&aProgress.iProgress, &aProgress.iDescription), 
       
   628 			aStatus);
       
   629 	}
       
   630 
       
   631 EXPORT_C void RMemSpySession::CancelDeviceWideOperationL()
       
   632 	{
       
   633 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpCancelDeviceWideOperation));
       
   634 	}
       
   635 
       
   636 // SWMT operations
       
   637 EXPORT_C void RMemSpySession::SetSwmtCategoriesL(TInt aCategories)
       
   638 	{
       
   639 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpSystemWideMemoryTrackingCategoriesSet,
       
   640 			TIpcArgs(aCategories)));
       
   641 	}
       
   642 
       
   643 EXPORT_C void RMemSpySession::SetSwmtHeapDumpsEnabledL(TBool aEnabled)
       
   644 	{
       
   645 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpSystemWideMemoryTrackingHeapDumpSet,
       
   646 			TIpcArgs(aEnabled)));
       
   647 	}
       
   648 
       
   649 EXPORT_C TBool RMemSpySession::IsSwmtRunningL()
       
   650 	{
       
   651 	TPckgBuf<TBool> ret;
       
   652 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpIsSwmtRunning, TIpcArgs(&ret)));
       
   653 	
       
   654 	return ret();
       
   655 	}
       
   656 
       
   657 EXPORT_C void RMemSpySession::StartSwmtTimerL(TInt aPeriod)
       
   658 	{
       
   659 	SetSwmtTimerIntervalL(aPeriod);
       
   660 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpSystemWideMemoryTrackingTimerStart));
       
   661 	}
       
   662 
       
   663 EXPORT_C void RMemSpySession::StartSwmtTimerL()
       
   664 	{
       
   665 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpSystemWideMemoryTrackingTimerStart));
       
   666 	}
       
   667 
       
   668 EXPORT_C void RMemSpySession::SetSwmtTimerIntervalL(TInt aPeriod)
       
   669 	{
       
   670 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpSystemWideMemoryTrackingTimerPeriodSet,
       
   671 			TIpcArgs(aPeriod)));
       
   672 	}
       
   673 
       
   674 EXPORT_C void RMemSpySession::StopSwmtTimerL()
       
   675 	{
       
   676 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpSystemWideMemoryTrackingTimerStop));
       
   677 	}
       
   678 
       
   679 
       
   680 EXPORT_C void RMemSpySession::ForceSwmtUpdateL()
       
   681 	{
       
   682 	User::LeaveIfError(SendReceive(EMemSpyClientServerOpSystemWideMemoryTrackingForceUpdate));
       
   683 	}
       
   684 
       
   685 EXPORT_C void RMemSpySession::ForceSwmtUpdate(TRequestStatus& aStatus)
       
   686 	{
       
   687 	SendReceive(EMemSpyClientServerOpSystemWideMemoryTrackingForceUpdate, 
       
   688 			TIpcArgs(),
       
   689 			aStatus);
       
   690 	}
       
   691 
       
   692 EXPORT_C void RMemSpySession::SetSwmtFilter( const TDesC& aFilter )
       
   693 	{	
       
   694 	TIpcArgs args( &aFilter );
       
   695 	User::LeaveIfError( SendReceive( EMemSpyClientServerOpSystemWideMemoryTrackingThreadNameFilterSet, args ) );
       
   696 	}
       
   697 
       
   698 EXPORT_C TInt TMemSpyDeviceWideOperationProgress::Progress() const 
       
   699 	{
       
   700 	return iProgress();
       
   701 	}
       
   702 
       
   703 EXPORT_C const TDesC& TMemSpyDeviceWideOperationProgress::Description() const
       
   704 	{
       
   705 	return iDescription;
       
   706 	}