Example #1
0
// ---------------------------------------------------------------------------
// CBSServer::DisplaySessionInfoL display the info for each open session,
// except for the one that called this method
// ---------------------------------------------------------------------------
//
void CBSServer::DisplaySessionInfoL( CBSSession* aSession, TInt aErrorCode )
	{
    TRACE( T_LIT( "CBSServer::DisplaySessionInfoL() begin aSession[%d], aErrorCode[%d]"),aSession,aErrorCode );

    User::LeaveIfNull( aSession );
    // some constants
    const TInt KStringLength = 512;
    const TInt KNumberLength = 16;
    _LIT( KMessage0,"Operation failed.Errorcode:");    
    _LIT( KMessage1," Info on open sessions [ProcessFileName|ThreadId|ProcessId|Caption]:");
    _LIT( KBracketOpen, " [");
    _LIT( KBracketClose, "]");
    _LIT( KSeparator, "|");
    

    HBufC* outputString = HBufC::NewLC( KStringLength );
    TPtr outputStringPtr( outputString->Des() );

    TBuf<KNumberLength> number;
    number.Num( aErrorCode );
    
    //make sure the string is long enough
    TInt newLength = outputString->Length() +
                     KMessage0().Length() +
                     number.Length() + 
                     KMessage1().Length();
    
    //reallocate if necessary
    if ( outputStringPtr.MaxLength() < newLength )
        {
        CleanupStack::Pop( outputString );
        outputString = outputString->ReAllocL( newLength );
        outputStringPtr.Set( outputString->Des() );
        CleanupStack::PushL( outputString );
        }    
        
    outputStringPtr.Append( KMessage0 );
    outputStringPtr.Append( number );
    outputStringPtr.Append( KMessage1 );
    
        
    TInt count = iSessions.Count();
	TRACE( T_LIT( "CBSServer::DisplaySessionInfoL() numberSessions=%d"),count );
	CBSSession* currentSession;
	for( TInt i = 0; i < count; i++ )
		{		
		currentSession = iSessions[i];
        TRACE( T_LIT( "CBSServer::DisplaySessionInfoL() iteration=%d session=%d"),i,currentSession );
    	if ( currentSession 
    	     && currentSession->InfoAvailable()
    	     && currentSession != aSession )
    	    {
    		TBuf<KNumberLength> threadIdStr;
    		TThreadId threadId;
    		if ( KErrNone == currentSession->ThreadId( threadId ) )
    		    {
    		    threadIdStr.NumUC( threadId.Id(), EDecimal );
    		    }    		
    		TBuf<KNumberLength> processIdStr;
    		TProcessId processId;
    		if ( KErrNone == currentSession->ProcessId( processId ) )
    		    {
    		    processIdStr.NumUC( processId.Id(), EDecimal );
    		    }
            
            //make sure the string is long enough
            newLength = outputString->Length() +
                        KBracketOpen().Length() +
                        currentSession->FileName().Length() + 
                        threadIdStr.Length() + 
                        processIdStr.Length() +
                        currentSession->Caption().Length() +                        
                        ( 3 * KSeparator().Length() ) +                        
                        KBracketClose().Length();

            //reallocate if necessary
            if ( outputStringPtr.MaxLength() < newLength )
                {
                CleanupStack::Pop( outputString );
                outputString = outputString->ReAllocL( newLength );
                outputStringPtr.Set( outputString->Des() );
                CleanupStack::PushL( outputString );
                }

  		    outputStringPtr.Append( KBracketOpen );
    		
    		//processfilename
    		outputStringPtr.Append( currentSession->FileName() );
    		outputStringPtr.Append( KSeparator );
    		    		
    		//threadid    		
    		outputStringPtr.Append( threadIdStr );
    		outputStringPtr.Append( KSeparator );
    		
    		//processid    		
    		outputStringPtr.Append( processIdStr );
    		outputStringPtr.Append( KSeparator );	
    		
    		//caption
    		outputStringPtr.Append( currentSession->Caption() );    		

    		outputStringPtr.Append( KBracketClose );
    	    }
		}     
	
	TRACE( T_LIT( "CBSServer::DisplaySessionInfoL() string creation OK") );
	TRACE( T_LIT( "%S"), outputString );
	CleanupStack::PopAndDestroy( outputString );
	TRACE( T_LIT( "CBSServer::DisplaySessionInfoL() end") );
	}
void CServerCrashDataSource::DoGetListL(const TListId aListId, 
										const TThreadId aThreadId,
										const TProcessId aProcessId,
										RBuf8 & aBuffer, 
										TUint32 & aSize )
	{

	LOG_MSG5( "->CServerCrashDataSource::DoGetList(aListId=%d, aThredId=%Lu, aProcessId=%Lu, aSize=%d\n", aListId, aThreadId.Id(), aProcessId.Id(), aSize );

	TInt ret;
	TListLevel listLevel;

	if( ((TUint)-1 == (TUint)aThreadId) && ((TUint)-1 == (TUint)aProcessId) )
		{
		listLevel = EListGlobal;
		ret = iSecSess.GetList( aListId, aBuffer, aSize );
		}
	else if( ((TUint)-1 != (TUint)aThreadId) && ((TUint)-1 == (TUint)aProcessId) )
		{
		listLevel = EListThread;
        LOG_MSG("CServerCrashDataSource::DoGetList - EListThread");
		ret = iSecSess.GetList( aThreadId, aListId, aBuffer, aSize );
		}
	else
		{
		listLevel = EListProcess;
        LOG_MSG("CServerCrashDataSource::DoGetList - EListProcess");
		ret = iSecSess.GetList( aProcessId, aListId, aBuffer, aSize );
		}
		 
	while( KErrTooBig == ret )
		{
		LOG_MSG2( "CServerCrashDataSource::DoGetListL - list too big, new size=%d\n", aSize );

		// Too big, and aSize should have been modified to the required new size
		// Since the list could have increased in size between calls, give it an 
		// extra margin.
		aSize += 256;

		aBuffer.ReAllocL( aSize );

		if( EListGlobal == listLevel )
			{
			ret = iSecSess.GetList( aListId, aBuffer, aSize );
			}
		else if( EListThread == listLevel )
			{
			ret = iSecSess.GetList( aThreadId, aListId, aBuffer, aSize );
			}
		else
			{
			ret = iSecSess.GetList( aProcessId, aListId, aBuffer, aSize );
			}

		}
    User::LeaveIfError(ret);
	}