memspyui/source/MemSpyViewThreadInfoItemGeneric.cpp
branchRCL_3
changeset 22 fad26422216a
parent 0 d6fe6244b863
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
       
     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 "MemSpyViewThreadInfoItemGeneric.h"
       
    19 
       
    20 // System includes
       
    21 #include <AknWaitDialog.h>
       
    22 #include <memspyui.rsg>
       
    23 
       
    24 // Engine includes
       
    25 #include <memspy/engine/memspyengine.h>
       
    26 #include <memspy/engine/memspyengineobjectprocess.h>
       
    27 #include <memspy/engine/memspyengineobjectthread.h>
       
    28 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    29 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h>
       
    30 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    31 #include <memspy/engine/memspyenginehelperprocess.h>
       
    32 
       
    33 // User includes
       
    34 #include "MemSpyContainerObserver.h"
       
    35 #include "MemSpyViewThreadInfoItemList.h"
       
    36 
       
    37 // Constants
       
    38 const TInt KMemSpyConstructionCheckerTimerPeriod = 500000; // 1/2 second
       
    39 
       
    40 
       
    41 
       
    42 CMemSpyViewThreadInfoItemGeneric::CMemSpyViewThreadInfoItemGeneric( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver, CMemSpyThreadInfoContainer& aInfoContainer, TMemSpyThreadInfoItemType aType )
       
    43 :   CMemSpyViewBase( aEngine, aObserver ), iContainer( aInfoContainer )
       
    44     {
       
    45     iContainer.Thread().Process().Open();
       
    46     iContainer.Thread().Open();
       
    47     iContainer.Open();
       
    48     //
       
    49     iInfoItem = &iContainer.Item( aType );
       
    50     __ASSERT_ALWAYS( iInfoItem != NULL, User::Invariant() );
       
    51     iInfoItem->Open();
       
    52     }
       
    53 
       
    54 
       
    55 CMemSpyViewThreadInfoItemGeneric::~CMemSpyViewThreadInfoItemGeneric()
       
    56     {
       
    57     if  ( iInfoItem )
       
    58         {
       
    59         iInfoItem->Close();
       
    60         }
       
    61     //
       
    62     DestroyWaitNote();
       
    63     //
       
    64     iContainer.Close();
       
    65     iContainer.Thread().Close();
       
    66     iContainer.Thread().Process().Close();
       
    67     }
       
    68 
       
    69 
       
    70 void CMemSpyViewThreadInfoItemGeneric::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
    71     {
       
    72     const TPtrC pTitle( iInfoItem->Name().Mid( 1 ) );
       
    73     SetTitleL( pTitle );
       
    74     //
       
    75     if  ( iInfoItem->IsReady() == EFalse )
       
    76         {
       
    77 #ifdef _DEBUG
       
    78         RDebug::Printf( "CMemSpyViewThreadInfoItemGeneric::ConstructL() - show wait note - item not ready, iType: %d", iInfoItem->Type() );
       
    79 #endif
       
    80 
       
    81         // Wait for engine data to be made ready... 
       
    82         ShowWaitNoteL();
       
    83         }
       
    84 
       
    85     CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune );
       
    86     }
       
    87 
       
    88 
       
    89 CMemSpyProcess& CMemSpyViewThreadInfoItemGeneric::Process() const
       
    90     {
       
    91     return iContainer.Thread().Process();
       
    92     }
       
    93 
       
    94 
       
    95 CMemSpyThread& CMemSpyViewThreadInfoItemGeneric::Thread() const
       
    96     {
       
    97     return iContainer.Thread();
       
    98     }
       
    99 
       
   100 
       
   101 CMemSpyThreadInfoContainer& CMemSpyViewThreadInfoItemGeneric::Container() const
       
   102     {
       
   103     return iContainer;
       
   104     }
       
   105 
       
   106 
       
   107 CMemSpyThreadInfoItemBase& CMemSpyViewThreadInfoItemGeneric::InfoItem() const
       
   108     {
       
   109     __ASSERT_ALWAYS( iInfoItem != NULL, User::Invariant() );
       
   110     return *iInfoItem;
       
   111     }
       
   112 
       
   113 
       
   114 void CMemSpyViewThreadInfoItemGeneric::RefreshL()
       
   115     {
       
   116     iInfoItem->RebuildL();    
       
   117     SetListBoxModelL();
       
   118     CMemSpyViewBase::RefreshL();
       
   119     }
       
   120 
       
   121 
       
   122 TMemSpyViewType CMemSpyViewThreadInfoItemGeneric::ViewType() const
       
   123     {
       
   124     TMemSpyViewType type = EMemSpyViewTypeNone;
       
   125     //
       
   126     switch( iInfoItem->Type() )
       
   127         {
       
   128     case EMemSpyThreadInfoItemTypeHeap:
       
   129         type = EMemSpyViewTypeThreadInfoItemHeap;
       
   130         break;
       
   131     case EMemSpyThreadInfoItemTypeStack:
       
   132         type = EMemSpyViewTypeThreadInfoItemStack;
       
   133         break;
       
   134     case EMemSpyThreadInfoItemTypeChunk:
       
   135         type = EMemSpyViewTypeThreadInfoItemChunk;
       
   136         break;
       
   137     case EMemSpyThreadInfoItemTypeCodeSeg:
       
   138         type = EMemSpyViewTypeThreadInfoItemCodeSeg;
       
   139         break;
       
   140     case EMemSpyThreadInfoItemTypeServer:
       
   141         type = EMemSpyViewTypeThreadInfoItemServer;
       
   142         break;
       
   143     case EMemSpyThreadInfoItemTypeSession:
       
   144         type = EMemSpyViewTypeThreadInfoItemSession;
       
   145         break;
       
   146     case EMemSpyThreadInfoItemTypeSemaphore:
       
   147         type = EMemSpyViewTypeThreadInfoItemSemaphore;
       
   148         break;
       
   149     case EMemSpyThreadInfoItemTypeMutex:
       
   150         type = EMemSpyViewTypeThreadInfoItemMutex;
       
   151         break;
       
   152     case EMemSpyThreadInfoItemTypeTimer:
       
   153         type = EMemSpyViewTypeThreadInfoItemTimer;
       
   154         break;
       
   155     case EMemSpyThreadInfoItemTypeLDD:
       
   156         type = EMemSpyViewTypeThreadInfoItemLDD;
       
   157         break;
       
   158     case EMemSpyThreadInfoItemTypePDD:
       
   159         type = EMemSpyViewTypeThreadInfoItemPDD;
       
   160         break;
       
   161     case EMemSpyThreadInfoItemTypeLogicalChannel:
       
   162         type = EMemSpyViewTypeThreadInfoItemLogicalChannel;
       
   163         break;
       
   164     case EMemSpyThreadInfoItemTypeChangeNotifier:
       
   165         type = EMemSpyViewTypeThreadInfoItemChangeNotifier;
       
   166         break;
       
   167     case EMemSpyThreadInfoItemTypeUndertaker:
       
   168         type = EMemSpyViewTypeThreadInfoItemUndertaker;
       
   169         break;
       
   170     case EMemSpyThreadInfoItemTypeMessageQueue:
       
   171         type = EMemSpyViewTypeThreadInfoItemMessageQueue;
       
   172         break;
       
   173     case EMemSpyThreadInfoItemTypeConditionalVariable:
       
   174         type = EMemSpyViewTypeThreadInfoItemConditionalVariable;
       
   175         break;
       
   176     case EMemSpyThreadInfoItemTypeOpenFiles:
       
   177         type = EMemSpyViewTypeThreadInfoItemOpenFiles;
       
   178         break;
       
   179     case EMemSpyThreadInfoItemTypeActiveObject:
       
   180         type = EMemSpyViewTypeThreadInfoItemActiveObject;
       
   181         break;
       
   182     case EMemSpyThreadInfoItemTypeGeneralInfo:
       
   183         type = EMemSpyViewTypeThreadInfoItemGeneralInfo;
       
   184         break;
       
   185     case EMemSpyThreadInfoItemTypeOtherThreads:
       
   186         type = EMemSpyViewTypeThreadInfoItemOtherThreads;
       
   187         break;
       
   188     case EMemSpyThreadInfoItemTypeOtherProcesses:
       
   189         type = EMemSpyViewTypeThreadInfoItemOtherProcesses;
       
   190         break;
       
   191     case EMemSpyThreadInfoItemTypeOwnedThreadHandles:
       
   192         type = EMemSpyViewTypeThreadInfoItemOwnedThreadHandles;
       
   193         break;
       
   194     case EMemSpyThreadInfoItemTypeOwnedProcessHandles:
       
   195         type = EMemSpyViewTypeThreadInfoItemOwnedProcessHandles;
       
   196         break;
       
   197 
       
   198     default:
       
   199         __ASSERT_DEBUG( EFalse, User::Invariant() );
       
   200         break;
       
   201         }
       
   202     //
       
   203     return type;
       
   204     }
       
   205 
       
   206 
       
   207 CMemSpyViewBase* CMemSpyViewThreadInfoItemGeneric::PrepareParentViewL()
       
   208     {
       
   209     CMemSpyViewThreadInfoItemList* parent = new(ELeave) CMemSpyViewThreadInfoItemList( iEngine, iObserver, Thread() );
       
   210     CleanupStack::PushL( parent );
       
   211     parent->ConstructL( Rect(), *Parent(), iInfoItem );
       
   212     CleanupStack::Pop( parent );
       
   213     return parent;
       
   214     }
       
   215 
       
   216 
       
   217 CMemSpyViewBase* CMemSpyViewThreadInfoItemGeneric::PrepareChildViewL()
       
   218     {
       
   219     __ASSERT_ALWAYS( iInfoItem != NULL, User::Invariant() );
       
   220     CMemSpyViewBase* child = NULL;
       
   221     //
       
   222     return child;
       
   223     }
       
   224 
       
   225 
       
   226 TBool CMemSpyViewThreadInfoItemGeneric::HandleCommandL( TInt aCommand )
       
   227     {
       
   228     TBool handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   229     return handled;
       
   230     }
       
   231 
       
   232 
       
   233 void CMemSpyViewThreadInfoItemGeneric::SetListBoxModelL()
       
   234     {
       
   235     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   236     listbox->Model()->SetItemTextArray( iInfoItem );
       
   237     listbox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   238     }
       
   239 
       
   240 
       
   241 void CMemSpyViewThreadInfoItemGeneric::HandleListBoxItemActionedL( TInt /*aIndex*/ )
       
   242     {
       
   243     // Notify observer about an item being 'fired'
       
   244     ReportEventL( MMemSpyViewObserver::EEventItemActioned );
       
   245     }
       
   246 
       
   247 
       
   248 void CMemSpyViewThreadInfoItemGeneric::HandleListBoxItemSelectedL( TInt /*aIndex*/ )
       
   249     {
       
   250     // Notify observer about item selection
       
   251     ReportEventL( MMemSpyViewObserver::EEventItemSelected );
       
   252     }
       
   253 
       
   254 
       
   255 
       
   256 void CMemSpyViewThreadInfoItemGeneric::ShowWaitNoteL()
       
   257     {
       
   258     // Ugly, but I'm not adding an observer mechanism just for this wait dialog.
       
   259     __ASSERT_ALWAYS( iWaitConstructionChecker == NULL, User::Invariant() );
       
   260     iWaitConstructionChecker = CPeriodic::NewL( CActive::EPriorityLow );
       
   261     iWaitConstructionChecker->Start( KMemSpyConstructionCheckerTimerPeriod, 
       
   262                                      KMemSpyConstructionCheckerTimerPeriod, 
       
   263                                      TCallBack( CheckForItemConstructionComplete, this ) );
       
   264 
       
   265     if  ( !iWaitNote )
       
   266         {
       
   267         iWaitNote = new ( ELeave ) CAknWaitDialog( reinterpret_cast<CEikDialog**> ( &iWaitNote ), ETrue );
       
   268         iWaitNote->ExecuteDlgLD( CAknNoteDialog::ENoTone, R_MEMSPY_PREPARING_INFO_ITEM_CONTAINER_WAIT_NOTE );
       
   269         }
       
   270     }
       
   271 
       
   272 
       
   273 void CMemSpyViewThreadInfoItemGeneric::DestroyWaitNote()
       
   274     {
       
   275 #ifdef _DEBUG
       
   276     RDebug::Printf( "CMemSpyViewThreadInfoItemGeneric::DestroyWaitNote() - START" );
       
   277 #endif
       
   278 	//
       
   279     delete iWaitConstructionChecker;
       
   280     iWaitConstructionChecker = NULL;
       
   281     //
       
   282     if  ( iWaitNote )
       
   283         {
       
   284         TRAP_IGNORE( iWaitNote->ProcessFinishedL() ); // deletes the dialog
       
   285         iWaitNote = NULL;
       
   286         }
       
   287 	//
       
   288 #ifdef _DEBUG
       
   289     RDebug::Printf( "CMemSpyViewThreadInfoItemGeneric::DestroyWaitNote() - END" );
       
   290 #endif
       
   291     }
       
   292 
       
   293 
       
   294 TInt CMemSpyViewThreadInfoItemGeneric::CheckForItemConstructionComplete( TAny* aSelf )
       
   295     {
       
   296     CMemSpyViewThreadInfoItemGeneric& self = *reinterpret_cast< CMemSpyViewThreadInfoItemGeneric* >( aSelf );
       
   297     //
       
   298 #ifdef _DEBUG
       
   299     RDebug::Printf( "CMemSpyViewThreadInfoItemGeneric::CheckForItemConstructionComplete() - ready status: %d, iType: %d", self.iInfoItem->IsReady(), self.iInfoItem->Type() );
       
   300 #endif
       
   301 	//
       
   302     TBool callAgain = ETrue;
       
   303     if  ( self.iInfoItem->IsReady() )
       
   304         {
       
   305         self.DestroyWaitNote();
       
   306         callAgain = EFalse;
       
   307         }
       
   308     //
       
   309     return callAgain;
       
   310     }
       
   311 
       
   312 
       
   313 
       
   314 
       
   315