memspy/Engine/Source/ClientServer/MemSpyEngineServer.cpp
changeset 22 a009639409f5
parent 0 a03f92240627
child 30 86a2e675b80a
equal deleted inserted replaced
17:67c6ff54ec25 22:a009639409f5
    17 
    17 
    18 #include "MemSpyEngineServer.h"
    18 #include "MemSpyEngineServer.h"
    19 
    19 
    20 // System includes
    20 // System includes
    21 #include <e32svr.h>
    21 #include <e32svr.h>
       
    22 #include <w32std.h>
       
    23 #include <APGTASK.H>
       
    24 #include <APGWGNAM.H>  
    22 
    25 
    23 // User includes
    26 // User includes
    24 #include <memspy/engine/memspyengine.h>
    27 #include <memspy/engine/memspyengine.h>
    25 #include <memspy/engine/memspyenginelogger.h>
    28 #include <memspy/engine/memspyenginelogger.h>
    26 #include <memspyengineclientinterface.h>
    29 #include <memspyengineclientinterface.h>
    36 #include <memspy/engine/memspyenginehelperfilesystem.h>
    39 #include <memspy/engine/memspyenginehelperfilesystem.h>
    37 #include <memspy/engine/memspyenginehelperram.h>
    40 #include <memspy/engine/memspyenginehelperram.h>
    38 #include <memspy/engine/memspyenginehelpersysmemtracker.h>
    41 #include <memspy/engine/memspyenginehelpersysmemtracker.h>
    39 #include <memspy/engine/memspyenginehelpersysmemtrackerconfig.h>
    42 #include <memspy/engine/memspyenginehelpersysmemtrackerconfig.h>
    40 #include <memspy/engine/memspyenginehelperkernelcontainers.h>
    43 #include <memspy/engine/memspyenginehelperkernelcontainers.h>
       
    44 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    45 
       
    46 #include <memspy/engine/memspyprocessdata.h>
       
    47 #include <memspy/engine/memspythreaddata.h>
       
    48 #include <memspy/engine/memspykernelobjectdata.h>
       
    49 #include <memspy/engine/memspythreadinfoitemdata.h>
    41 
    50 
    42 
    51 
    43 CMemSpyEngineServer::CMemSpyEngineServer( CMemSpyEngine& aEngine )
    52 CMemSpyEngineServer::CMemSpyEngineServer( CMemSpyEngine& aEngine )
    44 :   CServer2( EPriorityNormal ), iEngine( aEngine )
    53 :   CServer2( EPriorityNormal ), iEngine( aEngine )
    45     {
    54     {
   165     aMessage.Complete( error );
   174     aMessage.Complete( error );
   166 
   175 
   167     TRACE( RDebug::Print( _L("[MemSpy] CMemSpyEngineSession::ServiceL() - END - this: 0x%08x, fn: 0x%08x, id: %4d, client: %S"), this, aMessage.Function(), iClientThreadId, iClientThreadName ) );
   176     TRACE( RDebug::Print( _L("[MemSpy] CMemSpyEngineSession::ServiceL() - END - this: 0x%08x, fn: 0x%08x, id: %4d, client: %S"), this, aMessage.Function(), iClientThreadId, iClientThreadName ) );
   168 	}
   177 	}
   169 
   178 
   170 
   179 // ---------------------------------------------------------
       
   180 // DoServiceL( const RMessage2& aMessage )
       
   181 // ---------------------------------------------------------
       
   182 //
   171 void CMemSpyEngineSession::DoServiceL( const RMessage2& aMessage )
   183 void CMemSpyEngineSession::DoServiceL( const RMessage2& aMessage )
       
   184 	{
       
   185 	TInt function = aMessage.Function() & KMemSpyOpFlagsTypeMask;
       
   186 	if (function >= EMemSpyClientServerOpMarkerUiFirst && 
       
   187 		function < EMemSpyClientServerOpMarkerUiLast)
       
   188 		
       
   189 		DoUiServiceL(aMessage);
       
   190 	else
       
   191 		DoCmdServiceL(aMessage);
       
   192 	}
       
   193 
       
   194 // ---------------------------------------------------------
       
   195 // DoUiServiceL( const RMessage2& aMessage )
       
   196 // ---------------------------------------------------------
       
   197 //
       
   198 void CMemSpyEngineSession::DoUiServiceL( const RMessage2& aMessage )
       
   199     {
       
   200 	switch (aMessage.Function() & KMemSpyOpFlagsTypeMask)
       
   201 		{
       
   202 		case EMemSpyClientServerOpGetProcessCount:
       
   203 			{
       
   204 			aMessage.WriteL(0, TPckgBuf<TInt>(iEngine.Container().Count()));
       
   205 			break;
       
   206 			}
       
   207 		case EMemSpyClientServerOpGetProcesses:
       
   208 			{
       
   209 			CMemSpyEngineObjectContainer& list = iEngine.Container();
       
   210 			
       
   211 			TPckgBuf<TInt> a0;
       
   212 			aMessage.ReadL(0, a0);
       
   213 			TInt realCount = Min(a0(), list.Count());
       
   214 			
       
   215 			for(TInt i=0, offset = 0; i<realCount; i++, offset += sizeof(TMemSpyProcessData))
       
   216 				{
       
   217 				CMemSpyProcess& process = iEngine.Container().At(i);
       
   218 				TMemSpyProcessData data;
       
   219 				data.iId = process.Id();
       
   220 				data.iName.Copy(process.Name());
       
   221 				
       
   222 				TPckgBuf<TMemSpyProcessData> buffer(data);
       
   223 				aMessage.WriteL(1, buffer, offset);
       
   224 				}
       
   225 			
       
   226 			a0 = list.Count();
       
   227 			aMessage.WriteL(0, a0);
       
   228 	
       
   229 			break;
       
   230 			}
       
   231 		case EMemSpyClienServerOpGetProcessIdByName:
       
   232 			{
       
   233 			TFullName processName;
       
   234 			aMessage.ReadL(0, processName);
       
   235 			
       
   236 			TBool found(EFalse);
       
   237 			
       
   238 			for (TInt i=0; i<iEngine.Container().Count(); i++)
       
   239 				{
       
   240 				CMemSpyProcess& process = iEngine.Container().At(i);
       
   241 				if (process.Name().FindF(processName) >= 0)
       
   242 					{
       
   243 					found = ETrue;
       
   244 					TPckgBuf<TProcessId> procId(process.Id());
       
   245 					aMessage.WriteL(1, procId);
       
   246 					}
       
   247 				}
       
   248 			
       
   249 			if (!found)
       
   250 				{
       
   251 				User::Leave(KErrNotFound);
       
   252 				}
       
   253 			
       
   254 			break;
       
   255 			}
       
   256 		case EMemSpyClientServerOpProcessSystemPermanentOrCritical:
       
   257 			{
       
   258 			TBool ret = EFalse;
       
   259 			TPckgBuf<TProcessId> id;
       
   260 			aMessage.ReadL( 0, id );
       
   261 			
       
   262 			CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   263 			CMemSpyProcess& process = container.ProcessByIdL( id() );
       
   264 			
       
   265 			process.Open();
       
   266 	
       
   267 			if  ( process.IsSystemPermanent() || process.IsSystemCritical() )
       
   268 				{
       
   269 				ret = ETrue;
       
   270 				}
       
   271 			TPckgBuf<TBool> retBuf( ret );
       
   272 			aMessage.WriteL( 1, retBuf );
       
   273 			
       
   274 			break;
       
   275 			}
       
   276 		case EMemSpyClientServerOpEndProcess:
       
   277 			{
       
   278 			TPckgBuf<TProcessId> id;
       
   279 			aMessage.ReadL( 0, id );
       
   280 			TPckgBuf<TMemSpyEndType> type;
       
   281 			aMessage.ReadL( 1, type );
       
   282 					
       
   283 			CMemSpyEngineObjectContainer& container = iEngine.Container();			
       
   284 			CMemSpyProcess& process = container.ProcessByIdL( id() );
       
   285 									
       
   286 			switch ( type() )
       
   287 				{
       
   288 				case ETerminate:
       
   289 					{
       
   290 					process.TerminateL();
       
   291 					break;
       
   292 					}
       
   293 				case EPanic:
       
   294 					{
       
   295 					process.PanicL();
       
   296 					break;
       
   297 					}
       
   298 				case EKill:
       
   299 					{
       
   300 					process.KillL();
       
   301 					break;
       
   302 					}
       
   303 				}																
       
   304 			break;
       
   305 			}
       
   306 		case EMemSpyClientServerOpSwitchToProcess:
       
   307 			{/*
       
   308 			TInt wgCount;
       
   309 			RWsSession wsSession;
       
   310 			User::LeaveIfError( wsSession.Connect() );
       
   311 			CleanupClosePushL( wsSession );
       
   312 			User::LeaveIfError( wgCount = wsSession.NumWindowGroups() );
       
   313 			RArray<RWsSession::TWindowGroupChainInfo> wgArray;
       
   314 			CleanupClosePushL( wgArray );
       
   315 			User::LeaveIfError( wsSession.WindowGroupList( &wgArray ) );
       
   316 			TApaTask task( wsSession );
       
   317 			TBool brought( EFalse );
       
   318 			TInt wgId( KErrNotFound );
       
   319 			TThreadId threadId;
       
   320 			
       
   321 			TPckgBuf<TProcessId> id;
       
   322 			aMessage.ReadL( 0, id );
       
   323 			CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   324 			CMemSpyProcess& process = container.ProcessByIdL( id() );
       
   325 			
       
   326 			// loop trough threads in a process
       
   327 			for ( TInt i = 0; i < process.MdcaCount(); i++ )
       
   328 				{
       
   329 				TInt wgCountLocal = wgCount;
       
   330 							
       
   331 				// loop trough all window groups and see if a thread id matches
       
   332 				while( !brought && wgCountLocal-- )
       
   333 					{
       
   334 					wgId = wgArray[wgCountLocal].iId;
       
   335 					User::LeaveIfError( wsSession.GetWindowGroupClientThreadId( wgId, threadId ) );
       
   336 					if ( threadId == process.At( i ).Id() )
       
   337 						{
       
   338 						CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( wsSession, wgId );
       
   339 						task.SetWgId( wgId );
       
   340 						if ( !wgName->Hidden() && task.Exists() )
       
   341 							{
       
   342 							task.BringToForeground();
       
   343 							brought = ETrue;                        
       
   344 							}
       
   345 						CleanupStack::PopAndDestroy( wgName );
       
   346 						}
       
   347 					}
       
   348 				}
       
   349 			
       
   350 			TPckgBuf<TBool> ret( brought );
       
   351 			aMessage.WriteL( 1, ret );
       
   352 			
       
   353 			break;*/
       
   354 			}
       
   355 		case EMemSpyClientServerOpGetThreadCount:
       
   356 			{
       
   357 			TPckgBuf<TProcessId> pid;
       
   358 			aMessage.ReadL(1, pid);
       
   359 			CMemSpyProcess& process = iEngine.Container().ProcessByIdL(pid());
       
   360 			process.Open();
       
   361 			aMessage.WriteL(0, TPckgBuf<TInt>(process.Count()));
       
   362 			process.Close();
       
   363 			break;
       
   364 			}
       
   365 		case EMemSpyClientServerOpGetThreads:
       
   366 			{
       
   367 			TPckgBuf<TProcessId> pid;
       
   368 			aMessage.ReadL(2, pid);
       
   369 			
       
   370 			CMemSpyProcess& list = iEngine.Container().ProcessByIdL(pid());
       
   371 			list.Open();
       
   372 			
       
   373 			TPckgBuf<TInt> a0;
       
   374 			aMessage.ReadL(0, a0);
       
   375 			TInt realCount = Min(a0(), list.Count());
       
   376 			
       
   377 			for(TInt i=0, offset = 0; i<realCount; i++, offset += sizeof(TMemSpyThreadData))
       
   378 				{
       
   379 				CMemSpyThread& thread = list.At(i);
       
   380 				thread.Open();
       
   381 				
       
   382 				TMemSpyThreadData data;
       
   383 				data.iId = thread.Id();
       
   384 				data.iName.Copy(thread.Name());
       
   385 				data.iThreadPriority = thread.Priority();
       
   386 				
       
   387 				TPckgBuf<TMemSpyThreadData> buffer(data);
       
   388 				aMessage.WriteL(1, buffer, offset);
       
   389 				
       
   390 				thread.Close();
       
   391 				}
       
   392 			
       
   393 			a0 = list.Count();
       
   394 			aMessage.WriteL(0, a0);
       
   395 			
       
   396 			list.Close();
       
   397 	
       
   398 			break;
       
   399 			}
       
   400 		case EMemSpyClientServerOpSetThreadPriority:
       
   401 			{
       
   402 			TPckgBuf<TThreadId> tid;
       
   403 			TPckgBuf<TInt> priority;
       
   404 			aMessage.ReadL(0, tid);
       
   405 			aMessage.ReadL(1, priority);
       
   406 			
       
   407 			CMemSpyProcess* process = NULL;
       
   408 			CMemSpyThread* thread = NULL; 
       
   409 			User::LeaveIfError(iEngine.Container().ProcessAndThreadByThreadId(tid(), process, thread));
       
   410 			
       
   411 			if (thread)
       
   412 				{				
       
   413 				thread->Open();
       
   414 				thread->SetPriorityL(static_cast<TThreadPriority>(priority()));				
       
   415 				thread->Close();
       
   416 				}					
       
   417 			break;
       
   418 			}
       
   419 		case EMemSpyClientServerOpThreadSystemPermanentOrCritical:
       
   420 			{
       
   421 			TBool ret = EFalse;
       
   422 			TPckgBuf<TThreadId> id;
       
   423 			aMessage.ReadL( 0, id );
       
   424 			
       
   425 			CMemSpyEngineObjectContainer& container = iEngine.Container();            
       
   426 			CMemSpyProcess* process = NULL;
       
   427 			CMemSpyThread* thread = NULL; 
       
   428 			User::LeaveIfError( container.ProcessAndThreadByThreadId( id(), process, thread ) );
       
   429 			
       
   430 			if ( thread )
       
   431 				{				
       
   432 				thread->Open();
       
   433 				
       
   434 				if  ( thread->IsSystemPermanent() || thread->IsSystemCritical() )
       
   435 					{			
       
   436 					ret = ETrue;					
       
   437 					}
       
   438 				thread->Close();
       
   439 				}
       
   440 			TPckgBuf<TBool> retBuf( ret );
       
   441 			aMessage.WriteL( 1, retBuf );
       
   442 							
       
   443 			break;
       
   444 			}
       
   445 		case EMemSpyClientServerOpEndThread:
       
   446 			{
       
   447 			TPckgBuf<TThreadId> id;
       
   448 			aMessage.ReadL( 0, id );
       
   449 			TPckgBuf<TMemSpyEndType> type;
       
   450 			aMessage.ReadL( 1, type );
       
   451 			
       
   452 			CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   453 			CMemSpyProcess* process = NULL;
       
   454 			CMemSpyThread* thread = NULL; 
       
   455 			User::LeaveIfError( container.ProcessAndThreadByThreadId( id(), process, thread ) );
       
   456 			
       
   457 			if( thread )
       
   458 				{
       
   459 				switch ( type() )
       
   460 					{
       
   461 					case ETerminate:
       
   462 						{
       
   463 						thread->TerminateL();
       
   464 						break;
       
   465 						}
       
   466 					case EPanic:
       
   467 						{
       
   468 						thread->PanicL();
       
   469 						break;
       
   470 						}
       
   471 					case EKill:
       
   472 						{
       
   473 						thread->KillL();
       
   474 						break;
       
   475 						}
       
   476 					}				
       
   477 				}			
       
   478 			break;
       
   479 			}
       
   480 		case EMemSpyClientServerOpSwitchToThread:
       
   481 			{
       
   482 			TInt wgCount;
       
   483 			RWsSession wsSession;
       
   484 			User::LeaveIfError( wsSession.Connect() );
       
   485 			CleanupClosePushL( wsSession );
       
   486 			User::LeaveIfError( wgCount = wsSession.NumWindowGroups() );
       
   487 			RArray<RWsSession::TWindowGroupChainInfo> wgArray;
       
   488 			CleanupClosePushL( wgArray );
       
   489 			User::LeaveIfError( wsSession.WindowGroupList( &wgArray ) );
       
   490 			TApaTask task( wsSession );
       
   491 			TBool brought( EFalse );
       
   492 			TInt wgId( KErrNotFound );
       
   493 			TThreadId threadId;
       
   494 					
       
   495 			TPckgBuf<TThreadId> id;
       
   496 			aMessage.ReadL( 0, id );
       
   497 					
       
   498 			// loop trough all window groups and see if a thread id matches
       
   499 			while( !brought && wgCount-- )
       
   500 				{
       
   501 				wgId = wgArray[wgCount].iId;
       
   502 				User::LeaveIfError( wsSession.GetWindowGroupClientThreadId( wgId, threadId ) );
       
   503 				if ( threadId == id() )
       
   504 					{
       
   505 					CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( wsSession, wgId );
       
   506 					task.SetWgId( wgId );
       
   507 					if ( !wgName->Hidden() && task.Exists() )
       
   508 						{
       
   509 						task.BringToForeground();
       
   510 						brought = ETrue;                        
       
   511 						}
       
   512 					CleanupStack::PopAndDestroy( wgName );
       
   513 					}
       
   514 				}			
       
   515 			TPckgBuf<TBool> ret( brought );
       
   516 			aMessage.WriteL( 1, ret );															
       
   517 					
       
   518 			break;
       
   519 			}		
       
   520 		case EMemSpyClientServerOpGetInfoItemType:
       
   521 			{
       
   522 			TPckgBuf<TInt> index;
       
   523 			aMessage.ReadL( 0, index );			
       
   524 			TPckgBuf<TThreadId> id;
       
   525 			aMessage.ReadL( 1, id);
       
   526 								
       
   527 			CMemSpyEngineObjectContainer& container = iEngine.Container();            
       
   528 			CMemSpyProcess* process = NULL; //not needed
       
   529 			CMemSpyThread* thread = NULL; 
       
   530 			User::LeaveIfError( container.ProcessAndThreadByThreadId( id(), process, thread ) );
       
   531 		            
       
   532 			thread->Open();
       
   533 			process->Open();
       
   534 		            
       
   535 			CMemSpyThreadInfoContainer& threadInfoContainer = thread->InfoContainerForceSyncronousConstructionL();                        
       
   536 			TMemSpyThreadInfoItemType retType = threadInfoContainer.Item( index() ).Type();
       
   537 			
       
   538 			TPckgBuf<TMemSpyThreadInfoItemType> ret( retType );
       
   539 			aMessage.WriteL( 2, ret );			
       
   540 			
       
   541 			thread->Close();
       
   542 			process->Close();			
       
   543 			
       
   544 			break;
       
   545 			}
       
   546 		case EMemSpyClientServerOpGetThreadInfoItemsCount:
       
   547 			{		
       
   548 			TPckgBuf<TThreadId> id;
       
   549 			aMessage.ReadL( 0, id );
       
   550 			TPckgBuf<TMemSpyThreadInfoItemType> type;
       
   551 			aMessage.ReadL( 1, type );					 
       
   552 			
       
   553 			CMemSpyEngineObjectContainer& container = iEngine.Container();            
       
   554 			CMemSpyProcess* process = NULL;
       
   555 			CMemSpyThread* thread = NULL; 
       
   556 			
       
   557 			container.ProcessAndThreadByThreadId( id(), process, thread );
       
   558 			
       
   559 			thread->Open();
       
   560 			process->Open();
       
   561 				    
       
   562 			CMemSpyThreadInfoContainer& threadInfoContainer = thread->InfoContainerForceSyncronousConstructionL();                 
       
   563 								
       
   564 			CMemSpyThreadInfoItemBase& threadInfoItemBase = threadInfoContainer.Item( type() );
       
   565 				    
       
   566 			TInt count = threadInfoItemBase.MdcaCount();		    
       
   567 			TPckgBuf<TInt> tempret( count );
       
   568 			aMessage.WriteL( 2, tempret );
       
   569 					
       
   570 			thread->Close();
       
   571 			process->Close();
       
   572 					
       
   573 			break;
       
   574 			}		
       
   575 		case EMemSpyClientServerOpGetThreadInfoItems:
       
   576 			{
       
   577 			TPckgBuf<TInt> count;
       
   578 			aMessage.ReadL( 0, count );						
       
   579 			TPckgBuf<TThreadId> id;
       
   580 			aMessage.ReadL( 1, id );
       
   581 			TPckgBuf<TMemSpyThreadInfoItemType> type;
       
   582 			aMessage.ReadL( 2, type );			
       
   583 			
       
   584 			CMemSpyEngineObjectContainer& container = iEngine.Container();            
       
   585 			CMemSpyProcess* process = NULL;
       
   586 			CMemSpyThread* thread = NULL; 
       
   587 			User::LeaveIfError( container.ProcessAndThreadByThreadId( id() , process, thread ) );
       
   588 							  
       
   589 			process->Open();
       
   590 			thread->Open();
       
   591 					
       
   592 			CMemSpyThreadInfoContainer& threadInfoContainer = thread->InfoContainerForceSyncronousConstructionL();      
       
   593 					
       
   594 			CMemSpyThreadInfoItemBase& threadInfoItemBase = threadInfoContainer.Item( type() ); //get ThreadInfoItemBaseByType
       
   595 			
       
   596 			TInt itemCount = Min(count(), threadInfoItemBase.MdcaCount());
       
   597 					
       
   598 			for( TInt i=0, offset = 0; i<itemCount; i++, offset += sizeof( TMemSpyThreadInfoItemData ) )
       
   599 				{
       
   600 				TMemSpyThreadInfoItemData data;
       
   601 				
       
   602 				TPtrC caption(threadInfoItemBase.MdcaPoint(i).Mid(1));
       
   603 				TInt tabPos = caption.Locate('\t');
       
   604 				if (tabPos != KErrNotFound)
       
   605 					caption.Set(caption.Left(tabPos));
       
   606 				
       
   607 				TPtrC value(threadInfoItemBase.MdcaPoint(i));
       
   608 				tabPos = value.LocateReverse('\t');
       
   609 				if (tabPos != KErrNotFound)
       
   610 					value.Set(value.Mid(tabPos + 1));
       
   611 												
       
   612 				data.iCaption.Copy( caption );
       
   613 				data.iValue.Copy( value );
       
   614 							
       
   615 				TPckgBuf<TMemSpyThreadInfoItemData> buffer(data);
       
   616 				aMessage.WriteL(3, buffer, offset);				
       
   617 				}			
       
   618 			aMessage.WriteL(0, count);						
       
   619 					
       
   620 			thread->Close();
       
   621 			process->Close();
       
   622 					
       
   623 			break;
       
   624 			}
       
   625 		// --- KernelObjects related functions ---
       
   626 		case EMemSpyClientServerOpGetKernelObjectCount:
       
   627 			{
       
   628 			TInt iCount = EMemSpyDriverContainerTypeLast - EMemSpyDriverContainerTypeFirst;
       
   629 			TPckgBuf<TInt> ret( iCount );
       
   630 			aMessage.WriteL(0, ret);			
       
   631 			break;
       
   632 			}
       
   633 		case EMemSpyClientServerOpGetKernelObjects:
       
   634 			{
       
   635 			TPckgBuf<TInt> count;
       
   636 			aMessage.ReadL(0, count);
       
   637 			
       
   638 			CMemSpyEngineGenericKernelObjectContainer* model = iEngine.HelperKernelContainers().ObjectsAllL(); //contains all the objects
       
   639 			CleanupStack::PushL( model );
       
   640 			
       
   641 			for( TInt i=0, offset = 0; i<count(); i++, offset += sizeof( TMemSpyKernelObjectData ) )
       
   642 				{
       
   643 				TMemSpyKernelObjectData data;
       
   644 				
       
   645 				TPtrC name(model->At(i).Name().Mid(1));
       
   646 				TInt tabPos = name.Locate('\t');
       
   647 				if (tabPos != KErrNotFound)
       
   648 					name.Set(name.Left(tabPos));
       
   649 												
       
   650 				data.iName.Copy(name);
       
   651 				data.iType = model->At(i).Type();
       
   652 				data.iCount = model->At(i).Count();											
       
   653 				data.iSize = model->At(i).Count() * model->At(i).Count();
       
   654 	
       
   655 				TPckgBuf<TMemSpyKernelObjectData> buffer(data);
       
   656 				aMessage.WriteL(1, buffer, offset);
       
   657 				}			
       
   658 			aMessage.WriteL(0, count);
       
   659 			CleanupStack::PopAndDestroy( model );
       
   660 			break;
       
   661 			}
       
   662 		case EMemSpyClientServerOpGetKernelObjectItemCount:
       
   663 			{
       
   664 			TPckgBuf<TMemSpyDriverContainerType> tempType;
       
   665 			aMessage.ReadL(1, tempType); //get type of kernel object
       
   666 			TMemSpyDriverContainerType type = tempType();
       
   667 			
       
   668 			CMemSpyEngineHelperKernelContainers& kernelContainerManager = iEngine.HelperKernelContainers();
       
   669 			CMemSpyEngineGenericKernelObjectList* iObjectList = kernelContainerManager.ObjectsForSpecificContainerL( type );
       
   670 			CleanupStack::PushL( iObjectList );
       
   671 			
       
   672 			TInt count = iObjectList->Count();
       
   673 			TPckgBuf<TInt> ret( count );
       
   674 			aMessage.WriteL( 0, ret );
       
   675 			
       
   676 			CleanupStack::PopAndDestroy( iObjectList );
       
   677 			break;
       
   678 			}
       
   679 		case EMemSpyClientServerOpGetKernelObjectItems:
       
   680 			{
       
   681 			TPckgBuf<TInt> count;
       
   682 			TPckgBuf<TMemSpyDriverContainerType> tempType;
       
   683 			aMessage.ReadL( 0, count ); //get count of items
       
   684 			aMessage.ReadL(1, tempType); //get type of kernel object
       
   685 			TInt c = count();
       
   686 			
       
   687 			CMemSpyEngineHelperKernelContainers& kernelContainerManager = iEngine.HelperKernelContainers();
       
   688 			CMemSpyEngineGenericKernelObjectList* iObjectList = kernelContainerManager.ObjectsForSpecificContainerL( tempType() );
       
   689 			CleanupStack::PushL( iObjectList );
       
   690 			
       
   691 			for( TInt i=0, offset = 0; i<c; i++, offset += sizeof( TMemSpyDriverHandleInfoGeneric ) )
       
   692 				{
       
   693 				TMemSpyDriverHandleInfoGeneric data;								
       
   694 															
       
   695 				data = iObjectList->At( i );
       
   696 				
       
   697 				TPckgBuf<TMemSpyDriverHandleInfoGeneric> buffer(data);
       
   698 				aMessage.WriteL(2, buffer, offset);
       
   699 				}			
       
   700 			
       
   701 			CleanupStack::PopAndDestroy( iObjectList );			
       
   702 			break;
       
   703 			}
       
   704 		// --- Kernel Heap related functions ---
       
   705 		case EMemSpyClientServerOpGetHeap:
       
   706 			{
       
   707 			TMemSpyHeapInfo heapInfo;			
       
   708 			iEngine.HelperHeap().GetHeapInfoKernelL( heapInfo );
       
   709 			TMemSpyHeapData data = iEngine.HelperHeap().NewHeapRawInfo( heapInfo );
       
   710 			
       
   711 			TPckgBuf<TMemSpyHeapData> buffer(data);
       
   712 			aMessage.WriteL(0, buffer);
       
   713 			
       
   714 			break;
       
   715 			}
       
   716 		}
       
   717     }
       
   718 
       
   719 // ---------------------------------------------------------
       
   720 // DoCmdServiceL( const RMessage2& aMessage )
       
   721 // ---------------------------------------------------------
       
   722 //
       
   723 void CMemSpyEngineSession::DoCmdServiceL( const RMessage2& aMessage )
   172     {
   724     {
   173     TInt error = KErrNone;
   725     TInt error = KErrNone;
   174 
   726 
   175     // Check function attributes
   727     // Check function attributes
   176     const TInt function = aMessage.Function() & KMemSpyOpFlagsTypeMask;
   728     const TInt function = aMessage.Function() & KMemSpyOpFlagsTypeMask;