uiacceltk/hitchcock/goommonitor/src/goommemorymonitorsession.cpp
changeset 0 15bf7259bb7c
child 3 d8a3531bc6b8
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Main classes for Graphics Out of Memory Monitor
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "goommonitorclientserver.h"
       
    20 #include "goommemorymonitorsession.h"
       
    21 #include "goommemorymonitor.h"
       
    22 #include "goommemorymonitorserver.h"
       
    23 #include "goomtraces.h"
       
    24 
       
    25 CMemoryMonitorSession::CMemoryMonitorSession()
       
    26     {
       
    27     FUNC_LOG;
       
    28     }
       
    29 
       
    30 void CMemoryMonitorSession::CreateL()
       
    31     {
       
    32     FUNC_LOG;
       
    33     }
       
    34 
       
    35 CMemoryMonitorSession::~CMemoryMonitorSession()
       
    36     {
       
    37     FUNC_LOG;
       
    38     if (iUseAbsoluteTargets)
       
    39         { // se3ssion terminated while on critical allocation, release lock
       
    40         Server().Monitor().SessionInCriticalAllocation(0);
       
    41         }
       
    42     CloseAppsFinished(0, EFalse);
       
    43     }
       
    44 
       
    45 CMemoryMonitorServer& CMemoryMonitorSession::Server()
       
    46     {
       
    47     FUNC_LOG;
       
    48 
       
    49     return *static_cast<CMemoryMonitorServer*>(const_cast<CServer2*>(CSession2::Server()));
       
    50     }
       
    51 
       
    52 CMemoryMonitor& CMemoryMonitorSession::Monitor()
       
    53     {
       
    54     FUNC_LOG;
       
    55 
       
    56     return Server().Monitor();
       
    57     }
       
    58 
       
    59 void CMemoryMonitorSession::ServiceL(const RMessage2& aMessage)
       
    60     {
       
    61     FUNC_LOG;
       
    62     
       
    63     iFunction = aMessage.Function();
       
    64     RThread t;
       
    65     aMessage.Client(t);
       
    66     Server().Monitor().SetActiveClient(t.SecureId());
       
    67     t.Close();
       
    68     
       
    69     switch (aMessage.Function())
       
    70         {
       
    71         case EGOomMonitorRequestFreeMemory:
       
    72             if (!iRequestFreeRam.IsNull())
       
    73                 {
       
    74                 aMessage.Complete(KErrInUse);
       
    75                 return;
       
    76                 }
       
    77             // message will be completed when CloseAppsFinished() is called.
       
    78             if (aMessage.Int1() == 0)
       
    79                 {
       
    80                 iRequestFreeRam = aMessage;
       
    81 
       
    82                 TRAPD(err, Monitor().RequestFreeMemoryL(aMessage.Int0(), iUseAbsoluteTargets));
       
    83                 if (err)
       
    84                     {
       
    85                     // completes the message if that was left to pending
       
    86                     CloseAppsFinished(0, EFalse);
       
    87                     }
       
    88                 }
       
    89             else
       
    90                 {
       
    91                 TInt appUid = aMessage.Int1();
       
    92                 // if no new memory was needed, the message is completed synchronously
       
    93                 iRequestFreeRam = aMessage;
       
    94                 TRAP_IGNORE(Monitor().HandleFocusedWgChangeL(appUid));
       
    95                 }
       
    96             break;
       
    97 
       
    98         case EGOomMonitorCancelRequestFreeMemory:
       
    99             if (!iRequestFreeRam.IsNull())
       
   100                 {
       
   101                 iRequestFreeRam.Complete(KErrCancel);
       
   102                 }
       
   103             aMessage.Complete(KErrNone);
       
   104             break;
       
   105 
       
   106         case EGOomMonitorThisAppIsNotExiting:
       
   107             Monitor().AppNotExiting(aMessage.Int0());
       
   108             aMessage.Complete(KErrNone);
       
   109             break;
       
   110 
       
   111         case EGOomMonitorRequestOptionalRam:
       
   112             if (!iRequestFreeRam.IsNull())
       
   113                 {
       
   114                 aMessage.Complete(KErrInUse);
       
   115                 }
       
   116             // message will be completed when CloseAppsFinished() is called.
       
   117             iRequestFreeRam = aMessage;
       
   118             iMinimumMemoryRequested = aMessage.Int1();
       
   119             Monitor().FreeOptionalRamL(aMessage.Int0(), aMessage.Int2(), iUseAbsoluteTargets);
       
   120             break;
       
   121             
       
   122         case EGOomMonitorSetPriorityBusy:
       
   123             Monitor().SetPriorityBusy(aMessage.Int0());
       
   124             aMessage.Complete(KErrNone);
       
   125             break;
       
   126             
       
   127         case EGOomMonitorSetPriorityNormal:
       
   128                Monitor().SetPriorityNormal(aMessage.Int0());
       
   129             aMessage.Complete(KErrNone);
       
   130             break;
       
   131 
       
   132         case EGOomMonitorSetPriorityHigh:
       
   133                Monitor().SetPriorityHigh(aMessage.Int0());
       
   134             aMessage.Complete(KErrNone);
       
   135             break;
       
   136 
       
   137         case EGoomMonitorAppAboutToStart:
       
   138             {
       
   139             TInt appUid = aMessage.Int0();
       
   140             aMessage.Complete(KErrNone);  
       
   141             TRAP_IGNORE(Monitor().HandleFocusedWgChangeL(appUid))
       
   142             break;
       
   143             }
       
   144         case EGoomMonitorAppUsesAbsoluteMemTargets:
       
   145             {
       
   146             iUseAbsoluteTargets = aMessage.Int0();
       
   147             TRACES2("EGoomMonitorAppUsesAbsoluteMemTargets this: 0x%x, use abs targets %d", this, iUseAbsoluteTargets);
       
   148             Server().Monitor().SessionInCriticalAllocation(iUseAbsoluteTargets);
       
   149             aMessage.Complete(KErrNone);     
       
   150             break;
       
   151             }    
       
   152             
       
   153         default:
       
   154             PanicClient(aMessage, EPanicIllegalFunction);
       
   155             break;
       
   156         }
       
   157     }
       
   158 
       
   159 void CMemoryMonitorSession::CloseAppsFinished(TInt aBytesFree, TBool aMemoryGood)
       
   160     {
       
   161     FUNC_LOG;
       
   162 
       
   163     if (!iRequestFreeRam.IsNull())
       
   164         {
       
   165         if (iFunction == EGOomMonitorRequestOptionalRam)
       
   166             {
       
   167             TInt memoryAvailable = aBytesFree - CMemoryMonitor::GlobalConfig().iGoodRamThreshold;
       
   168             
       
   169             // If memory available is greater than the requested RAM then complete with the amount of free memory, otherwise complete with KErrNoMemory
       
   170             if (memoryAvailable >= iMinimumMemoryRequested)
       
   171                 {
       
   172                 iRequestFreeRam.Complete(memoryAvailable);
       
   173                 }
       
   174             else
       
   175                 {
       
   176                 iRequestFreeRam.Complete(KErrNoMemory);
       
   177                 }
       
   178             }
       
   179         else 
       
   180             iRequestFreeRam.Complete(aMemoryGood ? KErrNone : KErrNoMemory);
       
   181         }
       
   182     Server().Monitor().SetActiveClient(0);
       
   183     }