uiacceltk/hitchcock/goommonitor/src/goomcloseapp.cpp
changeset 38 69409653e863
parent 19 f5bac0badc7e
child 40 dd05fdd05078
equal deleted inserted replaced
32:27a3ad0677c1 38:69409653e863
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <apgtask.h>
    19 #include <apgtask.h>
    20 
    20 
       
    21 #include "goommemorymonitor.h"
       
    22 #include "goomwindowgrouplist.h"
    21 #include "goomcloseapp.h"
    23 #include "goomcloseapp.h"
    22 #include "goomtraces.h"
    24 #include "goomtraces.h"
    23 #include "goomappclosetimer.h"
    25 #include "goomappclosetimer.h"
    24 #include "goomappclosewatcher.h"
    26 #include "goomappclosewatcher.h"
    25 #include "goomactionref.h"
    27 #include "goomactionref.h"
    40 // Call the CGOomAction::MemoryFreed when it is done
    42 // Call the CGOomAction::MemoryFreed when it is done
    41 void CGOomCloseApp::FreeMemory(TInt, TBool)
    43 void CGOomCloseApp::FreeMemory(TInt, TBool)
    42     {
    44     {
    43     FUNC_LOG;
    45     FUNC_LOG;
    44 
    46 
       
    47     if ( iAlreadyGaveUp )	//will this ever be true ??? iAlredyGaveup is set true in closeAppEvent, which is called only if app gets notified by goom, which happens only after this
       
    48         {
       
    49         if (iAppCloseTimer)
       
    50         	{
       
    51 			iAppCloseTimer->Cancel();
       
    52     		}
       
    53 			
       
    54     	if (iAppCloseWatcher)
       
    55         	{
       
    56 			iAppCloseWatcher->Cancel();
       
    57 			}
       
    58 			
       
    59 		RDebug::Printf("GOOM: I should not activate actions for app that already refused to exit !!!!");
       
    60         MemoryFreed(KErrNone);
       
    61         return;
       
    62         }    
       
    63 
    45     iAppCloserRunning = ETrue;
    64     iAppCloserRunning = ETrue;
    46     
    65     
    47     // Set the TApaTask to the app
    66     // Set the TApaTask to the app
    48     iCurrentTask.SetWgId(iWgId);
    67     iCurrentTask.SetWgId(iWgId);
    49     
    68     
    50     // Start a timer and the thread watcher 
    69     // Start a timer and the thread watcher 
    51     iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppClosing);
    70     /*
       
    71 	iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppClosing);
    52     iAppCloseTimer->After(iCloseTimeout * 1000);
    72     iAppCloseTimer->After(iCloseTimeout * 1000);
    53     iAppCloseWatcher->Start(iCurrentTask);
    73     iAppCloseWatcher->Start(iCurrentTask);
    54     // Tell the app to close
    74     // Tell the app to close
    55     TRACES2("CGOomCloseApp::FreeMemory: Closing app with window group id %d Timeout = %d",iWgId, iCloseTimeout);
    75     TRACES2("CGOomCloseApp::FreeMemory: Closing app with window group id %d Timeout = %d",iWgId, iCloseTimeout);
    56     iCurrentTask.EndTask();
    76     iCurrentTask.EndTask();
       
    77 	*/
       
    78 	ConditionalClose();
    57     }
    79     }
    58 
    80 
    59 CGOomCloseApp::~CGOomCloseApp()
    81 CGOomCloseApp::~CGOomCloseApp()
    60     {
    82     {
    61     FUNC_LOG;
    83     FUNC_LOG;
    75     {
    97     {
    76     FUNC_LOG;
    98     FUNC_LOG;
    77 
    99 
    78     // The application has closed (or we have a timeout)
   100     // The application has closed (or we have a timeout)
    79     iAppCloserRunning = EFalse;
   101     iAppCloserRunning = EFalse;
       
   102     iAlreadyGaveUp = ETrue;
    80     
   103     
    81     if (iAppCloseTimer)
   104     if (iAppCloseTimer)
    82         {
   105         {
    83             iAppCloseTimer->Cancel();
   106         iAppCloseTimer->Cancel();
    84             iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppKilled);
   107         iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppKilled);
    85             iAppCloseTimer->After(iWaitAfterClose * 1000);
   108         iAppCloseTimer->After(iWaitAfterClose * 1000);
    86         }
   109         }
    87     
   110     
    88     if (iAppCloseWatcher)
   111     if (iAppCloseWatcher)
       
   112         {
    89         iAppCloseWatcher->Cancel(); 
   113         iAppCloseWatcher->Cancel(); 
    90     
   114         }    
    91     
       
    92     //MemoryFreed(KErrNone);
       
    93     }
   115     }
    94 
   116 
    95 void CGOomCloseApp::Reconfigure(const TActionRef& aRef)
   117 void CGOomCloseApp::Reconfigure(const TActionRef& aRef)
    96     {
   118     {
    97     FUNC_LOG;
   119     FUNC_LOG;
    98 
   120 
    99     iWgId = aRef.WgId();    
   121     iWgId = aRef.WgId();    
   100     iCloseTimeout = aRef.CloseTimeout();
   122     iCloseTimeout = aRef.CloseTimeout();
   101     iWaitAfterClose = aRef.WaitAfterClose();
   123     iWaitAfterClose = aRef.WaitAfterClose();
       
   124 	iAlreadyGaveUp = EFalse;
   102     }
   125     }
   103 
   126 
   104 void CGOomCloseApp::ConstructL()
   127 void CGOomCloseApp::ConstructL()
   105     {
   128     {
   106     FUNC_LOG;
   129     FUNC_LOG;
   112 CGOomCloseApp::CGOomCloseApp(MGOomActionObserver& aStateChangeObserver, RWsSession& aWs)
   135 CGOomCloseApp::CGOomCloseApp(MGOomActionObserver& aStateChangeObserver, RWsSession& aWs)
   113                                 : CGOomAction(aStateChangeObserver), iCurrentTask(aWs)
   136                                 : CGOomAction(aStateChangeObserver), iCurrentTask(aWs)
   114     {
   137     {
   115     FUNC_LOG;
   138     FUNC_LOG;
   116     }
   139     }
       
   140 
       
   141 TBool IsConsumingMemory(TInt aWgId)
       
   142     {
       
   143     FUNC_LOG;
       
   144     // Something more efficient could be done here
       
   145     CMemoryMonitor* globalMemoryMonitor = static_cast<CMemoryMonitor*>(Dll::Tls());
       
   146     globalMemoryMonitor->GetWindowGroupList()->Refresh();
       
   147     return (globalMemoryMonitor->GetWindowGroupList()->GetIndexFromWgId(aWgId) != KErrNotFound);
       
   148     }    
       
   149     
       
   150 void CGOomCloseApp::ConditionalClose()
       
   151     {
       
   152     FUNC_LOG;
       
   153     // Start a timer and the thread watcher 
       
   154     iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppClosing);
       
   155     iAppCloseTimer->After(iCloseTimeout * 1000);
       
   156     // Tell the app to close
       
   157 	// We are not asking system applications to exit anyway, so we'll send legacy event only
       
   158 	// even we have powermgmt capability 
       
   159     TRACES2("CGOomCloseApp::FreeMemory: Closing app with window group id %d Timeout = %d",iWgId, iCloseTimeout);
       
   160 	TWsEvent event;
       
   161 	event.SetType(EEventUser);
       
   162 	TInt* eventData = (TInt*)(event.EventData());
       
   163 	*eventData = EApaSystemEventShutdown;
       
   164 	eventData++;
       
   165 	*eventData = KGoomMemoryLowEvent;
       
   166 	
       
   167 	// should proxy the session..
       
   168     CMemoryMonitor* globalMemoryMonitor = static_cast<CMemoryMonitor*>(Dll::Tls());
       
   169     globalMemoryMonitor->iWs.SendEventToWindowGroup(iWgId, event);
       
   170     }    
       
   171 
   117 
   172 
   118 // ----------------------------------------------
   173 // ----------------------------------------------
   119 // Callback from iAppCloseTimer
   174 // Callback from iAppCloseTimer
   120 // App refused to exit gracefully on given time
   175 // App refused to exit gracefully on given time
   121 // ----------------------------------------------
   176 // ----------------------------------------------
   125     FUNC_LOG;
   180     FUNC_LOG;
   126     if (iAppCloseWatcher)
   181     if (iAppCloseWatcher)
   127         {
   182         {
   128         iAppCloseWatcher->Cancel(); 
   183         iAppCloseWatcher->Cancel(); 
   129         }
   184         }
   130     
   185         
   131     iCurrentTask.KillTask();
   186     if(IsConsumingMemory(iWgId))    
   132     iAppCloserRunning = EFalse;
   187         {    
   133     
   188         iCurrentTask.KillTask();
   134     iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppKilled);
   189         iAppCloserRunning = EFalse; // not sure if intended (?)
   135     iAppCloseTimer->After(iWaitAfterClose * 1000);
   190         iAppCloseTimer->SetState(CGOomAppCloseTimer::EGOomAppKilled);
       
   191         iAppCloseTimer->After(iWaitAfterClose * 1000);
       
   192         }
       
   193     else
       
   194         { // application has released its graphics resources -> we are no more interested about it
       
   195         CloseAppEvent();
       
   196         }    
   136     //MemoryFreed(KErrNone);
   197     //MemoryFreed(KErrNone);
   137     }
   198     }
   138 
   199 
   139 void CGOomCloseApp::KillTaskWaitDone()
   200 void CGOomCloseApp::KillTaskWaitDone()
   140     {
   201     {