memspyui/source/MemSpyViewThreadInfoItemServer.cpp
changeset 0 d6fe6244b863
equal deleted inserted replaced
-1:000000000000 0:d6fe6244b863
       
     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 #include "MemSpyViewThreadInfoItemServer.h"
       
    19 
       
    20 // Engine includes
       
    21 #include <memspy/engine/memspyengine.h>
       
    22 #include <memspy/engine/memspyengineobjectprocess.h>
       
    23 #include <memspy/engine/memspyengineobjectthread.h>
       
    24 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    25 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h>
       
    26 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    27 #include <memspy/engine/memspyenginehelperprocess.h>
       
    28 #include <memspy/engine/memspyenginehelperheap.h>
       
    29 #include <memspy/engine/memspyenginehelperserver.h>
       
    30 
       
    31 // User includes
       
    32 #include "MemSpyContainerObserver.h"
       
    33 
       
    34 // Constants
       
    35 const TInt KMemSpyServerSessionsIndex = 2;
       
    36 
       
    37 
       
    38 
       
    39 CMemSpyViewThreadInfoItemServer::CMemSpyViewThreadInfoItemServer( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver, CMemSpyThreadInfoContainer& aContainer )
       
    40 :   CMemSpyViewThreadInfoItemGeneric( aEngine, aObserver, aContainer, EMemSpyThreadInfoItemTypeServer )
       
    41     {
       
    42     }
       
    43 
       
    44 
       
    45 void CMemSpyViewThreadInfoItemServer::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
    46     {
       
    47     // Causes list of server's to be prepared
       
    48     CMemSpyViewThreadInfoItemGeneric::ConstructL( aRect, aContainer, aSelectionRune );
       
    49 
       
    50     _LIT( KTitle, "Server List" );
       
    51     SetTitleL( KTitle );
       
    52 
       
    53 #ifdef _DEBUG
       
    54     RDebug::Printf( "CMemSpyViewThreadInfoItemServer::ConstructL() - aSelectionRune: 0x%08x", aSelectionRune );
       
    55 #endif
       
    56 
       
    57     // Try to select the correct server
       
    58     CMemSpyThreadInfoHandleObjectBase* infoItem = static_cast< CMemSpyThreadInfoHandleObjectBase* >( iInfoItem );
       
    59     TInt selectedIndex = 0;
       
    60     if  ( aSelectionRune )
       
    61         {
       
    62         // Treat the rune as a handle, and try to look it up
       
    63         selectedIndex = infoItem->DetailsIndexByHandle( aSelectionRune );
       
    64         }
       
    65 
       
    66     // Select item
       
    67     if  ( infoItem->DetailsCount() > 0 )
       
    68         {
       
    69         iListBox->SetCurrentItemIndex( selectedIndex );
       
    70         HandleListBoxItemSelectedL( selectedIndex );
       
    71         }
       
    72     }
       
    73 
       
    74 
       
    75 TBool CMemSpyViewThreadInfoItemServer::HandleCommandL( TInt aCommand )
       
    76     {
       
    77     TBool handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
    78     return handled;
       
    79     }
       
    80 
       
    81 
       
    82 CMemSpyViewBase* CMemSpyViewThreadInfoItemServer::PrepareChildViewL()
       
    83     {
       
    84     CMemSpyViewThreadInfoItemServerDetails* child = new(ELeave) CMemSpyViewThreadInfoItemServerDetails( iEngine, iObserver, iContainer, iCurrentInfoItemDetails );
       
    85     CleanupStack::PushL( child );
       
    86     child->ConstructL( Rect(), *Parent() );
       
    87     CleanupStack::Pop( child );
       
    88     return child;
       
    89     }
       
    90 
       
    91 
       
    92 void CMemSpyViewThreadInfoItemServer::HandleListBoxItemSelectedL( TInt aIndex )
       
    93     {
       
    94     // Identify the type of item to display...
       
    95     CMemSpyThreadInfoHandleObjectBase* infoItem = static_cast< CMemSpyThreadInfoHandleObjectBase* >( iInfoItem );
       
    96     iCurrentInfoItemDetails = infoItem->DetailsAt( aIndex );
       
    97 
       
    98 #ifdef _DEBUG
       
    99     RDebug::Printf( "CMemSpyViewThreadInfoItemServer::HandleListBoxItemSelectedL() - iCurrentInfoItemDetails.iHandle: 0x%08x", iCurrentInfoItemDetails.iHandle );
       
   100 #endif
       
   101 
       
   102     // Notify observer about item selection
       
   103     ReportEventL( MMemSpyViewObserver::EEventItemSelected );
       
   104     }
       
   105 
       
   106 
       
   107 
       
   108 
       
   109 
       
   110 
       
   111 
       
   112 
       
   113 
       
   114 
       
   115 
       
   116 
       
   117 
       
   118 
       
   119 
       
   120 
       
   121 
       
   122 
       
   123 
       
   124 
       
   125 
       
   126 
       
   127 
       
   128 
       
   129 
       
   130 
       
   131 CMemSpyViewThreadInfoItemServerDetails::CMemSpyViewThreadInfoItemServerDetails( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver, CMemSpyThreadInfoContainer& aContainer, const TMemSpyDriverHandleInfoGeneric& aInfoItemDetails )
       
   132 :   CMemSpyViewThreadInfoItemGeneric( aEngine, aObserver, aContainer, EMemSpyThreadInfoItemTypeServer ), iInfoItemDetails( aInfoItemDetails )
       
   133     {
       
   134     }
       
   135 
       
   136 
       
   137 void CMemSpyViewThreadInfoItemServerDetails::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
   138     {
       
   139     // Causes list of server's to be prepared
       
   140     CMemSpyViewThreadInfoItemGeneric::ConstructL( aRect, aContainer, aSelectionRune );
       
   141 
       
   142     _LIT( KTitle, "Server Details" );
       
   143     SetTitleL( KTitle );
       
   144 
       
   145     // Try to select the correct server
       
   146     TInt selectedIndex = 0;
       
   147     if  ( aSelectionRune )
       
   148         {
       
   149         // Presence of non-null item means that we came from the "Server sessions" list
       
   150         selectedIndex = KMemSpyServerSessionsIndex;
       
   151         }
       
   152 
       
   153     // Select item
       
   154     iListBox->SetCurrentItemIndex( selectedIndex );
       
   155     HandleListBoxItemSelectedL( selectedIndex );
       
   156     }
       
   157 
       
   158 
       
   159 TBool CMemSpyViewThreadInfoItemServerDetails::HandleCommandL( TInt aCommand )
       
   160     {
       
   161     TBool handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   162     return handled;
       
   163     }
       
   164 
       
   165 
       
   166 TMemSpyViewType CMemSpyViewThreadInfoItemServerDetails::ViewType() const
       
   167     {
       
   168     return EMemSpyViewTypeThreadInfoItemServerDetails;
       
   169     }
       
   170 
       
   171 
       
   172 CMemSpyViewBase* CMemSpyViewThreadInfoItemServerDetails::PrepareChildViewL()
       
   173     {
       
   174     CMemSpyViewBase* child = NULL;
       
   175     const TInt currentIndex = iListBox->CurrentItemIndex();
       
   176     //
       
   177     if  ( currentIndex == KMemSpyServerSessionsIndex )
       
   178         {
       
   179         CMemSpyViewThreadInfoItemServerSessions* serverSessions = new(ELeave) CMemSpyViewThreadInfoItemServerSessions( iEngine, iObserver, iInfoItem->Container(), iInfoItemDetails );
       
   180         CleanupStack::PushL( serverSessions );
       
   181         serverSessions->ConstructL( Rect(), *Parent(), NULL );
       
   182         CleanupStack::Pop( serverSessions );
       
   183         child = serverSessions;
       
   184         }
       
   185     //
       
   186     return child;
       
   187     }
       
   188 
       
   189 
       
   190 CMemSpyViewBase* CMemSpyViewThreadInfoItemServerDetails::PrepareParentViewL()
       
   191     {
       
   192     CMemSpyViewThreadInfoItemServer* parent = new(ELeave) CMemSpyViewThreadInfoItemServer( iEngine, iObserver, iInfoItem->Container() );
       
   193     CleanupStack::PushL( parent );
       
   194     parent->ConstructL( Rect(), *Parent(), iInfoItemDetails.iHandle );
       
   195     CleanupStack::Pop( parent );
       
   196     return parent;
       
   197     }
       
   198 
       
   199 
       
   200 void CMemSpyViewThreadInfoItemServerDetails::SetListBoxModelL()
       
   201     {
       
   202     CDesCArrayFlat* model = new(ELeave) CDesCArrayFlat(4);
       
   203     CleanupStack::PushL( model );
       
   204 
       
   205     TBuf<KMaxFullName + 1> item;
       
   206 
       
   207     // 1st item = session type
       
   208     const TPtrC pServerSessionType = CMemSpyThreadInfoServer::SessionType( iInfoItemDetails.iSessionType );
       
   209     _LIT(KItem1Format, "\tServer Type\t\t%S");
       
   210     item.Format( KItem1Format, &pServerSessionType );
       
   211     model->AppendL( item );
       
   212 
       
   213     // 2nd item = session count
       
   214     _LIT(KItem2Format, "\tConnected Sessions\t\t%d");
       
   215     item.Format( KItem2Format, iInfoItemDetails.iCount );
       
   216     model->AppendL( item );
       
   217 
       
   218     // 3rd item = view sessions
       
   219     if  ( iInfoItem->Container().MdcaCount() > 0 )
       
   220         {
       
   221         _LIT(KItem3Format, "\tView Sessions");
       
   222         model->AppendL( KItem3Format );
       
   223         }
       
   224 
       
   225     // Set up list box
       
   226     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   227     listbox->Model()->SetItemTextArray( model );
       
   228     listbox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   229     CleanupStack::Pop( model );
       
   230     }
       
   231 
       
   232 
       
   233 void CMemSpyViewThreadInfoItemServerDetails::HandleListBoxItemActionedL( TInt /*aIndex*/ )
       
   234     {
       
   235     // Notify observer about an item being 'fired'
       
   236     ReportEventL( MMemSpyViewObserver::EEventItemActioned );
       
   237     }
       
   238 
       
   239 
       
   240 void CMemSpyViewThreadInfoItemServerDetails::HandleListBoxItemSelectedL( TInt /*aIndex*/ )
       
   241     {
       
   242     // Notify observer about item selection
       
   243     ReportEventL( MMemSpyViewObserver::EEventItemSelected );
       
   244     }
       
   245 
       
   246 
       
   247 
       
   248 
       
   249 
       
   250 
       
   251 
       
   252 
       
   253 
       
   254 
       
   255 
       
   256 
       
   257 
       
   258 
       
   259 
       
   260 
       
   261 
       
   262 
       
   263 
       
   264 
       
   265 
       
   266 
       
   267 
       
   268 
       
   269 
       
   270 
       
   271 
       
   272 
       
   273 CMemSpyViewThreadInfoItemServerSessions::CMemSpyViewThreadInfoItemServerSessions( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver, CMemSpyThreadInfoContainer& aContainer, const TMemSpyDriverHandleInfoGeneric& aInfoItemDetails )
       
   274 :   CMemSpyViewThreadInfoItemGeneric( aEngine, aObserver, aContainer, EMemSpyThreadInfoItemTypeServer ), iInfoItemDetails( aInfoItemDetails )
       
   275     {
       
   276     }
       
   277 
       
   278 
       
   279 void CMemSpyViewThreadInfoItemServerSessions::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
   280     {
       
   281     CMemSpyViewThreadInfoItemGeneric::ConstructL( aRect, aContainer, aSelectionRune );
       
   282     //
       
   283     _LIT( KTitle, "Connected Session List" );
       
   284     SetTitleL( KTitle );
       
   285     }
       
   286 
       
   287 
       
   288 TBool CMemSpyViewThreadInfoItemServerSessions::HandleCommandL( TInt aCommand )
       
   289     {
       
   290     TBool handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   291     return handled;
       
   292     }
       
   293 
       
   294 
       
   295 TMemSpyViewType CMemSpyViewThreadInfoItemServerSessions::ViewType() const
       
   296     {
       
   297     return EMemSpyViewTypeThreadInfoItemServerSessions;
       
   298     }
       
   299 
       
   300 
       
   301 CMemSpyViewBase* CMemSpyViewThreadInfoItemServerSessions::PrepareParentViewL()
       
   302     {
       
   303     CMemSpyViewThreadInfoItemServerDetails* parent = new(ELeave) CMemSpyViewThreadInfoItemServerDetails( iEngine, iObserver, iInfoItem->Container(), iInfoItemDetails );
       
   304     CleanupStack::PushL( parent );
       
   305     parent->ConstructL( Rect(), *Parent(), this );
       
   306     CleanupStack::Pop( parent );
       
   307     return parent;
       
   308     }
       
   309 
       
   310 
       
   311 void CMemSpyViewThreadInfoItemServerSessions::SetListBoxModelL()
       
   312     {
       
   313     CDesCArrayFlat* model = new(ELeave) CDesCArrayFlat(4);
       
   314     CleanupStack::PushL( model );
       
   315 
       
   316     // Get handles
       
   317     RArray<TMemSpyDriverServerSessionInfo> sessions;
       
   318     CleanupClosePushL( sessions );
       
   319     iEngine.HelperServer().GetServerSessionsL( iInfoItemDetails, sessions );
       
   320 
       
   321     // Prepare items
       
   322     TBuf<KMaxFullName + 1> item;
       
   323     const TInt count = sessions.Count();
       
   324     for( TInt i=0; i<count; i++ )
       
   325         {
       
   326         _LIT(KInsertTab, "\t");
       
   327 
       
   328         const TMemSpyDriverServerSessionInfo& session = sessions[ i ];
       
   329         item.Zero();
       
   330 
       
   331         if  ( session.iOwnerType == TMemSpyDriverServerSessionInfo::EOwnerThread )
       
   332             {
       
   333             // Find the thread object
       
   334             CMemSpyThread* thread = NULL;
       
   335             CMemSpyProcess* process = NULL;
       
   336             //
       
   337             const TInt error = iEngine.Container().ProcessAndThreadByThreadId( session.iOwnerId, process, thread );
       
   338             //
       
   339             if  ( error == KErrNone )
       
   340                 {
       
   341                 item.Append( process->Name() );
       
   342                 item.Append( KInsertTab );
       
   343                 item.Append( KInsertTab );
       
   344                 item.Append( thread->Name() );
       
   345                 }
       
   346             }
       
   347         else if ( session.iOwnerType == TMemSpyDriverServerSessionInfo::EOwnerProcess )
       
   348             {
       
   349             // Find the process object
       
   350             CMemSpyProcess* process = NULL;
       
   351             TRAPD( error, process = &iEngine.Container().ProcessByIdL( session.iOwnerId ) );
       
   352             if  ( error == KErrNone )
       
   353                 {
       
   354                 item.Append( process->Name() );
       
   355                 }
       
   356             }
       
   357 
       
   358         if  ( !item.Length() )
       
   359             {
       
   360             // Fall-back case
       
   361             item.Copy( session.iName );
       
   362             }
       
   363 
       
   364         // Add item
       
   365         item.Insert( 0, KInsertTab );
       
   366         model->AppendL( item );
       
   367         }
       
   368     CleanupStack::PopAndDestroy( &sessions );
       
   369 
       
   370     // Set up list box
       
   371     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   372     listbox->Model()->SetItemTextArray( model );
       
   373     listbox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   374     CleanupStack::Pop( model );
       
   375     }
       
   376 
       
   377 
       
   378 
       
   379 
       
   380 
       
   381 
       
   382 
       
   383 
       
   384 
       
   385 
       
   386 
       
   387 
       
   388 
       
   389 
       
   390 
       
   391