uiacceltk/hitchcock/goommonitor/src/goomactionlist.cpp
changeset 38 69409653e863
parent 32 27a3ad0677c1
child 40 dd05fdd05078
child 48 7ced047fb7ae
equal deleted inserted replaced
32:27a3ad0677c1 38:69409653e863
   212 
   212 
   213 void CGOomActionList::BuildKillAppActionListL(CGOomWindowGroupList& aWindowGroupList, CGOomConfig& aConfig)
   213 void CGOomActionList::BuildKillAppActionListL(CGOomWindowGroupList& aWindowGroupList, CGOomConfig& aConfig)
   214     {
   214     {
   215     FUNC_LOG;
   215     FUNC_LOG;
   216     
   216     
   217 //    iActionRefs.Reset();
   217     // we can't reset action index here because plugins would miss memory good events
   218 //    iCurrentActionIndex = 0;
   218 
       
   219     iAppIndex = 0;
   219     
   220     
   220     aWindowGroupList.RefreshL(iTryOptional);
   221     aWindowGroupList.RefreshL(iTryOptional);
   221     
   222 /*    
   222     for (TInt i = 0; aWindowGroupList.LowOnMemWgs(i) != KErrNotFound ; i++ )
   223     for (TInt i = 0; aWindowGroupList.LowOnMemWgs(i) != KErrNotFound ; i++ )
   223         {
   224         {
   224         if ( iLowOnMemWgs.Find(aWindowGroupList.LowOnMemWgs(i)) == KErrNotFound)
   225         if ( iLowOnMemWgs.Find(aWindowGroupList.LowOnMemWgs(i)) == KErrNotFound)
   225             {
   226             {
   226             iLowOnMemWgs.Append(aWindowGroupList.LowOnMemWgs(i));    
   227             iLowOnMemWgs.Append(aWindowGroupList.LowOnMemWgs(i));    
   227             }
   228             }
   228         }
   229         }
   229         
   230 */        
   230     iRunningKillAppActions = ETrue;
   231     iRunningKillAppActions = ETrue;
   231     
   232     
   232     if (aWindowGroupList.Count())
   233     if (aWindowGroupList.Count())
   233             {
   234             {
   234             // Go through each item in the wglist, create an app close action for this application
   235             // Go through each item in the wglist, create an app close action for this application
   301     
   302     
   302                     //AppClose Actions should always have a unique prioirity determined by the application's z order.
   303                     //AppClose Actions should always have a unique prioirity determined by the application's z order.
   303                     TInt err = iActionRefs.InsertInOrder(ref, ComparePriorities);
   304                     TInt err = iActionRefs.InsertInOrder(ref, ComparePriorities);
   304                     if ((err != KErrNone) && (err != KErrAlreadyExists))
   305                     if ((err != KErrNone) && (err != KErrAlreadyExists))
   305                         {
   306                         {
       
   307                         TRACES3("BuildActionListL: Adding app to action list, Uid = %x, wgId = %d, err = %d", appId, wgId, err);
   306                         User::Leave(err);
   308                         User::Leave(err);
   307                         }
   309                         }
   308                     TRACES3("BuildActionListL: Adding app to action list, Uid = %x, wgId = %d, wgIndex = %d", appId, wgId, wgIndex);
   310                     TRACES3("BuildActionListL: Adding app to action list, Uid = %x, wgId = %d, wgIndex = %d", appId, wgId, wgIndex);
   309                     }
   311                     }
   310     
   312     
   350             continue;
   352             continue;
   351             }
   353             }
   352         
   354         
   353         TActionRef ref = iActionRefs[iCurrentActionIndex];
   355         TActionRef ref = iActionRefs[iCurrentActionIndex];
   354         CGOomAction* action = NULL;
   356         CGOomAction* action = NULL;
   355         if (ref.Type() == TActionRef::EAppClose)
   357         if (ref.Type() == TActionRef::EAppClose )
   356             {
   358             {     
   357             action = iCloseAppActions[numberOfRunningActions];
   359             iAppIndex%=iCloseAppActions.Count();
       
   360             TRACES2("Proceeding with app action from index %d, out of %d", iAppIndex, iCloseAppActions.Count() );
       
   361             action = iCloseAppActions[iAppIndex];
       
   362             iAppIndex++;
   358             static_cast<CGOomCloseApp*>(action)->Reconfigure(ref);
   363             static_cast<CGOomCloseApp*>(action)->Reconfigure(ref);
       
   364             
       
   365             ref.iAppPlugin = action;
   359             
   366             
   360             //Double checking again if this app is now in foreground, if yes then we dont kill
   367             //Double checking again if this app is now in foreground, if yes then we dont kill
   361             CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(iWs, iWs.GetFocusWindowGroup());
   368             CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(iWs, iWs.GetFocusWindowGroup());
   362             
   369             
   363             TInt32 fgApp = wgName->AppUid().iUid;
   370             TInt32 fgApp = wgName->AppUid().iUid;
   364             TInt32 appId = iMonitor.GetWindowGroupList()->AppIdfromWgId(ref.WgId(), ETrue);
   371             TInt32 appId = iMonitor.GetWindowGroupList()->AppIdfromWgId(ref.WgId(), ETrue);
   365             
   372                   
   366             
       
   367             if(appId == fgApp)
   373             if(appId == fgApp)
   368                 {
   374                 {
   369                 TRACES1("Foreground App wgid %x, spared by GOOM", appId);
   375                 TRACES1("Foreground App wgid %x, spared by GOOM", appId);
   370                 
   376                 
   371                 iCurrentActionIndex++;
   377                 iCurrentActionIndex++;
   400                 }
   406                 }
   401             CleanupStack::PopAndDestroy();
   407             CleanupStack::PopAndDestroy();
   402             if(spared)
   408             if(spared)
   403                 {
   409                 {
   404                 iCurrentActionIndex++;
   410                 iCurrentActionIndex++;
   405                 continue;
   411                 if (iCurrentActionIndex >= iActionRefs.Count())
       
   412                     {
       
   413                     StateChanged();
       
   414                     return;
       
   415                     }
       
   416                 else
       
   417                     {    
       
   418                     continue;
       
   419                     }
   406                 }
   420                 }
   407             }
   421             }
   408         else
   422         else
   409             {
   423             {
   410             action = &(ref.RunPlugin());
   424             action = &(ref.RunPlugin());
   469             }
   483             }
   470         else
   484         else
   471             {
   485             {
   472             iTryOptional = EFalse;
   486             iTryOptional = EFalse;
   473             iOptionalTried = EFalse;
   487             iOptionalTried = EFalse;
   474 
       
   475             TRACES("CGOomActionList::FreeMemory: No usable memory freeing action has been found");
   488             TRACES("CGOomActionList::FreeMemory: No usable memory freeing action has been found");
       
   489             iFreeingMemory = EFalse;
   476             iServer.CloseAppsFinished(freeMemory, EFalse);
   490             iServer.CloseAppsFinished(freeMemory, EFalse);
   477             iMonitor.WaitAndSynchroniseMemoryState();
   491             iMonitor.WaitAndSynchroniseMemoryState();
   478             }
   492             }
   479         }
   493         }
   480     }
   494     }
   482 // Should be called when the memory situation is good
   496 // Should be called when the memory situation is good
   483 // It results in notifications of the good memory state to all plugins with an outstanding FreeMemory request
   497 // It results in notifications of the good memory state to all plugins with an outstanding FreeMemory request
   484 void CGOomActionList::MemoryGood()
   498 void CGOomActionList::MemoryGood()
   485     {
   499     {
   486     FUNC_LOG;
   500     FUNC_LOG;
   487 
   501     if(!ALWAYS_SW_REND)
       
   502         {
   488     TInt actionRefIndex = iActionRefs.Count();
   503     TInt actionRefIndex = iActionRefs.Count();
   489 
   504 
   490     // Go through each of the action references, if it's a plugin action then call MemoryGood on it
   505     // Go through each of the action references, if it's a plugin action then call MemoryGood on it
   491     // Note that this only results in a call to the plugin if FreeMemory has been called on this plugin since that last call to MemoryGood
   506     // Note that this only results in a call to the plugin if FreeMemory has been called on this plugin since that last call to MemoryGood
   492     while (actionRefIndex--)
   507     while (actionRefIndex--)
   495                 || (iActionRefs[actionRefIndex].Type() == TActionRef::ESystemPlugin))
   510                 || (iActionRefs[actionRefIndex].Type() == TActionRef::ESystemPlugin))
   496             {
   511             {
   497             iActionRefs[actionRefIndex].RunPlugin().MemoryGood();
   512             iActionRefs[actionRefIndex].RunPlugin().MemoryGood();
   498             }
   513             }
   499         }
   514         }
   500     // notify window groups which were triggered to low mem that 
   515     // notify window groups which were triggered to low mem that
       
   516     iMonitor.SwitchMemMode(CMemoryMonitor::EGOomGoodMemMode);
       
   517         }
       
   518 /*    
   501     TWsEvent event;
   519     TWsEvent event;
   502     event.SetType(KGoomMemoryGoodEvent); // naive
   520     event.SetType(KGoomMemoryGoodEvent); // naive
   503 
   521 
   504     for (TInt i = iLowOnMemWgs.Count()-1; i>=0; i--)
   522     for (TInt i = iLowOnMemWgs.Count()-1; i>=0; i--)
   505         {
   523         {
   506 #ifdef SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS
   524 #ifdef SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS
   507         iWs.SendEventToWindowGroup(iLowOnMemWgs[i], event);
   525         iWs.SendEventToWindowGroup(iLowOnMemWgs[i], event);
   508 #endif // #ifdef SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS
   526 #endif // #ifdef SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS
   509         iLowOnMemWgs.Remove(i);
   527         iLowOnMemWgs.Remove(i);
   510 		}    
   528 		}
       
   529 */		    
   511     }
   530     }
   512 
   531 
   513 TBool CGOomActionList::FreeMemoryAboveTarget(TInt& aFreeMemory)
   532 TBool CGOomActionList::FreeMemoryAboveTarget(TInt& aFreeMemory)
   514     {
   533     {
   515     FUNC_LOG;
   534     FUNC_LOG;
   610 void CGOomActionList::AppNotExiting(TInt aWgId)
   629 void CGOomActionList::AppNotExiting(TInt aWgId)
   611     {
   630     {
   612     FUNC_LOG;
   631     FUNC_LOG;
   613 
   632 
   614     TInt index = iCloseAppActions.Count();
   633     TInt index = iCloseAppActions.Count();
       
   634     TRACES1("CGOomCloseApp::AppNotExiting: count of actions %d",index);
       
   635 
   615     while (index--)
   636     while (index--)
   616         {
   637         {
   617         CGOomCloseApp* action = iCloseAppActions[index];
   638         CGOomCloseApp* action = iCloseAppActions[index];
       
   639         TRACES3("CGOomCloseApp::AppNotExiting: %d %d %d", aWgId, action->WgId(), action->IsRunning());
       
   640         
   618         if ( (action->WgId() == aWgId) && (action->IsRunning()) )
   641         if ( (action->WgId() == aWgId) && (action->IsRunning()) )
   619             {
   642             {
   620             TRACES1("CGOomCloseApp::AppNotExiting: App with window group id %d has not responded to the close event", aWgId);
   643             TRACES1("CGOomCloseApp::AppNotExiting: App with window group id %d has not responded to the close event", aWgId);
   621             action->CloseAppEvent();
   644             action->CloseAppEvent();
   622             }
   645             }
   629     {
   652     {
   630     FUNC_LOG;
   653     FUNC_LOG;
   631 
   654 
   632     TBool allActionsComplete = ETrue;
   655     TBool allActionsComplete = ETrue;
   633 
   656 
   634     // Note that the actions themselves are responsible for timing out if necessary.
   657     TInt index = iActionRefs.Count();
   635     TInt index = iCloseAppActions.Count();
   658 	while ((index--) && (allActionsComplete))
   636     while ((index--) && (allActionsComplete))
   659         {
   637         {
   660         if (iActionRefs[index].IsRunning())
   638         if (iCloseAppActions[index]->IsRunning())
   661             {
   639             {
   662             TRACES1("CGOomActionList::StateChanged. Action %d STILL RUNNING.", index);
   640             TRACES1("CGOomActionList::StateChanged. CloseAppAction %d STILL RUNNING. PROBLEM !!! YOU SHOULD NEVER SEE THIS", index);
       
   641             allActionsComplete = EFalse;
       
   642             }
       
   643         }
       
   644 
       
   645     index = iRunPluginActions.Count();
       
   646     while ((index--) && (allActionsComplete))
       
   647         {
       
   648         if (iRunPluginActions[index]->IsRunning())
       
   649             {
       
   650             TRACES1("CGOomActionList::StateChanged. PluginAction %d STILL RUNNING. PROBLEM !!! YOU SHOULD NEVER SEE THIS", index);
       
   651             allActionsComplete = EFalse;
   663             allActionsComplete = EFalse;
   652             }
   664             }
   653         }
   665         }
   654 
   666 
   655     TRACES1("CGOomActionList::StateChanged. Current Target = %d", iCurrentTarget);
   667     TRACES1("CGOomActionList::StateChanged. Current Target = %d", iCurrentTarget);
   663         TRACES1("CGOomActionList::StateChanged. Free Memory = %d", freeMemory);
   675         TRACES1("CGOomActionList::StateChanged. Free Memory = %d", freeMemory);
   664         if (!freeMemoryAboveTarget)
   676         if (!freeMemoryAboveTarget)
   665             // If we are still below the good-memory-threshold then continue running actions
   677             // If we are still below the good-memory-threshold then continue running actions
   666             {            
   678             {            
   667             TRACES2("CGOomActionList::StateChanged: Finished Action %d out of %d",iCurrentActionIndex, iActionRefs.Count());
   679             TRACES2("CGOomActionList::StateChanged: Finished Action %d out of %d",iCurrentActionIndex, iActionRefs.Count());
   668             
   680 
   669             
   681             if (iCurrentActionIndex < iActionRefs.Count())
   670             if (iCurrentActionIndex >= iActionRefs.Count())
       
   671                 {
   682                 {
   672                 if(iRunningKillAppActions)
   683                 // There are still more actions to try, so we continue
       
   684                 TRACES1("CGOomActionList::StateChanged: All current actions complete, running more actions. freeMemory=%d", freeMemory);
       
   685                 return FreeMemory(iMaxPriority);
       
   686                 } 
       
   687                                    
       
   688             if(iRunningKillAppActions)
       
   689 	            {
       
   690                 iRunningKillAppActions = EFalse;
       
   691 
       
   692                 if (!iTryOptional && !iOptionalTried && freeMemory < 25*1024*1024 ) // magic, should read this from config
       
   693                     { 
       
   694                     iTryOptional = ETrue;
       
   695                     iOptionalTried = ETrue;
       
   696                     iMonitor.RunCloseAppActions(iMaxPriority);
       
   697                     }
       
   698                 else
   673                     {
   699                     {
   674                     iRunningKillAppActions = EFalse;
       
   675                     // There are no more actions to try, so we give up
   700                     // There are no more actions to try, so we give up
   676                     TRACES1("CGOomActionList::StateChanged: All current actions complete, below good threshold with no more actions available. freeMemory=%d", freeMemory);
   701                     TRACES1("CGOomActionList::StateChanged: All current actions complete, below good threshold with no more actions available. freeMemory=%d", freeMemory);
   677                     
   702                     iTryOptional = EFalse;       
   678                     /* Do not call memory good immidiately after freeing memory for some app
   703                     iServer.CloseAppsFinished(freeMemory, EFalse);
   679                     if (freeMemory >= iCurrentTarget && !iMonitor.NeedToPostponeMemGood())
   704                     iMonitor.WaitAndSynchroniseMemoryState();
   680                     {                    
   705                     }
   681                     MemoryGood();
       
   682                     }
       
   683                      */
       
   684                     if (!iTryOptional && !iOptionalTried && freeMemory < 25*1024*1024 ) // magic, should read this from config
       
   685                         { 
       
   686                         iTryOptional = ETrue;
       
   687                         iOptionalTried = EFalse;
       
   688                         iMonitor.RunCloseAppActions(iMaxPriority);
       
   689                         }
       
   690                     else
       
   691                         {
       
   692                         iTryOptional = EFalse;       
       
   693                         iServer.CloseAppsFinished(freeMemory, EFalse);
       
   694                         iMonitor.WaitAndSynchroniseMemoryState();
       
   695                         }
       
   696                     }
       
   697                 else
       
   698                     {
       
   699                     TRACES1("CGOomActionList::StateChanged: All current Plugin actions complete, below good threshold, Time to kill bad guys. freeMemory=%d", freeMemory);
       
   700                     iRunningKillAppActions = ETrue;
       
   701                     iMonitor.RunCloseAppActions(iMaxPriority);
       
   702                     }
       
   703                 
       
   704                 }
   706                 }
   705             else
   707             else
   706                 {
   708                 {
   707                 // There are still more actions to try, so we continue
   709                 TRACES1("CGOomActionList::StateChanged: All current Plugin actions complete, below good threshold, Time to kill bad guys. freeMemory=%d", freeMemory);
   708                 TRACES1("CGOomActionList::StateChanged: All current actions complete, running more actions. freeMemory=%d", freeMemory);
   710                 iRunningKillAppActions = ETrue;
   709                 FreeMemory(iMaxPriority);
   711                 iMonitor.RunCloseAppActions(iMaxPriority);
   710                 }
   712                 }
       
   713         
   711             }
   714             }
   712         else
   715         else
   713             {
   716             {
   714             TRACES1("CGOomActionList::StateChanged: All current actions complete, memory good. freeMemory=%d", freeMemory);
   717             TRACES1("CGOomActionList::StateChanged: All current actions complete, memory good. freeMemory=%d", freeMemory);
   715             /* Do not call memory good immidiately after freeing memory for some app
       
   716 			if(freeMemory > iMonitor.GetGoodThreshold() && !iMonitor.NeedToPostponeMemGood())
       
   717                 {
       
   718                 MemoryGood();
       
   719                 }
       
   720             */
       
   721             iRunningKillAppActions = EFalse;
   718             iRunningKillAppActions = EFalse;
   722             iServer.CloseAppsFinished(freeMemory, ETrue);
   719             iServer.CloseAppsFinished(freeMemory, ETrue);
   723             iMonitor.WaitAndSynchroniseMemoryState();
   720             iMonitor.WaitAndSynchroniseMemoryState();
   724             }
   721             }
   725         }
   722         }