sysresmonitoring/oommonitor/inc/oommemorymonitor.h
changeset 35 13fd6fd25fe7
child 46 eea20ed08f4b
equal deleted inserted replaced
29:6a787171e1de 35:13fd6fd25fe7
       
     1 /*
       
     2 * Copyright (c) 2006-2010 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:  Main classes for Out of Memory Monitor.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef OOMMEMORYMONITOR_H
       
    20 #define OOMMEMORYMONITOR_H
       
    21 
       
    22 #include <e32property.h>
       
    23 #include <f32file.h>
       
    24 #include <w32std.h>
       
    25 #include "oomglobalconfig.h"
       
    26 #include "oomwindowgrouplist.h"
       
    27 #include "oommonitorsession.h"
       
    28 
       
    29 enum TActionTriggerType
       
    30     {
       
    31     ERamRotation,
       
    32     EClientServerRequestOptionalRam,
       
    33     EClientServerRequestFreeMemory,
       
    34     EPublishAndSubscribe        
       
    35     };
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // CMemoryMonitor
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 class COutOfMemoryWatcher;
       
    42 class CSubscribeHelper;
       
    43 class COomMonitorPlugin;
       
    44 class CMemoryMonitorServer;
       
    45 class CWservEventReceiver;
       
    46 class COomActionList;
       
    47 class COomLogger;
       
    48 class COomConfig;
       
    49 class COomClientRequestQueue;
       
    50 
       
    51 /**
       
    52  *  The main manager class for Oom Monitor. It has the following responsibility: 
       
    53  *  
       
    54  *  - initiates building the static configuration at boot time and owns the object which holds this. 
       
    55  *  - owns and drives the action list which runs actions
       
    56  *  - owns the internal representation of the window group list and an active object to monitor window group changes
       
    57  *  - owns the public API via the server and client request queue.
       
    58  *  - has an active object which monitors low RAM events
       
    59  *
       
    60  *  @lib oommonitor.lib
       
    61  *  @since S60 v5.0
       
    62  */
       
    63 NONSHARABLE_CLASS(CMemoryMonitor) : public CBase
       
    64     {
       
    65 public:
       
    66     static CMemoryMonitor* NewL();
       
    67     ~CMemoryMonitor();
       
    68 
       
    69 public: // event handlers
       
    70     void FreeMemThresholdCrossedL();
       
    71     void AppNotExiting(TInt aWgId);
       
    72     void StartFreeSomeRamL(TInt aFreeRamTarget, TInt aFreeSwapSpaceTarget);
       
    73     void StartFreeSomeRamL(TInt aFreeRamTarget, TInt aFreeSwapSpaceTarget, TInt aMaxPriority);
       
    74     void FreeOptionalRamL(TInt aBytesRequested, TInt aPluginId, TBool aDataPaged); // The ID of the plugin that will clear up the allocation, used to determine the priority of the allocation
       
    75     void HandleFocusedWgChangeL();
       
    76     static const COomGlobalConfig& GlobalConfig();
       
    77     void SetPriorityBusy(TInt aWgId);
       
    78     void SetPriorityNormal(TInt aWgId);
       
    79     void SetPriorityHigh(TInt aWgId);
       
    80     void ResetTargets();
       
    81     void RequestTimerCallbackL();
       
    82     void GetFreeMemory(TInt& aCurrentFreeMemory);
       
    83     void GetFreeSwapSpace(TInt& aCurrentFreeSwapSpace);
       
    84     TActionTriggerType ActionTrigger() const;
       
    85 #ifdef CLIENT_REQUEST_QUEUE
       
    86     void ActionsCompleted(TInt aBytesFree, TBool aMemoryGood);
       
    87     TInt GoodRamThreshold() const;
       
    88     TInt LowRamThreshold() const;
       
    89 #endif
       
    90     void RequestFreeMemoryL(TInt aBytesRequested, TBool aDataPaged);
       
    91     void RequestFreeMemoryPandSL(TInt aBytesRequested);
       
    92     
       
    93     /*
       
    94      * Sets the RProperty associated with KOomMemoryMonitorStatusPropertyKey
       
    95      * It checks if the value is going to be changed. 
       
    96      * If the new value is the same as the old one then the property is not updated
       
    97      * If the new value is different from the previously set one then the property is update
       
    98      * 
       
    99      * @param aNewValue one of TMemoryMonitorStatusPropertyValues 
       
   100      */
       
   101     void SetMemoryMonitorStatusProperty(const TMemoryMonitorStatusPropertyValues aValue);
       
   102    
       
   103 private:
       
   104     CMemoryMonitor();
       
   105     void ConstructL();
       
   106 #ifndef CLIENT_REQUEST_QUEUE
       
   107     static TInt WatchdogStatusStatusChanged(TAny* aPtr);
       
   108     void HandleWatchdogStatusCallBack();
       
   109     TBool FreeMemoryAboveThreshold(TInt& aCurrentFreeMemory);    void CloseNextApp();
       
   110 #endif
       
   111     void RefreshThresholds();
       
   112     
       
   113 public:
       
   114     // All members are owned
       
   115     // generally useful sessions
       
   116     RFs iFs;
       
   117     RWsSession iWs;
       
   118 
       
   119     TBool iDataPaged;
       
   120     
       
   121 private: //data
       
   122 
       
   123     // parameters for OOM watcher.
       
   124     TInt iLowRamThreshold;
       
   125     TInt iGoodRamThreshold;
       
   126     TInt iLowSwapThreshold;
       
   127     TInt iGoodSwapThreshold;
       
   128     TInt iCurrentRamTarget;
       
   129     TInt iCurrentSwapTarget;
       
   130     
       
   131    
       
   132     
       
   133 #ifdef CLIENT_REQUEST_QUEUE
       
   134     TInt iClientBytesRequested;
       
   135 #endif        
       
   136     // event receivers
       
   137     
       
   138     /**
       
   139      * The active object which monitors the kernel change notifier for changes in the low and good thresholds
       
   140      * Own
       
   141      */    
       
   142     COutOfMemoryWatcher* iOOMWatcher;
       
   143     
       
   144     
       
   145     CWservEventReceiver* iWservEventReceiver;
       
   146 
       
   147 #ifndef CLIENT_REQUEST_QUEUE
       
   148     // parameters for P&S watcher.
       
   149     /**
       
   150     * The handle to the P&S property that can be used to initiate OOM Monitor actions
       
   151     */    
       
   152     RProperty iWatchdogStatusProperty;
       
   153 
       
   154     /**
       
   155      * The active object which monitors the P&S property that can be used to initiate OOM Monitor actions
       
   156      * Own.       
       
   157      */    
       
   158     CSubscribeHelper* iWatchdogStatusSubscriber;
       
   159 #endif
       
   160     
       
   161     /**
       
   162      * The Memory Monitor Server
       
   163      * Own.       
       
   164      */
       
   165     CMemoryMonitorServer* iServer;
       
   166     
       
   167 #ifdef CLIENT_REQUEST_QUEUE
       
   168     COomClientRequestQueue* iQueue;
       
   169 #endif
       
   170     
       
   171 #ifdef _DEBUG    
       
   172     /**
       
   173      * Oom logging tool - samples free memory for profiling
       
   174      * Own.       
       
   175      */
       
   176     COomLogger* iLogger;
       
   177 #endif
       
   178     
       
   179     /**
       
   180      * A list of window group Ids, with child window groups removed such that there is one Id per application
       
   181      * Own.       
       
   182      */    
       
   183     COomWindowGroupList* iOomWindowGroupList;
       
   184     
       
   185     /**
       
   186      * The object responsible for identifying the best actions to run, and running them 
       
   187      * Own.       
       
   188      */
       
   189     COomActionList* iOomActionList;
       
   190     
       
   191     /**
       
   192      * The entire Oom Monitor configuration
       
   193      * Own.       
       
   194      */
       
   195     COomConfig* iConfig;
       
   196 
       
   197     /**
       
   198      * The most recent value the memory monitor status property was set to 
       
   199      */
       
   200     TInt iLastMemoryMonitorStatusProperty;
       
   201     
       
   202     TActionTriggerType iActionTrigger;
       
   203     };
       
   204 
       
   205 #endif /*OOMMEMORYMONITOR_H*/