uiacceltk/hitchcock/goommonitor/src/goommemorymonitorsession.cpp
branchRCL_3
changeset 17 c9d868f1e20c
parent 15 cd0ae4656946
child 18 1801340c26a2
equal deleted inserted replaced
15:cd0ae4656946 17:c9d868f1e20c
    33     }
    33     }
    34 
    34 
    35 CMemoryMonitorSession::~CMemoryMonitorSession()
    35 CMemoryMonitorSession::~CMemoryMonitorSession()
    36     {
    36     {
    37     FUNC_LOG;
    37     FUNC_LOG;
    38     Server().Monitor().SessionInCriticalAllocation(0,iClientId);
    38     Server().Monitor().SessionInCriticalAllocation(0,0);
    39     CloseAppsFinished(0, EFalse);
    39     CloseAppsFinished(0, EFalse);
    40     }
    40     }
    41 
    41 
    42 CMemoryMonitorServer& CMemoryMonitorSession::Server()
    42 CMemoryMonitorServer& CMemoryMonitorSession::Server()
    43     {
    43     {
    59     
    59     
    60     iFunction = aMessage.Function();
    60     iFunction = aMessage.Function();
    61     RThread t;
    61     RThread t;
    62     aMessage.Client(t);
    62     aMessage.Client(t);
    63     
    63     
    64     iClientId = t.SecureId();
    64     TUint clientId = t.SecureId();
    65     t.Close();
    65     t.Close();
    66     
    66     
    67     TRACES1("NEW REQUEST from client %x", iClientId);
    67     TRACES1("NEW REQUEST from client %x", clientId);
    68     switch (aMessage.Function())
    68     switch (aMessage.Function())
    69         {
    69         {
    70         case EGOomMonitorRequestFreeMemory:
    70         case EGOomMonitorRequestFreeMemory:
    71 
    71 
    72             //Do not take any more requests from the same client if previous request being served
    72             //Do not take any more requests from the same client if previous request being served
    73             if (!iRequestFreeRam.IsNull() && !Server().Monitor().IsSafeToProcessNewRequest(iClientId))
    73             if (!iRequestFreeRam.IsNull() && !Server().Monitor().IsSafeToProcessNewRequest(clientId))
    74                 {
    74                 {
    75                 TRACES1("CANNOT PROCESS NEW REQUEST from %x", iClientId);
    75                 TRACES1("CANNOT PROCESS NEW REQUEST from %x", clientId);
    76                 aMessage.Complete(KErrInUse);
    76                 aMessage.Complete(KErrInUse);
    77                 return;
    77                 return;
    78                 }
    78                 }
    79             
    79             
    80             Server().Monitor().SetActiveClient(iClientId);
    80             Server().Monitor().SetActiveClient(clientId);
    81             // message will be completed when CloseAppsFinished() is called.
    81             // message will be completed when CloseAppsFinished() is called.
    82             if (aMessage.Int1() == 0)
    82             if (aMessage.Int1() == 0)
    83                 {
    83                 {
    84                 iRequestFreeRam = aMessage;
    84                 iRequestFreeRam = aMessage;
    85 
    85 
    86                 Server().Monitor().SessionInCriticalAllocation(1, iClientId);
    86                 Server().Monitor().SessionInCriticalAllocation(1, clientId);
    87                 
    87                 
    88                 TRAPD(err, Monitor().RequestFreeMemoryL(aMessage.Int0()));
    88                 TRAPD(err, Monitor().RequestFreeMemoryL(aMessage.Int0()));
    89                 if (err)
    89                 if(err == KErrCompletion) 
       
    90                     {
       
    91                     TRACES("There is already enough memory - nothing to do");
       
    92                     Server().Monitor().SessionInCriticalAllocation(0, clientId);
       
    93                     }
       
    94                 else if (err != KErrNone )
    90                     {
    95                     {
    91                     // completes the message if that was left to pending
    96                     // completes the message if that was left to pending
    92                     TRACES1("Error in RequestFreeMemory %d", err);
    97                     TRACES1("Error in RequestFreeMemory %d", err);
    93                     CloseAppsFinished(0, EFalse);
    98                     CloseAppsFinished(0, EFalse);
    94                     }
    99                     }
   101                 TRAP_IGNORE(Monitor().HandleFocusedWgChangeL(appUid));
   106                 TRAP_IGNORE(Monitor().HandleFocusedWgChangeL(appUid));
   102                 }
   107                 }
   103             break;
   108             break;
   104             
   109             
   105         case EGOomMonitorMemoryAllocationsComplete:
   110         case EGOomMonitorMemoryAllocationsComplete:
   106             TRACES1("ServiceL : Memory Allocations complete from %x", iClientId);
   111             TRACES1("ServiceL : Memory Allocations complete from %x", clientId);
   107             Server().Monitor().SessionInCriticalAllocation(0, iClientId);
   112             Server().Monitor().SessionInCriticalAllocation(0, clientId);
   108             aMessage.Complete(KErrNone);
   113             aMessage.Complete(KErrNone);
   109             break;
   114             break;
   110 
   115 
   111         case EGOomMonitorCancelRequestFreeMemory:
   116         case EGOomMonitorCancelRequestFreeMemory:
   112             if (!iRequestFreeRam.IsNull())
   117             if (!iRequestFreeRam.IsNull())
   113                 {
   118                 {
   114                 iRequestFreeRam.Complete(KErrCancel);
   119                 iRequestFreeRam.Complete(KErrCancel);
   115                 }
   120                 }
   116             Server().Monitor().SessionInCriticalAllocation(0, iClientId);
   121             Server().Monitor().SessionInCriticalAllocation(0, clientId);
   117             aMessage.Complete(KErrNone);
   122             aMessage.Complete(KErrNone);
   118             break;
   123             break;
   119 
   124 
   120         case EGOomMonitorThisAppIsNotExiting:
   125         case EGOomMonitorThisAppIsNotExiting:
   121             Monitor().AppNotExiting(aMessage.Int0());
   126             Monitor().AppNotExiting(aMessage.Int0());
   122             aMessage.Complete(KErrNone);
   127             aMessage.Complete(KErrNone);
   123             break;
   128             break;
   124 
   129 
   125         case EGOomMonitorRequestOptionalRam:
   130         case EGOomMonitorRequestOptionalRam:
   126             if (!iRequestFreeRam.IsNull() && !Server().Monitor().IsSafeToProcessNewRequest(iClientId))
   131             if (!iRequestFreeRam.IsNull() && !Server().Monitor().IsSafeToProcessNewRequest(clientId))
   127                 {
   132                 {
   128                 aMessage.Complete(KErrInUse);
   133                 aMessage.Complete(KErrInUse);
   129                 }
   134                 }
   130             Server().Monitor().SetActiveClient(iClientId);
   135             Server().Monitor().SetActiveClient(clientId);
   131             // message will be completed when CloseAppsFinished() is called.
   136             // message will be completed when CloseAppsFinished() is called.
   132             iRequestFreeRam = aMessage;
   137             iRequestFreeRam = aMessage;
   133             iMinimumMemoryRequested = aMessage.Int1();
   138             iMinimumMemoryRequested = aMessage.Int1();
   134             Monitor().FreeOptionalRamL(aMessage.Int0(), aMessage.Int2());
   139             Monitor().FreeOptionalRamL(aMessage.Int0(), aMessage.Int2());
   135             break;
   140             break;