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