uiacceltk/hitchcock/goommonitor/inc/goomactionlist.h
changeset 0 15bf7259bb7c
child 3 d8a3531bc6b8
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     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:  Classes for executing Graphics OOM actions (e.g. closing applications and running plugins).
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef GOOMACTIONLIST_H_
       
    20 #define GOOMACTIONLIST_H_
       
    21 
       
    22 #include <e32def.h>
       
    23 #include <e32base.h>
       
    24 
       
    25 #include "goommonitorplugin.h"
       
    26 #include "goommemorymonitor.h"
       
    27 
       
    28 class CGOomWindowGroupList;
       
    29 class CMemoryMonitorServer;
       
    30 class CGOomCloseApp;
       
    31 class TActionRef;
       
    32 class CGOomRunPlugin;
       
    33 class CGOomConfig;
       
    34 
       
    35 /*
       
    36  * Interface for reporting a change of state in a GOOM action
       
    37  * e.g. that the action has changed from a freeing-memory state to an idle state
       
    38  * 
       
    39  * @lib oommonitor.lib
       
    40  * @since S60 v5.0
       
    41  */
       
    42 class MGOomActionObserver
       
    43     {
       
    44 public:
       
    45     virtual void StateChanged() = 0;
       
    46     virtual TInt ClientId() = 0;
       
    47     };
       
    48 
       
    49 
       
    50 template <class T> 
       
    51 /**
       
    52  *  A class for getting instances of all of the GOOM ECom plugins
       
    53  *  This class is templated because we actually need two types of list
       
    54  *  One list for V1 plugins
       
    55  *  One list for V2 plugins
       
    56  *  The functionality of each list is nearly identical, hence the templated class
       
    57  *  
       
    58  * @lib oommonitor.lib
       
    59  * @since S60 v5.0
       
    60  */
       
    61 NONSHARABLE_CLASS(CGOomPluginList) : public CBase
       
    62     {
       
    63 public:
       
    64     
       
    65     /**
       
    66      * Two-phased constructor.
       
    67      * @param aInterfaceUid The interface of the plugin (either V1 or V2) depending on the templated type
       
    68      */
       
    69     static CGOomPluginList* NewL(TInt aInterfaceUid);
       
    70     inline TInt Count();
       
    71     inline T& Implementation(TInt aIndex);
       
    72     inline TInt32 Uid(TInt aIndex);
       
    73     
       
    74     ~CGOomPluginList();
       
    75     
       
    76 private:
       
    77     CGOomPluginList();
       
    78     void ConstructL(TInt aInterfaceUid);
       
    79     
       
    80 private: // data
       
    81     
       
    82     struct TPlugin
       
    83         {
       
    84         TPlugin();
       
    85         T* iImpl;
       
    86         TUid iDtorUid;
       
    87         TInt32 iUid;
       
    88         };
       
    89     
       
    90     RArray<TPlugin> iPlugins;
       
    91     };
       
    92 
       
    93     
       
    94 /*
       
    95  * The list of possible OOM actions to be run.
       
    96  * 
       
    97  * This class is responsible for identifying the best action(s) to execute at a given time.
       
    98  * This decision is based on the properties of each action and idle time of the target apps.
       
    99  *
       
   100  *  @lib oommonitor.lib
       
   101  *  @since S60 v5.0
       
   102  */
       
   103 NONSHARABLE_CLASS(CGOomActionList) : public CBase, public MGOomActionObserver
       
   104     {
       
   105 public:
       
   106 
       
   107     /**
       
   108      * Two-phased constructor.
       
   109      * @param aMonitor the owning Memory Monitor
       
   110      * @param aServer 
       
   111      * @param aWs a handle to a window server session, opened by the Memory Monitor
       
   112      * @param aConfig
       
   113      */
       
   114     static CGOomActionList* NewL(CMemoryMonitor& aMonitor, CMemoryMonitorServer& aServer, RWsSession& aWs, CGOomConfig& aConfig);
       
   115 
       
   116     ~CGOomActionList();
       
   117     
       
   118     /**
       
   119      * Creates a list of actions based on the contents of the config and the current window group list
       
   120      * Any old actions will be replaced.
       
   121      * 
       
   122      * @since S60 5.0
       
   123      * @param aWindowGroupList
       
   124      * @param aConfig
       
   125      */
       
   126     void BuildPluginActionListL(CGOomWindowGroupList& aWindowGroupList, CGOomConfig& aConfig);    
       
   127     void BuildKillAppActionListL(CGOomWindowGroupList& aWindowGroupList, CGOomConfig& aConfig);
       
   128     
       
   129     /**
       
   130      * Execute the OOM actions according to their priority
       
   131      * Actions are run in batches according to their sync mode
       
   132      * 
       
   133      * @since S60 5.0
       
   134      * @param aMaxPriority The maximum priority of actions to run 
       
   135      */     
       
   136     void FreeMemory(TInt aMaxPriority);
       
   137     
       
   138     /**
       
   139      * Sets the target; the maximum prioirity up to which actions are run when an GOomMonitor event 
       
   140      * occurs
       
   141      * 
       
   142      * @since S60 5.0
       
   143      * @param aCurrentTarget the prio
       
   144      */    
       
   145     inline void SetCurrentTarget(TUint aCurrentTarget);
       
   146     
       
   147     /**
       
   148      * Should be called when the memory situation is good, i.e. the actions run have released enough memory 
       
   149      * so that the device is above the current target.
       
   150      * It results in notifications of the good memory state to all plugins
       
   151      * 
       
   152      * @since S60 5.0
       
   153      */     
       
   154     void MemoryGood();
       
   155         
       
   156     /**
       
   157      * Checks the current memory level of the device and compares this with the current target
       
   158      * 
       
   159      * @since S60 5.0
       
   160      * @param aFreeMemory the amount of free memory left on the device
       
   161      * @return ETrue if the free memory is above the current target, else EFalse
       
   162      */    
       
   163     TBool FreeMemoryAboveTarget(TInt& aFreeMemory);
       
   164         
       
   165     /**
       
   166      * Compares priorites of two actions, hard-coded rules are used to determine the order 
       
   167      * of actions with equal priority:
       
   168      * - application plugins are run in preference to system plugins
       
   169      * - appliction plugins where the target app is not running are run first
       
   170      * - Z order of the target app determines order of the rest of the application plugins (furthest back first)
       
   171      * - system plugins are run before app close actions
       
   172      * - Z order determines the prioirty of app close actions (furthest back first)
       
   173      * 
       
   174      * @since S60 5.0
       
   175      */    
       
   176     static TInt ComparePriorities(const TActionRef& aPos1, const TActionRef& aPos2 );
       
   177 
       
   178     /**
       
   179      * A callback from the UI framework that an applications has failed to respond to the close event.
       
   180      * Allows us to cleanup the related app close action object and move on the next available action.
       
   181      * 
       
   182      * @since S60 5.0
       
   183      * @param aWgId the window group ID of the application that has not closed.
       
   184      */    
       
   185     void AppNotExiting(TInt aWgId);
       
   186     
       
   187 // from MGOomActionObserver
       
   188 
       
   189     /**
       
   190      * 
       
   191      * from MGOomActionObserver
       
   192      * 
       
   193      * An action has changed state (possibly it has completed freeing memory)
       
   194      */
       
   195     void StateChanged();    
       
   196     
       
   197     /** The secure id of a client that requested free memory **/
       
   198     TInt ClientId()
       
   199         {
       
   200         return iMonitor.ActiveClientId();
       
   201         }
       
   202     
       
   203     void SetPriority(TInt aWgId, TInt aPriority);
       
   204             
       
   205 private:
       
   206     
       
   207     CGOomActionList(CMemoryMonitor& aMonitor, CMemoryMonitorServer& aServer, RWsSession& aWs);
       
   208     
       
   209     void ConstructL(CGOomConfig& aConfig);
       
   210     
       
   211 private: //data    
       
   212     
       
   213     RWsSession& iWs;
       
   214     
       
   215     RPointerArray<CGOomCloseApp> iCloseAppActions;
       
   216     RPointerArray<CGOomRunPlugin> iRunPluginActions;
       
   217     RArray<TActionRef> iActionRefs;
       
   218     
       
   219     TInt iCurrentActionIndex;
       
   220         
       
   221     TUint iCurrentTarget;
       
   222 
       
   223     /*
       
   224      * Flag specifying that a GOomMonitor event is in progress.
       
   225      */
       
   226     TBool iFreeingMemory;
       
   227     
       
   228     CMemoryMonitor& iMonitor;
       
   229 
       
   230     /**
       
   231      * The list of plugins
       
   232      * Own
       
   233      */
       
   234     CGOomPluginList<CGOomMonitorPlugin>* iPluginList;
       
   235 
       
   236     
       
   237     /**
       
   238      * The maximum priority of actions that should be run by an GOomMonitor Event
       
   239      */
       
   240     TInt iMaxPriority; 
       
   241     
       
   242     CMemoryMonitorServer& iServer;
       
   243     
       
   244     RArray<TUint> iAppsProtectedByPlugins;
       
   245     
       
   246     TBool iRunningKillAppActions;
       
   247     };
       
   248 
       
   249 #include "goomactionlist.inl"
       
   250 
       
   251 #endif /*GOOMACTIONLIST_H_*/