memspyui/memspywindowserverhelper/src/MemSpyEngineHelperWindowServerImpl.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 "MemSpyEngineHelperWindowServerImpl.h"
       
    19 
       
    20 // System includes
       
    21 #include <apgwgnam.h>
       
    22 #include <apgtask.h>
       
    23 
       
    24 // ============================= LOCAL FUNCTIONS ===============================
       
    25 
       
    26 EXPORT_C MMemSpyEngineHelperWindowServer* NewMemSpyEngineHelperWindowServerImplL()
       
    27     {
       
    28     return CMemSpyEngineHelperWindowServerImpl::NewL();
       
    29     }
       
    30 
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 CMemSpyEngineHelperWindowServerImpl::CMemSpyEngineHelperWindowServerImpl()
       
    35     {
       
    36     }
       
    37 
       
    38     
       
    39 CMemSpyEngineHelperWindowServerImpl::~CMemSpyEngineHelperWindowServerImpl()
       
    40     {
       
    41     iWsSession.Close();
       
    42     }
       
    43 
       
    44 
       
    45 void CMemSpyEngineHelperWindowServerImpl::ConstructL()
       
    46     {
       
    47     User::LeaveIfError( iWsSession.Connect() );
       
    48     }
       
    49 
       
    50 
       
    51 EXPORT_C CMemSpyEngineHelperWindowServerImpl* CMemSpyEngineHelperWindowServerImpl::NewL()
       
    52     {
       
    53     CMemSpyEngineHelperWindowServerImpl* self = new(ELeave) CMemSpyEngineHelperWindowServerImpl();
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL();
       
    56     CleanupStack::Pop( self );
       
    57     return self;
       
    58     }
       
    59 
       
    60 
       
    61 EXPORT_C MMemSpyEngineWindowGroupList* CMemSpyEngineHelperWindowServerImpl::WindowGroupListL()
       
    62     {
       
    63     CMemSpyEngineWindowGroupListImpl* list = CMemSpyEngineWindowGroupListImpl::NewLC();
       
    64     //
       
    65     RArray<TMemSpyEngineWindowGroupBasicInfo> groups;
       
    66     CleanupClosePushL( groups );
       
    67     //
       
    68     GetWindowGroupListL( groups );
       
    69     //
       
    70     const TInt count = groups.Count();
       
    71     for( TInt i = 0; i < count; i++ )
       
    72         {
       
    73         list->AddItemL( groups[ i ] );
       
    74         }
       
    75     //
       
    76     CleanupStack::PopAndDestroy( &groups );
       
    77 
       
    78     // Done
       
    79     CleanupStack::Pop( list );
       
    80     return list;
       
    81     }
       
    82 
       
    83 
       
    84 EXPORT_C void CMemSpyEngineHelperWindowServerImpl::GetWindowGroupListL( RArray<TMemSpyEngineWindowGroupBasicInfo>& aWindowGroups )
       
    85     {
       
    86     TInt count;
       
    87     User::LeaveIfError( count = iWsSession.NumWindowGroups() );
       
    88     RArray<RWsSession::TWindowGroupChainInfo> array;
       
    89     CleanupClosePushL( array );
       
    90     User::LeaveIfError( iWsSession.WindowGroupList( &array ) );
       
    91     for (TInt i =0; i < count; i++ )
       
    92         {
       
    93         TMemSpyEngineWindowGroupBasicInfo group;
       
    94         group.iId = array[i].iId;
       
    95         TThreadId threadId;
       
    96         RThread thread;
       
    97         iWsSession.GetWindowGroupClientThreadId( array[i].iId, threadId );
       
    98         group.iThreadId = threadId;
       
    99         group.iOrdinalPosition = i;
       
   100         if ( !thread.Open( threadId ) )
       
   101             {
       
   102             _LIT( KLineFormatSpec, "%d\t%S" );
       
   103             group.iFullName.Format( KLineFormatSpec, group.iId, &thread.Name() );
       
   104             }
       
   105         else
       
   106             {
       
   107             _LIT( KLineFormatSpec, "%d\t<Unresolved name>" );
       
   108             group.iFullName.Format( KLineFormatSpec, group.iId );
       
   109             }
       
   110         thread.Close();        
       
   111         aWindowGroups.AppendL( group );
       
   112         }
       
   113     CleanupStack::PopAndDestroy( &array );
       
   114     }
       
   115 
       
   116 
       
   117 EXPORT_C void CMemSpyEngineHelperWindowServerImpl::GetWindowGroupDetailsL( TInt aWindowGroupId, TMemSpyEngineWindowGroupDetails& aWindowGroupDetails )
       
   118     {
       
   119     TThreadId threadId;
       
   120     RThread thread;
       
   121     iWsSession.GetWindowGroupClientThreadId( aWindowGroupId, threadId );
       
   122     aWindowGroupDetails.iThreadId = threadId;
       
   123     aWindowGroupDetails.iId = aWindowGroupId;
       
   124     if ( !thread.Open( threadId ) )
       
   125         {
       
   126         aWindowGroupDetails.iFullName.Copy( thread.Name() );
       
   127         }
       
   128     else
       
   129         {
       
   130         aWindowGroupDetails.iFullName.Copy( _L("<Unresolved name>") );
       
   131         }
       
   132     thread.Close();
       
   133     aWindowGroupDetails.iPriority = iWsSession.GetWindowGroupOrdinalPriority( aWindowGroupId );
       
   134     aWindowGroupDetails.iWindowGroupHandle = iWsSession.GetWindowGroupHandle( aWindowGroupId );
       
   135     CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( iWsSession, aWindowGroupId );
       
   136     aWindowGroupDetails.iUID = wgName->AppUid();
       
   137     aWindowGroupDetails.iIsBusy = wgName->IsBusy();
       
   138     aWindowGroupDetails.iIsSystem = wgName->IsSystem();
       
   139     aWindowGroupDetails.iIsHidden = wgName->Hidden();
       
   140     aWindowGroupDetails.iCaption = wgName->Caption();
       
   141     aWindowGroupDetails.iDocName = wgName->DocName();
       
   142     CleanupStack::PopAndDestroy( wgName );
       
   143     }
       
   144         
       
   145 
       
   146 EXPORT_C void CMemSpyEngineHelperWindowServerImpl::SwitchToL( TInt aWindowGroupId )
       
   147     {
       
   148     TApaTask task( iWsSession );
       
   149     CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( iWsSession, aWindowGroupId );
       
   150     task.SetWgId( aWindowGroupId );
       
   151     if ( wgName->Hidden() )
       
   152         {
       
   153         User::Leave( KErrGeneral );
       
   154         }
       
   155     if ( !task.Exists() )
       
   156         {
       
   157         User::Leave( KErrNotFound );
       
   158         }
       
   159     task.BringToForeground();                     
       
   160     CleanupStack::PopAndDestroy( wgName );
       
   161     }
       
   162 
       
   163 
       
   164 
       
   165 
       
   166 
       
   167 
       
   168 
       
   169 
       
   170         
       
   171 CMemSpyEngineWindowGroupListImpl::CMemSpyEngineWindowGroupListImpl()
       
   172     {
       
   173     }
       
   174 
       
   175 
       
   176 CMemSpyEngineWindowGroupListImpl::~CMemSpyEngineWindowGroupListImpl()
       
   177     {
       
   178     iItems.Close();
       
   179     }
       
   180 
       
   181 
       
   182 void CMemSpyEngineWindowGroupListImpl::ConstructL()
       
   183     {
       
   184     }
       
   185 
       
   186 
       
   187 CMemSpyEngineWindowGroupListImpl* CMemSpyEngineWindowGroupListImpl::NewLC()
       
   188     {
       
   189     CMemSpyEngineWindowGroupListImpl* self = new(ELeave) CMemSpyEngineWindowGroupListImpl();
       
   190     CleanupStack::PushL( self );
       
   191     self->ConstructL();
       
   192     return self;
       
   193     }
       
   194 
       
   195 
       
   196 EXPORT_C TInt CMemSpyEngineWindowGroupListImpl::Count() const
       
   197     {
       
   198     return iItems.Count();
       
   199     }
       
   200 
       
   201 
       
   202 EXPORT_C const TMemSpyEngineWindowGroupBasicInfo& CMemSpyEngineWindowGroupListImpl::At( TInt aIndex ) const
       
   203     {
       
   204     return iItems[ aIndex ];
       
   205     }
       
   206 
       
   207 
       
   208 EXPORT_C TInt CMemSpyEngineWindowGroupListImpl::ItemIndex( const TMemSpyEngineWindowGroupBasicInfo& /*aEntry*/ ) const
       
   209     {
       
   210     TInt ret = KErrNotFound;
       
   211     return ret;
       
   212     }
       
   213 
       
   214 
       
   215 void CMemSpyEngineWindowGroupListImpl::AddItemL( TMemSpyEngineWindowGroupBasicInfo& aItem )
       
   216     {
       
   217     iItems.AppendL( aItem );
       
   218     }
       
   219 
       
   220 
       
   221 EXPORT_C TInt CMemSpyEngineWindowGroupListImpl::MdcaCount() const
       
   222     {
       
   223     return Count();
       
   224     }
       
   225 
       
   226 
       
   227 EXPORT_C TPtrC CMemSpyEngineWindowGroupListImpl::MdcaPoint( TInt aIndex ) const
       
   228     {
       
   229     return TPtrC( At( aIndex ).iFullName );
       
   230     }
       
   231 
       
   232