uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp
changeset 38 69409653e863
parent 32 27a3ad0677c1
child 40 dd05fdd05078
child 48 7ced047fb7ae
--- a/uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp	Wed Jun 09 11:48:49 2010 +0300
+++ b/uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp	Tue Jun 22 12:40:35 2010 +0300
@@ -214,11 +214,12 @@
     {
     FUNC_LOG;
     
-//    iActionRefs.Reset();
-//    iCurrentActionIndex = 0;
+    // we can't reset action index here because plugins would miss memory good events
+
+    iAppIndex = 0;
     
     aWindowGroupList.RefreshL(iTryOptional);
-    
+/*    
     for (TInt i = 0; aWindowGroupList.LowOnMemWgs(i) != KErrNotFound ; i++ )
         {
         if ( iLowOnMemWgs.Find(aWindowGroupList.LowOnMemWgs(i)) == KErrNotFound)
@@ -226,7 +227,7 @@
             iLowOnMemWgs.Append(aWindowGroupList.LowOnMemWgs(i));    
             }
         }
-        
+*/        
     iRunningKillAppActions = ETrue;
     
     if (aWindowGroupList.Count())
@@ -303,6 +304,7 @@
                     TInt err = iActionRefs.InsertInOrder(ref, ComparePriorities);
                     if ((err != KErrNone) && (err != KErrAlreadyExists))
                         {
+                        TRACES3("BuildActionListL: Adding app to action list, Uid = %x, wgId = %d, err = %d", appId, wgId, err);
                         User::Leave(err);
                         }
                     TRACES3("BuildActionListL: Adding app to action list, Uid = %x, wgId = %d, wgIndex = %d", appId, wgId, wgIndex);
@@ -352,18 +354,22 @@
         
         TActionRef ref = iActionRefs[iCurrentActionIndex];
         CGOomAction* action = NULL;
-        if (ref.Type() == TActionRef::EAppClose)
-            {
-            action = iCloseAppActions[numberOfRunningActions];
+        if (ref.Type() == TActionRef::EAppClose )
+            {     
+            iAppIndex%=iCloseAppActions.Count();
+            TRACES2("Proceeding with app action from index %d, out of %d", iAppIndex, iCloseAppActions.Count() );
+            action = iCloseAppActions[iAppIndex];
+            iAppIndex++;
             static_cast<CGOomCloseApp*>(action)->Reconfigure(ref);
             
+            ref.iAppPlugin = action;
+            
             //Double checking again if this app is now in foreground, if yes then we dont kill
             CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(iWs, iWs.GetFocusWindowGroup());
             
             TInt32 fgApp = wgName->AppUid().iUid;
             TInt32 appId = iMonitor.GetWindowGroupList()->AppIdfromWgId(ref.WgId(), ETrue);
-            
-            
+                  
             if(appId == fgApp)
                 {
                 TRACES1("Foreground App wgid %x, spared by GOOM", appId);
@@ -402,7 +408,15 @@
             if(spared)
                 {
                 iCurrentActionIndex++;
-                continue;
+                if (iCurrentActionIndex >= iActionRefs.Count())
+                    {
+                    StateChanged();
+                    return;
+                    }
+                else
+                    {    
+                    continue;
+                    }
                 }
             }
         else
@@ -471,8 +485,8 @@
             {
             iTryOptional = EFalse;
             iOptionalTried = EFalse;
-
             TRACES("CGOomActionList::FreeMemory: No usable memory freeing action has been found");
+            iFreeingMemory = EFalse;
             iServer.CloseAppsFinished(freeMemory, EFalse);
             iMonitor.WaitAndSynchroniseMemoryState();
             }
@@ -484,7 +498,8 @@
 void CGOomActionList::MemoryGood()
     {
     FUNC_LOG;
-
+    if(!ALWAYS_SW_REND)
+        {
     TInt actionRefIndex = iActionRefs.Count();
 
     // Go through each of the action references, if it's a plugin action then call MemoryGood on it
@@ -497,7 +512,10 @@
             iActionRefs[actionRefIndex].RunPlugin().MemoryGood();
             }
         }
-    // notify window groups which were triggered to low mem that 
+    // notify window groups which were triggered to low mem that
+    iMonitor.SwitchMemMode(CMemoryMonitor::EGOomGoodMemMode);
+        }
+/*    
     TWsEvent event;
     event.SetType(KGoomMemoryGoodEvent); // naive
 
@@ -507,7 +525,8 @@
         iWs.SendEventToWindowGroup(iLowOnMemWgs[i], event);
 #endif // #ifdef SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS
         iLowOnMemWgs.Remove(i);
-		}    
+		}
+*/		    
     }
 
 TBool CGOomActionList::FreeMemoryAboveTarget(TInt& aFreeMemory)
@@ -612,9 +631,13 @@
     FUNC_LOG;
 
     TInt index = iCloseAppActions.Count();
+    TRACES1("CGOomCloseApp::AppNotExiting: count of actions %d",index);
+
     while (index--)
         {
         CGOomCloseApp* action = iCloseAppActions[index];
+        TRACES3("CGOomCloseApp::AppNotExiting: %d %d %d", aWgId, action->WgId(), action->IsRunning());
+        
         if ( (action->WgId() == aWgId) && (action->IsRunning()) )
             {
             TRACES1("CGOomCloseApp::AppNotExiting: App with window group id %d has not responded to the close event", aWgId);
@@ -631,23 +654,12 @@
 
     TBool allActionsComplete = ETrue;
 
-    // Note that the actions themselves are responsible for timing out if necessary.
-    TInt index = iCloseAppActions.Count();
-    while ((index--) && (allActionsComplete))
+    TInt index = iActionRefs.Count();
+	while ((index--) && (allActionsComplete))
         {
-        if (iCloseAppActions[index]->IsRunning())
+        if (iActionRefs[index].IsRunning())
             {
-            TRACES1("CGOomActionList::StateChanged. CloseAppAction %d STILL RUNNING. PROBLEM !!! YOU SHOULD NEVER SEE THIS", index);
-            allActionsComplete = EFalse;
-            }
-        }
-
-    index = iRunPluginActions.Count();
-    while ((index--) && (allActionsComplete))
-        {
-        if (iRunPluginActions[index]->IsRunning())
-            {
-            TRACES1("CGOomActionList::StateChanged. PluginAction %d STILL RUNNING. PROBLEM !!! YOU SHOULD NEVER SEE THIS", index);
+            TRACES1("CGOomActionList::StateChanged. Action %d STILL RUNNING.", index);
             allActionsComplete = EFalse;
             }
         }
@@ -665,59 +677,44 @@
             // If we are still below the good-memory-threshold then continue running actions
             {            
             TRACES2("CGOomActionList::StateChanged: Finished Action %d out of %d",iCurrentActionIndex, iActionRefs.Count());
-            
-            
-            if (iCurrentActionIndex >= iActionRefs.Count())
+
+            if (iCurrentActionIndex < iActionRefs.Count())
                 {
-                if(iRunningKillAppActions)
-                    {
-                    iRunningKillAppActions = EFalse;
-                    // There are no more actions to try, so we give up
-                    TRACES1("CGOomActionList::StateChanged: All current actions complete, below good threshold with no more actions available. freeMemory=%d", freeMemory);
-                    
-                    /* Do not call memory good immidiately after freeing memory for some app
-                    if (freeMemory >= iCurrentTarget && !iMonitor.NeedToPostponeMemGood())
-                    {                    
-                    MemoryGood();
-                    }
-                     */
-                    if (!iTryOptional && !iOptionalTried && freeMemory < 25*1024*1024 ) // magic, should read this from config
-                        { 
-                        iTryOptional = ETrue;
-                        iOptionalTried = EFalse;
-                        iMonitor.RunCloseAppActions(iMaxPriority);
-                        }
-                    else
-                        {
-                        iTryOptional = EFalse;       
-                        iServer.CloseAppsFinished(freeMemory, EFalse);
-                        iMonitor.WaitAndSynchroniseMemoryState();
-                        }
+                // There are still more actions to try, so we continue
+                TRACES1("CGOomActionList::StateChanged: All current actions complete, running more actions. freeMemory=%d", freeMemory);
+                return FreeMemory(iMaxPriority);
+                } 
+                                   
+            if(iRunningKillAppActions)
+	            {
+                iRunningKillAppActions = EFalse;
+
+                if (!iTryOptional && !iOptionalTried && freeMemory < 25*1024*1024 ) // magic, should read this from config
+                    { 
+                    iTryOptional = ETrue;
+                    iOptionalTried = ETrue;
+                    iMonitor.RunCloseAppActions(iMaxPriority);
                     }
                 else
                     {
-                    TRACES1("CGOomActionList::StateChanged: All current Plugin actions complete, below good threshold, Time to kill bad guys. freeMemory=%d", freeMemory);
-                    iRunningKillAppActions = ETrue;
-                    iMonitor.RunCloseAppActions(iMaxPriority);
+                    // There are no more actions to try, so we give up
+                    TRACES1("CGOomActionList::StateChanged: All current actions complete, below good threshold with no more actions available. freeMemory=%d", freeMemory);
+                    iTryOptional = EFalse;       
+                    iServer.CloseAppsFinished(freeMemory, EFalse);
+                    iMonitor.WaitAndSynchroniseMemoryState();
                     }
-                
                 }
             else
                 {
-                // There are still more actions to try, so we continue
-                TRACES1("CGOomActionList::StateChanged: All current actions complete, running more actions. freeMemory=%d", freeMemory);
-                FreeMemory(iMaxPriority);
+                TRACES1("CGOomActionList::StateChanged: All current Plugin actions complete, below good threshold, Time to kill bad guys. freeMemory=%d", freeMemory);
+                iRunningKillAppActions = ETrue;
+                iMonitor.RunCloseAppActions(iMaxPriority);
                 }
+        
             }
         else
             {
             TRACES1("CGOomActionList::StateChanged: All current actions complete, memory good. freeMemory=%d", freeMemory);
-            /* Do not call memory good immidiately after freeing memory for some app
-			if(freeMemory > iMonitor.GetGoodThreshold() && !iMonitor.NeedToPostponeMemGood())
-                {
-                MemoryGood();
-                }
-            */
             iRunningKillAppActions = EFalse;
             iServer.CloseAppsFinished(freeMemory, ETrue);
             iMonitor.WaitAndSynchroniseMemoryState();