tstaskmonitor/server/src/tsfswengine.cpp
changeset 83 156f692b1687
parent 80 397d00875918
equal deleted inserted replaced
80:397d00875918 83:156f692b1687
    15  *
    15  *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include "tsfswengine.h"
    19 #include "tsfswengine.h"
    20 
       
    21 #include "tsfswdatalist.h"
    20 #include "tsfswdatalist.h"
    22 
       
    23 
       
    24 
       
    25 
       
    26 #include <apgtask.h>
       
    27 #include <AknDef.h>
       
    28 #include <apgwgnam.h>
       
    29 #include <mmf/common/mmfcontrollerpluginresolver.h> // for CleanupResetAndDestroyPushL
       
    30 #include <featmgr.h>
       
    31 #include <swi/swispubsubdefs.h>
       
    32 #include <s32mem.h>
       
    33 #include <bitmaptransforms.h>
       
    34 
       
    35 // time to wait before refreshing content
       
    36 const TInt KContentRefreshDelay = 50000; // 0.05 sec
       
    37 
    21 
    38 
    22 
    39 // --------------------------------------------------------------------------
    23 // --------------------------------------------------------------------------
    40 // CTsFswEngine::NewL
    24 // CTsFswEngine::NewL
    41 // --------------------------------------------------------------------------
    25 // --------------------------------------------------------------------------
    42 //
    26 //
    43 CTsFswEngine* CTsFswEngine::NewL( MHsDataObserver& aObserver )
    27 CTsFswEngine* CTsFswEngine::NewL(MHsDataObserver& observer)
    44     {
    28 {
    45     CTsFswEngine* self = NewLC( aObserver );
    29     CTsFswEngine* self = NewLC(observer);
    46     CleanupStack::Pop( self );
    30     CleanupStack::Pop(self);
    47     return self;
    31     return self;
    48     }
    32 }
    49 
    33 
    50 // --------------------------------------------------------------------------
    34 // --------------------------------------------------------------------------
    51 // CTsFswEngine::NewLC
    35 // CTsFswEngine::NewLC
    52 // --------------------------------------------------------------------------
    36 // --------------------------------------------------------------------------
    53 //
    37 //
    54 CTsFswEngine* CTsFswEngine::NewLC( MHsDataObserver& aObserver )
    38 CTsFswEngine* CTsFswEngine::NewLC(MHsDataObserver& observer)
    55     {
    39 {
    56     CTsFswEngine* self = new ( ELeave ) CTsFswEngine( aObserver );
    40     CTsFswEngine* self = new (ELeave) CTsFswEngine(observer);
    57     CleanupStack::PushL( self );
    41     CleanupStack::PushL(self);
    58     self->ConstructL();
    42     self->ConstructL();
    59     return self;
    43     return self;
    60     }
    44 }
    61 
    45 
    62 // --------------------------------------------------------------------------
    46 // --------------------------------------------------------------------------
    63 // CTsFswEngine::CTsFswEngine
    47 // CTsFswEngine::CTsFswEngine
    64 // --------------------------------------------------------------------------
    48 // --------------------------------------------------------------------------
    65 //
    49 //
    66 CTsFswEngine::CTsFswEngine( MHsDataObserver& aObserver )
    50 CTsFswEngine::CTsFswEngine(MHsDataObserver& observer) :
    67         :iObserver( aObserver )
    51     mObserver(observer)
    68     {
    52 {
    69     }
    53 }
    70 
    54 
    71 // --------------------------------------------------------------------------
    55 // --------------------------------------------------------------------------
    72 // CTsFswEngine::ConstructL
    56 // CTsFswEngine::ConstructL
    73 // --------------------------------------------------------------------------
    57 // --------------------------------------------------------------------------
    74 //
    58 //
    75 void CTsFswEngine::ConstructL()
    59 void CTsFswEngine::ConstructL()
    76     {
    60 {
    77     User::LeaveIfError( iWsSession.Connect() );
    61     mDataList = CTsFswDataList::NewL(mObserver);
    78     User::LeaveIfError( iAppArcSession.Connect() );
       
    79 
       
    80     iDataList = CTsFswDataList::NewL(*this);    
       
    81 
       
    82     // get an initial list of tasks
       
    83     iDataList->SetAppDataRefreshNeeded();
       
    84     CollectTasksL();
    62     CollectTasksL();
    85 
    63 }
    86     iUpdateStarter = CPeriodic::NewL( CActive::EPriorityStandard );   
       
    87     }
       
    88 
    64 
    89 // --------------------------------------------------------------------------
    65 // --------------------------------------------------------------------------
    90 // CTsFswEngine::~CTsFswEngine
    66 // CTsFswEngine::~CTsFswEngine
    91 // --------------------------------------------------------------------------
    67 // --------------------------------------------------------------------------
    92 //
    68 //
    93 CTsFswEngine::~CTsFswEngine()
    69 CTsFswEngine::~CTsFswEngine()
    94     {
    70 {
    95 
    71     delete mDataList;
    96     delete iUpdateStarter;
    72 }
    97 
       
    98     iWgIds.Close();
       
    99 
       
   100     iAppArcSession.Close();
       
   101     iWsSession.Close();
       
   102 
       
   103     delete iDataList;
       
   104     }
       
   105 
    73 
   106 // --------------------------------------------------------------------------
    74 // --------------------------------------------------------------------------
   107 // CTsFswEngine::FswDataL
    75 // CTsFswEngine::FswDataL
   108 // --------------------------------------------------------------------------
    76 // --------------------------------------------------------------------------
   109 //
    77 //
   110 const RTsFswArray& CTsFswEngine::FswDataL()
    78 const RTsFswArray& CTsFswEngine::FswDataL()
   111     {
    79 {
   112     return iDataList->FswDataL();
    80     return mDataList->FswDataL();
   113     }
    81 }
   114 
    82 
   115 // --------------------------------------------------------------------------
    83 // --------------------------------------------------------------------------
   116 // CTsFswEngine::UpdateTaskList
    84 // CTsFswEngine::UpdateTaskList
   117 // Callback from appui
    85 // Callback from appui
   118 // --------------------------------------------------------------------------
    86 // --------------------------------------------------------------------------
   119 //
    87 //
   120 void CTsFswEngine::UpdateTaskList()
    88 void CTsFswEngine::DataChanged()
   121     {
    89 {
   122     // There can be many calls in a row, use a timer to prevent degrading
    90     TBool changed = EFalse;
   123     // device performance.
    91     TRAPD( err, changed = CollectTasksL() );
   124     iDataList->SetDirty();
    92     if (err == KErrNone && changed) {
   125     if ( !iUpdateStarter->IsActive() )
    93         mObserver.DataChanged();
   126         {
       
   127         iUpdateStarter->Start( KContentRefreshDelay, 0,
       
   128                 TCallBack( UpdateStarterCallback, this ) );
       
   129         }    
       
   130     // get the foreground app uid and publish it to CFW if different than before
       
   131     TRAP_IGNORE( PublishFgAppUidL() );
       
   132     }
    94     }
   133 
    95 }
   134 // --------------------------------------------------------------------------
       
   135 // CTsFswEngine::UpdateStarterCallback
       
   136 // Callback for the timer
       
   137 // --------------------------------------------------------------------------
       
   138 //
       
   139 TInt CTsFswEngine::UpdateStarterCallback( TAny* aParam )
       
   140     {
       
   141     CTsFswEngine* self = static_cast<CTsFswEngine*>( aParam );
       
   142     self->iUpdateStarter->Cancel();
       
   143     // get list of tasks and notify observer if there is a change in the list
       
   144     TBool changed = EFalse;
       
   145     TRAPD( err, changed = self->CollectTasksL() );
       
   146     if ( err == KErrNone && changed )
       
   147         {
       
   148         self->iObserver.DataChanged();
       
   149         }
       
   150     return 0;
       
   151     }
       
   152 
    96 
   153 // --------------------------------------------------------------------------
    97 // --------------------------------------------------------------------------
   154 // CTsFswEngine::CollectTasksL
    98 // CTsFswEngine::CollectTasksL
   155 // --------------------------------------------------------------------------
    99 // --------------------------------------------------------------------------
   156 //
   100 //
   157 TBool CTsFswEngine::CollectTasksL()
   101 TBool CTsFswEngine::CollectTasksL()
   158     {
   102 {
   159     TBool changed = iDataList->CollectTasksL();
   103     TBool changed = mDataList->CollectTasksL();
   160     return changed;
   104     return changed;
   161     }
   105 }
   162 
   106 
   163 // --------------------------------------------------------------------------
   107 // --------------------------------------------------------------------------
   164 // CTsFswEngine::ForegroundAppUidL
   108 // CTsFswEngine::SetScreenshotL
   165 // --------------------------------------------------------------------------
   109 // --------------------------------------------------------------------------
   166 //
   110 //
   167 TUid CTsFswEngine::ForegroundAppUidL( TInt aType )
   111 void CTsFswEngine::SetScreenshotL(const CFbsBitmap* bitmap, UpdatePriority priority, TInt wgId)
   168     {
   112 {
   169     // Do not use GetFocusWindowGroup or others.
   113     TBool changed = mDataList->SetScreenshotL(bitmap, priority, wgId);
   170     // We want to see only "real" application uids in FgApp,
   114     if (!changed) {
   171     // i.e. stuff that would also be shown in the task swapper
   115         User::Leave(KErrAccessDenied);
   172     // area of Taskswitcher.
       
   173 
       
   174     TUid result = KNullUid;
       
   175     RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
       
   176     CleanupClosePushL( allWgIds );
       
   177     User::LeaveIfError( iWsSession.WindowGroupList( 0, &allWgIds ) );
       
   178     TInt count = allWgIds.Count();
       
   179     for ( TInt i = 0; i < count; ++i )
       
   180         {
       
   181         // Depending on aType we may not need to bother with iParentId here.
       
   182         // If aType == EUseEmbeddedUid => embedded apps are treated as others.
       
   183         // If aType == EUseStandaloneUid => embedded apps must be ignored.
       
   184         if ( allWgIds[i].iParentId > 0
       
   185                 && aType == CTsFswEngine::EUseStandaloneUid )
       
   186             {
       
   187             continue;
       
   188             }
       
   189 
       
   190         CApaWindowGroupName* wgn = CApaWindowGroupName::NewLC(
       
   191             iWsSession, allWgIds[i].iId );
       
   192         TUid newUid = wgn->AppUid();
       
   193         TBool hidden = wgn->Hidden();
       
   194         CleanupStack::PopAndDestroy( wgn );
       
   195 
       
   196         if ( !hidden && newUid.iUid && !iDataList->IsHiddenUid(newUid) )
       
   197             {
       
   198             result = newUid;
       
   199             break;
       
   200             }
       
   201         }
       
   202     CleanupStack::PopAndDestroy( &allWgIds );
       
   203     
       
   204     return result;
       
   205     }
   116     }
       
   117 }
   206 
   118 
   207 // --------------------------------------------------------------------------
   119 // --------------------------------------------------------------------------
   208 // CTsFswEngine::PublishFgAppUidL
   120 // CTsFswEngine::SetScreenshotL
   209 // --------------------------------------------------------------------------
   121 // --------------------------------------------------------------------------
   210 //
   122 //
   211 void CTsFswEngine::PublishFgAppUidL()
   123 void CTsFswEngine::RemoveScreenshotL(TInt wgId)
   212     {
   124 {
   213     TUid newUid = ForegroundAppUidL( CTsFswEngine::EUseEmbeddedUid );
   125     TBool changed = mDataList->RemoveScreenshotL(wgId);
   214     if ( iFgAppUid != newUid && newUid.iUid )
   126     if (changed) {
   215         {
   127         mObserver.DataChanged();
   216         iFgAppUid = newUid;
       
   217         iDataList->MoveEntryAtStart(newUid.iUid, EFalse);
       
   218         }
       
   219     }
   128     }
   220 
   129 }
   221 // end of file
   130 // end of file