sysresmonitoring/oommonitor/src/oomcloseapp.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 
       
    19 #include <apgtask.h>
       
    20 
       
    21 #include "oomcloseapp.h"
       
    22 #include "OomTraces.h"
       
    23 #include "oomappclosetimer.h"
       
    24 #include "oomappclosewatcher.h"
       
    25 #include "oomactionref.h"
       
    26 #include "oommemorymonitor.h"
       
    27 #include "oomconstants.hrh"
       
    28 #include "oompanic.h"
       
    29 
       
    30 COomCloseApp* COomCloseApp::NewL(MOomActionObserver& aStateChangeObserver, RWsSession& aWs)
       
    31     {
       
    32     FUNC_LOG;
       
    33 
       
    34     COomCloseApp* self = new (ELeave) COomCloseApp(aStateChangeObserver, aWs);
       
    35     CleanupStack::PushL(self);
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop(self);
       
    38     return self;
       
    39     }
       
    40 
       
    41 // Close the application in order to free memory
       
    42 // Call the COomAction::MemoryFreed when it is done
       
    43 void COomCloseApp::FreeMemory(TInt)
       
    44     {
       
    45     FUNC_LOG;
       
    46 
       
    47     iAppCloserRunning = ETrue;
       
    48     
       
    49     // Set the TApaTask to the app
       
    50     iCurrentTask.SetWgId(iWgId);
       
    51     
       
    52     __ASSERT_DEBUG(!iAppCloseTimer->IsActive(), OomMonitorPanic(KStartingActiveCloseAppTimer));    
       
    53     __ASSERT_DEBUG(!iAppCloseWatcher->IsActive(), OomMonitorPanic(KStartingActiveAppCloseWatcher));    
       
    54     // Start a timer and the thread watcher 
       
    55     iAppCloseTimer->After(CMemoryMonitor::GlobalConfig().iMaxAppExitTime * KMicrosecondsInMillisecond);
       
    56     iAppCloseWatcher->Start(iCurrentTask);
       
    57     // Tell the app to close
       
    58     TRACES1("COomCloseApp::FreeMemory: Closing app with window group id %d",iWgId);
       
    59     iCurrentTask.EndTask();
       
    60     }
       
    61 
       
    62 COomCloseApp::~COomCloseApp()
       
    63     {
       
    64     FUNC_LOG;
       
    65 
       
    66     if (iAppCloseTimer)
       
    67         iAppCloseTimer->Cancel();
       
    68     
       
    69     if (iAppCloseWatcher)
       
    70         iAppCloseWatcher->Cancel();
       
    71     
       
    72     delete iAppCloseTimer;    
       
    73     delete iAppCloseWatcher;
       
    74     }
       
    75 
       
    76 // Callback from COomAppCloseWatcher and COomAppCloseTimer
       
    77 void COomCloseApp::CloseAppEvent()
       
    78     {
       
    79     FUNC_LOG;
       
    80 
       
    81     // The application has closed (or we have a timeout)
       
    82     iAppCloserRunning = EFalse;
       
    83     
       
    84     if (iAppCloseTimer)
       
    85         iAppCloseTimer->Cancel();
       
    86     if (iAppCloseWatcher)
       
    87         iAppCloseWatcher->Cancel(); 
       
    88     
       
    89     MemoryFreed(KErrNone);
       
    90     }
       
    91 
       
    92 void COomCloseApp::Reconfigure(const TActionRef& aRef)
       
    93     {
       
    94     FUNC_LOG;
       
    95 
       
    96     iWgId = aRef.WgId();    
       
    97     }
       
    98 
       
    99 void COomCloseApp::ConstructL()
       
   100     {
       
   101     FUNC_LOG;
       
   102 
       
   103     iAppCloseTimer = COomAppCloseTimer::NewL(*this);
       
   104     iAppCloseWatcher = new(ELeave) COomAppCloseWatcher(*this);
       
   105     }
       
   106         
       
   107 COomCloseApp::COomCloseApp(MOomActionObserver& aStateChangeObserver, RWsSession& aWs)
       
   108                                 : COomAction(aStateChangeObserver), iCurrentTask(aWs)
       
   109     {
       
   110     FUNC_LOG;
       
   111     }