diff -r 000000000000 -r a03f92240627 memspy/Engine/Source/Helpers/MemSpyEngineHelperServer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memspy/Engine/Source/Helpers/MemSpyEngineHelperServer.cpp Tue Feb 02 01:57:15 2010 +0200 @@ -0,0 +1,455 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include + +// Driver includes +#include +#include + +// User includes +#include +#include +#include +#include +#include +#include + +// Literal constants +_LIT( KMemSpyEngineServListOutputComma, ", " ); + + + +CMemSpyEngineHelperServer::CMemSpyEngineHelperServer( CMemSpyEngine& aEngine ) +: iEngine( aEngine ) + { + } + + +CMemSpyEngineHelperServer::~CMemSpyEngineHelperServer() + { + } + + +void CMemSpyEngineHelperServer::ConstructL() + { + } + + +CMemSpyEngineHelperServer* CMemSpyEngineHelperServer::NewL( CMemSpyEngine& aEngine ) + { + CMemSpyEngineHelperServer* self = new(ELeave) CMemSpyEngineHelperServer( aEngine ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + + +EXPORT_C void CMemSpyEngineHelperServer::GetServerSessionsL( TAny* aServerHandle, RArray& aSessions ) + { + const TInt KMaxCount = 256; + TAny* handles[KMaxCount]; + TInt c = KMaxCount; + + TInt r = iEngine.Driver().GetServerSessionHandles( aServerHandle, handles, c ); + if ( r == KErrNone ) + { + if ( c > 0 ) + { + if (c > KMaxCount) + { + c = KMaxCount; + } + + TMemSpyDriverServerSessionInfo info; + for (TInt i=0; i& aSessions ) + { + GetServerSessionsL( aServerDetails.iHandle, aSessions ); + } + + +EXPORT_C void CMemSpyEngineHelperServer::GetServerListL( RArray& aServers ) + { + const TInt KMaxCount = 256; + TAny* handles[KMaxCount]; + TInt c = KMaxCount; + + TInt r = iEngine.Driver().GetContainerHandles( EMemSpyDriverContainerTypeServer, handles, c ); + if ( r == KErrNone ) + { + if ( c > 0 ) + { + if (c > KMaxCount) + { + c = KMaxCount; + } + + TMemSpyDriverHandleInfoGeneric info; + for (TInt i=0; i servers; + CleanupClosePushL( servers ); + // + GetServerListL( servers ); + // + const TInt count = servers.Count(); + for( TInt i=0; iAddItemL( serverEntry ); + CleanupStack::Pop( serverEntry ); + } + // + CleanupStack::PopAndDestroy( &servers ); + + // Sort the list by session count + list->SortBySessionCountL(); + + // Done + CleanupStack::Pop( list ); + return list; + } + + +CMemSpyEngine& CMemSpyEngineHelperServer::Engine() const + { + return iEngine; + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +CMemSpyEngineServerList::CMemSpyEngineServerList() + { + } + + +EXPORT_C CMemSpyEngineServerList::~CMemSpyEngineServerList() + { + iItems.ResetAndDestroy(); + iItems.Close(); + } + + +void CMemSpyEngineServerList::ConstructL() + { + } + + +CMemSpyEngineServerList* CMemSpyEngineServerList::NewLC() + { + CMemSpyEngineServerList* self = new(ELeave) CMemSpyEngineServerList(); + CleanupStack::PushL( self ); + self->ConstructL(); + return self; + } + + +EXPORT_C TInt CMemSpyEngineServerList::Count() const + { + return iItems.Count(); + } + + +EXPORT_C const CMemSpyEngineServerEntry& CMemSpyEngineServerList::At( TInt aIndex ) const + { + return *iItems[ aIndex ]; + } + + +EXPORT_C void CMemSpyEngineServerList::SortByNameL() + { + TLinearOrder< CMemSpyEngineServerEntry > comparer( CompareByName ); + iItems.Sort( comparer ); + } + + +EXPORT_C void CMemSpyEngineServerList::SortBySessionCountL() + { + TLinearOrder< CMemSpyEngineServerEntry > comparer( CompareBySessionCount ); + iItems.Sort( comparer ); + } + + +EXPORT_C TInt CMemSpyEngineServerList::ItemIndex( const CMemSpyEngineServerEntry& aEntry ) const + { + TInt ret = KErrNotFound; + // + const TInt count = Count(); + for( TInt i=0; iDes() ); + // + _LIT(KCol1, "Thread/Process Id"); + pColumns.Append( KCol1 ); + pColumns.Append( KMemSpyEngineServListOutputComma ); + // + _LIT(KCol2, "Name"); + pColumns.Append( KCol2 ); + pColumns.Append( KMemSpyEngineServListOutputComma ); + // + _LIT(KCol3, "Connected Session Count"); + pColumns.Append( KCol3 ); + // + if ( aClientThreadColumns ) + { + _LIT(KCol4, "Connected Client"); + pColumns.Append( KMemSpyEngineServListOutputComma ); + pColumns.Append( KCol4 ); + } + // + aEngine.Sink().OutputLineL( pColumns ); + CleanupStack::PopAndDestroy( columns ); + } + + +void CMemSpyEngineServerList::AddItemL( CMemSpyEngineServerEntry* aItem ) + { + iItems.AppendL( aItem ); + } + + +EXPORT_C TInt CMemSpyEngineServerList::MdcaCount() const + { + return Count(); + } + + +EXPORT_C TPtrC CMemSpyEngineServerList::MdcaPoint( TInt aIndex ) const + { + const CMemSpyEngineServerEntry& item = At( aIndex ); + return TPtrC( item.Caption() ); + } + + +TInt CMemSpyEngineServerList::CompareByName( const CMemSpyEngineServerEntry& aLeft, const CMemSpyEngineServerEntry& aRight ) + { + const TInt ret = aLeft.Name().CompareF( aRight.Name() ); + return ret; + } + + +TInt CMemSpyEngineServerList::CompareBySessionCount( const CMemSpyEngineServerEntry& aLeft, const CMemSpyEngineServerEntry& aRight ) + { + TInt ret = -1; + // + if ( aLeft.SessionCount() < aRight.SessionCount() ) + { + ret = 1; + } + else if ( aLeft.SessionCount() == aRight.SessionCount() ) + { + ret = 0; + } + // + return ret; + } + + + + + + + + + + + + + + + + + + + +CMemSpyEngineServerEntry::CMemSpyEngineServerEntry() + { + } + + +EXPORT_C CMemSpyEngineServerEntry::~CMemSpyEngineServerEntry() + { + delete iCaption; + delete iName; + } + + +void CMemSpyEngineServerEntry::ConstructL( const TMemSpyDriverHandleInfoGeneric& aInfo ) + { + iName = HBufC::NewL( aInfo.iName.Length() ); + iName->Des().Copy( aInfo.iName ); + iSessionCount = aInfo.iCount; + iId = aInfo.iId; + iHandle = aInfo.iHandle; + + // Make caption + _LIT(KServerListFormat, "\t%S\t\t%d session"); + TBuf item; + // + item.Format( KServerListFormat, iName, iSessionCount ); + // + if ( iSessionCount != 1 ) + { + // Add missing 's' + item.Append( TChar('s') ); + } + // + iCaption = item.AllocL(); + } + + +CMemSpyEngineServerEntry* CMemSpyEngineServerEntry::NewLC( const TMemSpyDriverHandleInfoGeneric& aInfo ) + { + CMemSpyEngineServerEntry* self = new(ELeave) CMemSpyEngineServerEntry(); + CleanupStack::PushL( self ); + self->ConstructL( aInfo ); + return self; + } + + +EXPORT_C void CMemSpyEngineServerEntry::OutputDataL( CMemSpyEngineHelperServer& aHelper, TBool aClientThreadColumns ) const + { + _LIT(KMemSpyEngineServListOutputDecimal, "%d"); + _LIT(KMemSpyEngineServListOutputString, "%S"); + // + HBufC* columns = HBufC::NewLC( 1024 ); + TPtr pColumns( columns->Des() ); + // + pColumns.AppendFormat( KMemSpyEngineServListOutputDecimal, Id() ); + pColumns.Append( KMemSpyEngineServListOutputComma ); + // + pColumns.AppendFormat( KMemSpyEngineServListOutputString, &Name() ); + pColumns.Append( KMemSpyEngineServListOutputComma ); + // + pColumns.AppendFormat( KMemSpyEngineServListOutputDecimal, SessionCount() ); + // + aHelper.Engine().Sink().OutputLineL( pColumns ); + + if ( aClientThreadColumns ) + { + RArray sessions; + CleanupClosePushL( sessions ); + + // Get the sessions + GetSessionsL( aHelper, sessions ); + + // Output an additional line per entry + const TInt count = sessions.Count(); + for( TInt i=0; i& aSessions ) const + { + aHelper.GetServerSessionsL( Handle(), aSessions ); + } + +