sysresmonitoring/oommonitor/src/oomrunplugin.cpp
branchRCL_3
changeset 1 0fdb7f6b0309
child 18 0818dd463d41
equal deleted inserted replaced
0:2e3d3ce01487 1:0fdb7f6b0309
       
     1 /*
       
     2 * Copyright (c) 2006 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 OOM actions (e.g. closing applications and running plugins).
       
    15 *
       
    16 */
       
    17 
       
    18 #include "oomrunplugin.h"
       
    19 #include "OomTraces.h"
       
    20 #include "oommemorymonitor.h"
       
    21 #include "oommonitorplugin.h"
       
    22 #include "oompanic.h"
       
    23 
       
    24 COomRunPlugin* COomRunPlugin::NewL(TUint aPluginId, COomRunPluginConfig& aConfig, MOomActionObserver& aStateChangeObserver, COomMonitorPlugin& aPlugin, COomMonitorPluginV2* aV2Plugin)
       
    25     {
       
    26     FUNC_LOG;
       
    27 
       
    28     COomRunPlugin* self = new (ELeave) COomRunPlugin(aPluginId, aConfig, aStateChangeObserver, aPlugin, aV2Plugin);
       
    29     CleanupStack::PushL(self);
       
    30     self->ConstructL(aConfig);
       
    31     CleanupStack::Pop(self);
       
    32     return self;
       
    33     }
       
    34 
       
    35 // Run the OOM plugin in order to free memory
       
    36 // Call the COomAction::MemoryFreed when it is done
       
    37 void COomRunPlugin::FreeMemory(TInt aBytesRequested)
       
    38     {
       
    39     FUNC_LOG;
       
    40     TRACES1("COomRunPlugin::FreeMemory: iPluginId = %x", iPluginId);        
       
    41 
       
    42     // Ask the plugin to free some memory
       
    43 
       
    44     // Do we have a V2 plugin, if so then use it
       
    45     if (iV2Plugin)
       
    46         iV2Plugin->FreeRam(aBytesRequested);
       
    47     else
       
    48         // If we only have a V1 plugin then use that
       
    49         iPlugin.FreeRam();
       
    50     
       
    51     iFreeMemoryCalled = ETrue;
       
    52     
       
    53     // Wait for the required time before we signal completion.
       
    54     __ASSERT_DEBUG(!iPluginWaiter->IsActive(), OomMonitorPanic(KStartingActivePluginWaiter));    
       
    55     iPluginWaiter->Start();
       
    56     }
       
    57 
       
    58 // Call the memory good function on the plugin but...
       
    59 // only if there is an outstanding FreeMemory request
       
    60 void COomRunPlugin::MemoryGood()
       
    61     {
       
    62     FUNC_LOG;
       
    63 
       
    64     if (iFreeMemoryCalled)
       
    65         {
       
    66         iPlugin.MemoryGood();
       
    67         iFreeMemoryCalled = EFalse;
       
    68         }
       
    69     }
       
    70 
       
    71 COomRunPlugin::~COomRunPlugin()
       
    72     {
       
    73     FUNC_LOG;
       
    74 
       
    75     delete iPluginWaiter;
       
    76     }
       
    77 
       
    78 COomRunPlugin::COomRunPlugin(TUint aPluginId, COomRunPluginConfig& aConfig, MOomActionObserver& aStateChangeObserver, COomMonitorPlugin& aPlugin, COomMonitorPluginV2* aV2Plugin) : COomAction(aStateChangeObserver), iPluginId(aPluginId), iPlugin(aPlugin), iConfig(aConfig), iV2Plugin(aV2Plugin)
       
    79     {
       
    80     FUNC_LOG;
       
    81     }
       
    82 
       
    83 void COomRunPlugin::ConstructL(COomRunPluginConfig& aPluginConfig)
       
    84     {
       
    85     FUNC_LOG;
       
    86 
       
    87     TInt waitDuration = CMemoryMonitor::GlobalConfig().iDefaultWaitAfterPlugin;
       
    88     
       
    89     if (aPluginConfig.WaitAfterPluginDefined())
       
    90         {
       
    91         // If the wait duration for this plugin is overridden then use the overridden value
       
    92         waitDuration = aPluginConfig.WaitAfterPlugin();
       
    93         }
       
    94     
       
    95     iPluginWaiter = COomPluginWaiter::NewL(waitDuration, *this);
       
    96     }