sysresmonitoring/oommonitor/src/oomoutofmemorywatcher.cpp
branchRCL_3
changeset 58 0818dd463d41
parent 12 7645e9ce10dc
child 62 924385140d98
equal deleted inserted replaced
57:5e7d68cc22e0 58:0818dd463d41
     1 /*
     1 /*
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    28 
    28 
    29 // ---------------------------------------------------------
    29 // ---------------------------------------------------------
    30 //
    30 //
    31 // ---------------------------------------------------------
    31 // ---------------------------------------------------------
    32 //
    32 //
    33 COutOfMemoryWatcher* COutOfMemoryWatcher::NewL(CMemoryMonitor& aMonitor, TInt aLowThreshold, TInt aGoodThreshold)
    33 COutOfMemoryWatcher* COutOfMemoryWatcher::NewL(CMemoryMonitor& aMonitor, TInt aLowRamThreshold, TInt aGoodRamThreshold, TBool aSwapUsageMonitored, TInt aLowSwapThreshold, TInt aGoodSwapThreshold)
    34     {
    34     {
    35     FUNC_LOG;
    35     FUNC_LOG;
    36 
    36 
    37     COutOfMemoryWatcher* self = new (ELeave) COutOfMemoryWatcher(aMonitor);
    37     COutOfMemoryWatcher* self = new (ELeave) COutOfMemoryWatcher(aMonitor, aSwapUsageMonitored);
    38     CleanupStack::PushL(self);
    38     CleanupStack::PushL(self);
    39     self->ConstructL(aLowThreshold, aGoodThreshold);
    39     self->ConstructL(aLowRamThreshold, aGoodRamThreshold, aLowSwapThreshold, aGoodSwapThreshold);
    40     CleanupStack::Pop(self);
    40     CleanupStack::Pop(self);
    41     return self;
    41     return self;
    42     }
    42     }
    43 
    43 
    44 // ---------------------------------------------------------
    44 // ---------------------------------------------------------
    54 
    54 
    55 // ---------------------------------------------------------
    55 // ---------------------------------------------------------
    56 //
    56 //
    57 // ---------------------------------------------------------
    57 // ---------------------------------------------------------
    58 //
    58 //
    59 COutOfMemoryWatcher::COutOfMemoryWatcher(CMemoryMonitor& aMonitor)
    59 COutOfMemoryWatcher::COutOfMemoryWatcher(CMemoryMonitor& aMonitor, TBool aSwapUsageMonitored)
    60 :   CActive(CActive::EPriorityStandard),
    60 :   CActive(CActive::EPriorityStandard),
    61     iLafShutdown(aMonitor)
    61     iMemoryMonitor(aMonitor),
       
    62     iSwapUsageMonitored(aSwapUsageMonitored)
    62     {
    63     {
    63     FUNC_LOG;
    64     FUNC_LOG;
    64 
    65 
    65     CActiveScheduler::Add(this);
    66     CActiveScheduler::Add(this);
    66     }
    67     }
    67 
    68 
    68 // ---------------------------------------------------------
    69 // ---------------------------------------------------------
    69 //
    70 //
    70 // ---------------------------------------------------------
    71 // ---------------------------------------------------------
    71 //
    72 //
    72 void COutOfMemoryWatcher::ConstructL(TInt aLowThreshold, TInt aGoodThreshold)
    73 void COutOfMemoryWatcher::ConstructL(TInt aLowRamThreshold, TInt aGoodRamThreshold, TInt aLowSwapThreshold, TInt aGoodSwapThreshold)
    73     {
    74     {
    74     FUNC_LOG;
    75     FUNC_LOG;
    75 
    76 
    76     UserSvr::SetMemoryThresholds(aLowThreshold,aGoodThreshold);
    77     UserSvr::SetMemoryThresholds(aLowRamThreshold,aGoodRamThreshold);
       
    78     if (iSwapUsageMonitored)
       
    79         {
       
    80         SVMSwapThresholds thresholds;
       
    81         thresholds.iLowThreshold = aLowSwapThreshold;
       
    82         thresholds.iGoodThreshold = aGoodSwapThreshold;
       
    83         UserSvr::HalFunction(EHalGroupVM, EVMHalSetSwapThresholds, &thresholds, 0);
       
    84         }
    77     User::LeaveIfError(iChangeNotifier.Create());
    85     User::LeaveIfError(iChangeNotifier.Create());
    78     }
    86     }
    79 
    87 
    80 void COutOfMemoryWatcher::UpdateThresholds(TInt aLowThreshold, TInt aGoodThreshold)
    88 void COutOfMemoryWatcher::UpdateThresholds(TInt aLowRamThreshold, TInt aGoodRamThreshold, TInt aLowSwapThreshold, TInt aGoodSwapThreshold)
    81     {
    89     {
    82     FUNC_LOG;
    90     FUNC_LOG;
    83 
    91 
    84     UserSvr::SetMemoryThresholds(aLowThreshold,aGoodThreshold);
    92     UserSvr::SetMemoryThresholds(aLowRamThreshold,aGoodRamThreshold);
       
    93     if (iSwapUsageMonitored)
       
    94         {
       
    95         SVMSwapThresholds thresholds;
       
    96         thresholds.iLowThreshold = aLowSwapThreshold;
       
    97         thresholds.iGoodThreshold = aGoodSwapThreshold;
       
    98         UserSvr::HalFunction(EHalGroupVM, EVMHalSetSwapThresholds, &thresholds, 0);
       
    99         }
    85     }
   100     }
    86 
   101 
    87 // ---------------------------------------------------------
   102 // ---------------------------------------------------------
    88 //
   103 //
    89 // ---------------------------------------------------------
   104 // ---------------------------------------------------------
   126         }
   141         }
   127 
   142 
   128     // Check for memory status change.
   143     // Check for memory status change.
   129     if (status & EChangesFreeMemory)
   144     if (status & EChangesFreeMemory)
   130         {
   145         {
   131         iLafShutdown.FreeMemThresholdCrossedL();
   146         iMemoryMonitor.FreeMemThresholdCrossedL();
   132         }
   147         }
   133 
   148 
   134     // We are not active until FreeMemThresholdCrossedL returns.
   149     // We are not active until FreeMemThresholdCrossedL returns.
   135     Start();
   150     Start();
   136     }
   151     }