taskswitcher/contextengine/tsfswserver/engine/inc/tsfswengine.h
changeset 4 4d54b72983ae
child 9 f966699dea19
equal deleted inserted replaced
3:fb3763350a08 4:4d54b72983ae
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Task monitor engine
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef TSFSWENGINE_H
       
    20 #define TSFSWENGINE_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <e32cmn.h>
       
    24 #include <s32strm.h>
       
    25 #include <fbs.h>
       
    26 #include <eikenv.h>
       
    27 #include <w32std.h>
       
    28 #include <e32hashtab.h>
       
    29 #include <apgcli.h>
       
    30 #include <e32property.h>
       
    31 #include "tspreviewobserver.h"
       
    32 #include "tsfswentry.h"
       
    33 #include "tsfswobservers.h"
       
    34 
       
    35 class CTsFsAlwaysShownAppList;
       
    36 class CTsFsHiddenAppList;
       
    37 class CTsFsWidgetList;
       
    38 class MTsFswEngineObserver;
       
    39 class CTsFswIconCache;
       
    40 class CTsFastSwapPreviewProvider;
       
    41 class CApaWindowGroupName;
       
    42 
       
    43 // descriptor big enough to store hex repr of 32-bit integer plus 0x prefix
       
    44 typedef TBuf<10> TAppUidHexString;
       
    45 
       
    46 /**
       
    47  * Engine for fast swap server.
       
    48  * Performs task monitoring, notifications about wg changes are
       
    49  * received from the appui.
       
    50  */
       
    51 NONSHARABLE_CLASS( CTsFswEngine ) : public CActive,
       
    52         public MTsFswTaskListObserver,
       
    53         public MTsFswResourceObserver,
       
    54         public MTsFsHiddenAppListObserver,
       
    55         public MTsFastSwapPreviewObserver
       
    56     {
       
    57 public:
       
    58     /**
       
    59      * Creates a new instance.
       
    60      * @param   aObserver   ref to observer
       
    61      */
       
    62     IMPORT_C static CTsFswEngine* NewL( MTsFswEngineObserver& aObserver );
       
    63     
       
    64     /**
       
    65      * @copydoc NewL
       
    66      */
       
    67     IMPORT_C static CTsFswEngine* NewLC( MTsFswEngineObserver& aObserver );
       
    68     
       
    69     /**
       
    70      * Destructor.
       
    71      */
       
    72     ~CTsFswEngine();
       
    73 
       
    74     /**
       
    75      * Returns a reference to the current content.
       
    76      * Also performs sanity checks, e.g. associates application icons
       
    77      * when no screenshot has been received.
       
    78      * @return  ref to content array
       
    79      */
       
    80     IMPORT_C const RTsFswArray& FswDataL();
       
    81     
       
    82     /**
       
    83      * Tries to close the given app.
       
    84      * @param   aWgId   value given by WgId() for an entry in iData
       
    85      */
       
    86     IMPORT_C void CloseAppL( TInt aWgId );
       
    87     
       
    88     /**
       
    89      * Brings the given app to foreground.
       
    90      * @param   aWgId   value given by WgId() for an entry in iData
       
    91      */
       
    92     IMPORT_C void SwitchToAppL( TInt aWgId );
       
    93 
       
    94     /**
       
    95      * Returns the uid of the foreground app or KNullUid.
       
    96      * Will never return hidden apps, only those which can
       
    97      * also be seen in the array returned by FswDataL.
       
    98      *
       
    99      * In case of embedded apps the behaviour is controlled
       
   100      * by aType: it will return either the uid of the embedded
       
   101      * application or the container app.
       
   102      *
       
   103      * @param   aType   @see CTsFswClient::TTsFswFgAppType
       
   104      */
       
   105     IMPORT_C TUid ForegroundAppUidL( TInt aType );
       
   106 
       
   107 private:
       
   108     // from CActive
       
   109     void RunL();
       
   110     TInt RunError( TInt aError );
       
   111     void DoCancel();
       
   112 
       
   113     // from MTsFswTaskListObserver
       
   114     void UpdateTaskList();
       
   115     
       
   116     // from MTsFswResourceObserver
       
   117     void HandleResourceChange( TInt aType );
       
   118 
       
   119     // from MTsFsHiddenAppListObserver
       
   120     void HiddenAppListUpdated();
       
   121 
       
   122     // from MTsFastSwapPreviewObserver
       
   123     void HandleFswPpApplicationChange( TInt aWgId, TInt aFbsHandle );
       
   124     void HandleFswPpApplicationUnregistered( TInt aWgId );
       
   125 
       
   126 private:
       
   127     /**
       
   128      * Constructor.
       
   129      */
       
   130     CTsFswEngine( MTsFswEngineObserver& aObserver );
       
   131     
       
   132     /**
       
   133      * Performs 2nd phase construction.
       
   134      */
       
   135     void ConstructL();
       
   136     
       
   137     /**
       
   138      * Gets the window group list and reconstructs the fsw content.
       
   139      * @return   TBool   ETrue if the list has been modified
       
   140      */
       
   141     TBool CollectTasksL();
       
   142     
       
   143     /**
       
   144      * Called from CollectTasksL for each entry in the task list.
       
   145      * @param   aWgId       window group id
       
   146      * @param   aAppUid     application uid
       
   147      * @param   aWgName     window group name or NULL
       
   148      * @param   aNewList    list to add to
       
   149      * @param   aIsWidget   true if the entry corresponds to a web widget
       
   150      * @return  TBool   ETrue if it was really a new entry in the list
       
   151      */
       
   152     TBool AddEntryL( TInt aWgId, const TUid& aAppUid,
       
   153         CApaWindowGroupName* aWgName, RTsFswArray& aNewList,
       
   154         TBool aIsWidget );
       
   155 
       
   156     /**
       
   157      * Checks if there is an entry for same app in the content list.
       
   158      * If yes then it takes some of the data for the entry that
       
   159      * will correspond to the same app in the refreshed content list.
       
   160      * @param   aEntry      new entry in content list
       
   161      * @param   aAppUid     application uid
       
   162      * @param   aChanged    ref to change-flag, set to ETrue if it is sure
       
   163      * that the new content list will be different from the previous one
       
   164      * @param   aNewList    ref to new content list
       
   165      * @return  ETrue if app was found
       
   166      */
       
   167     TBool CheckIfExistsL( CTsFswEntry& aEntry,
       
   168         const TUid& aAppUid,
       
   169         TBool& aChanged,
       
   170         RTsFswArray& aNewList );
       
   171 
       
   172     /**
       
   173      * Adds running widgets to the list.
       
   174      * @param   aNewList    array to add to
       
   175      */
       
   176     void CheckWidgetsL( RTsFswArray& aNewList );
       
   177 
       
   178     /**
       
   179      * Finds out the app uid for the given window group id.
       
   180      * @param   aWgId   a valid window group id
       
   181      * @return  application uid
       
   182      */
       
   183     TUid AppUidForWgIdL( TInt aWgId );
       
   184     
       
   185     /**
       
   186      * Returns the parent's wg id or KErrNotFound.
       
   187      * @param   aWgId   a valid window group id
       
   188      * @return parent wg id or KErrNotFound if there is no parent
       
   189      */
       
   190     TInt FindParentWgId( TInt aWgId );
       
   191     
       
   192     /**
       
   193      * Finds out the application name.
       
   194      * @param   aWindowName window group name or NULL
       
   195      * @param   aAppUId     application uid
       
   196      * @param   aWgId       window group id
       
   197      * @return  application name, ownership transferred to caller
       
   198      */
       
   199     HBufC* FindAppNameLC( CApaWindowGroupName* aWindowName,
       
   200         const TUid& aAppUid, TInt aWgId );
       
   201 
       
   202     /**
       
   203      * Makes a copy of the bitmap with the given handle.
       
   204      * @param   aFbsHandle          bitmap handle
       
   205      * @param   aKeepAspectRatio    if true then aspect ratio is kept
       
   206      * @return  CFbsBitmap*     the copy, ownership transferred to caller
       
   207      */
       
   208     CFbsBitmap* CopyBitmapL( TInt aFbsHandle, TBool aKeepAspectRatio );
       
   209     
       
   210     /**
       
   211      * Checks if the app to which the screenshot belongs is in the task list
       
   212      * and updates the entry when found. Also triggers change notification
       
   213      * to observer when data is modified.
       
   214      * @param   aWgIdForScreenshot  wgid for the screenshot 
       
   215      * @param   aBitmapHandle       handle for screenshot bitmap
       
   216      */
       
   217     void AssignScreenshotHandle( TInt aWgIdForScreenshot, TInt aBitmapHandle );
       
   218     
       
   219     /**
       
   220      * Returns the bitmap handle for the screenshot belonging to the given app
       
   221      * or 0 if not (yet) found.
       
   222      * @param   aWgIdForApp     a window group id (from the window group list)
       
   223      * @return  bitmap handle or 0
       
   224      */
       
   225     TInt LookupScreenshotHandle( TInt aWgIdForApp );
       
   226     
       
   227     /**
       
   228      * Callback for the iUpdateStarter timer.
       
   229      * Calls CollectTasksL and notifies the observer if the task list
       
   230      * has really been modified.
       
   231      */
       
   232     static TInt UpdateStarterCallback( TAny* aParam );
       
   233 
       
   234     /**
       
   235      * Brings the given web widget to foreground.
       
   236      * @param   aWidgetIndex    index in the list of running widgets
       
   237      */
       
   238     void SwitchToWidgetL( TInt aWidgetIndex );
       
   239 
       
   240     /**
       
   241      * Configues the preview provider with current screen size.
       
   242      */
       
   243     void SetPreviewParams();
       
   244 
       
   245     /**
       
   246      * Registers and unregisters window groups to iPreviewProvider
       
   247      * if the window group list has been changed.
       
   248      */
       
   249     void UpdatePreviewContent();
       
   250 
       
   251     /**
       
   252      * Gets and publishes the foreground app uid to CFW.
       
   253      */
       
   254     void PublishFgAppUidL();
       
   255 
       
   256     /**
       
   257      * Helper function to publish something to CFW.
       
   258      * @param   aType   context type
       
   259      * @param   aValue  value to publish
       
   260      */
       
   261     //void PublishContextL( const TDesC& aType, const TDesC& aValue );
       
   262 
       
   263 private: // data    
       
   264     MTsFswEngineObserver& iObserver;
       
   265     RTsFswArray iData; // current fsw content, i.e. the task list
       
   266     CEikonEnv* iEnv; // not own
       
   267 
       
   268     // always shown app list, own    
       
   269     CTsFsAlwaysShownAppList* iAlwaysShownAppList;
       
   270     
       
   271     // hidden app list, own
       
   272     CTsFsHiddenAppList* iHiddenAppList;
       
   273     
       
   274     // web widget list, own
       
   275     CTsFsWidgetList* iWidgetList;
       
   276 
       
   277     // window server session
       
   278     RWsSession iWsSession;
       
   279     
       
   280     // apparc session
       
   281     RApaLsSession iAppArcSession;
       
   282 
       
   283     /**
       
   284      * Hash table storing the screenshots.
       
   285      * Key: window group id for the screenshot
       
   286      * (the one received in ApplicationChange)
       
   287      * Value: CFbsBitmap*, pointers owned
       
   288      */    
       
   289     RHashMap<TInt, CFbsBitmap*> iScreenshots;
       
   290     
       
   291     // preview provider instance, own
       
   292     CTsFastSwapPreviewProvider* iPreviewProvider;
       
   293     
       
   294     // timer to defer content refresh
       
   295     CPeriodic* iUpdateStarter;
       
   296     
       
   297     // app icon provider/container instance, own
       
   298     CTsFswIconCache* iAppIcons;
       
   299     
       
   300     // true if web widgets are supported by the system
       
   301     TBool iWidgetsSupported;
       
   302     // wgid of widget appui is saved here
       
   303     TInt iWidgetAppUiWgId;
       
   304 
       
   305     // PS property to listen for swi status changes
       
   306     RProperty iSwiProp;
       
   307     // when true CollectTasksL will call GetAllApps etc.
       
   308     // which is slow and need not be done normally, except
       
   309     // during startup and perhaps when new applications are installed
       
   310     TBool iAppDataRefreshNeeded;
       
   311 
       
   312     // window group ids returned by last WindowGroupList call
       
   313     RArray<TInt> iWgIds;
       
   314     
       
   315     // Dirty flag, indicates that iData is not up-to-date because
       
   316     // there were no subscribed clients during a previous possible
       
   317     // change of the task list.
       
   318     TBool iTaskListDirty;
       
   319 
       
   320     // For publishing the foreground app uid to Context Framework    
       
   321     TAppUidHexString iFgAppUidStr;
       
   322     TUid iFgAppUid;
       
   323 
       
   324     };
       
   325 
       
   326 #endif