sysresmonitoring/oommonitor/tsrc/ut_oom_memorymonitor/src/mockoommemorymonitorsession.cpp
changeset 77 b01c07dfcf84
equal deleted inserted replaced
74:1505405bc645 77:b01c07dfcf84
       
     1 /*
       
     2 * Copyright (c) 2010 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 Out of Memory Monitor.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <oommonitorclientserver.h>
       
    19 #include <oommemorymonitorsession.h>
       
    20 #include <../../../inc/oommemorymonitor.h>
       
    21 #include <oommemorymonitorserver.h>
       
    22 #include <OomTraces.h>
       
    23 #include <oomclientrequestqueue.h>
       
    24 
       
    25 CMemoryMonitorSession::CMemoryMonitorSession()
       
    26     {
       
    27 
       
    28     }
       
    29 
       
    30 CMemoryMonitorSession::~CMemoryMonitorSession()
       
    31     {
       
    32 
       
    33     }
       
    34 
       
    35 CMemoryMonitorServer& CMemoryMonitorSession::Server()
       
    36     {
       
    37     return *static_cast<CMemoryMonitorServer*>(const_cast<CServer2*>(CSession2::Server()));
       
    38     }
       
    39 
       
    40 #ifdef CLIENT_REQUEST_QUEUE
       
    41 COomClientRequestQueue& CMemoryMonitorSession::ClientRequestQueue()
       
    42     {
       
    43     return Server().ClientRequestQueue();
       
    44     }
       
    45 #endif
       
    46 
       
    47 CMemoryMonitor& CMemoryMonitorSession::Monitor()
       
    48     {
       
    49 
       
    50 #ifdef CLIENT_REQUEST_QUEUE
       
    51     return ClientRequestQueue().Monitor();
       
    52 #else
       
    53     return Server().Monitor();    
       
    54 #endif
       
    55     }
       
    56 #ifndef CLIENT_REQUEST_QUEUE
       
    57 TBool CMemoryMonitorSession::IsDataPaged(const RMessage2& aMessage)
       
    58     {
       
    59     RThread clientThread;
       
    60     TInt err = aMessage.Client(clientThread);
       
    61     TBool dataPaged = EFalse;
       
    62     if(err == KErrNone)
       
    63         {
       
    64         RProcess processName;
       
    65         err = clientThread.Process(processName);
       
    66         if(err == KErrNone)
       
    67             {
       
    68             dataPaged = processName.DefaultDataPaged();
       
    69             }
       
    70         else
       
    71             {
       
    72             PanicClient(aMessage, EPanicIllegalFunction);
       
    73             }
       
    74         }
       
    75     else
       
    76         {
       
    77         PanicClient(aMessage, EPanicIllegalFunction);
       
    78         }
       
    79     return dataPaged;            
       
    80     }
       
    81 #endif
       
    82 
       
    83 void CMemoryMonitorSession::ServiceL(const RMessage2& aMessage)
       
    84     {
       
    85 
       
    86     }
       
    87 
       
    88 #ifndef CLIENT_REQUEST_QUEUE
       
    89 void CMemoryMonitorSession::CloseAppsFinished(TInt aBytesFree, TBool aMemoryGood)
       
    90     {
       
    91     FUNC_LOG;
       
    92 
       
    93     if (!iRequestFreeRam.IsNull())
       
    94         {
       
    95         if (iFunction == EOomMonitorRequestOptionalRam)
       
    96             {
       
    97             TInt memoryAvailable = aBytesFree - CMemoryMonitor::GlobalConfig().iGoodRamThreshold;
       
    98             
       
    99             // If memory available is greater than the requested RAM then complete with the amount of free memory, otherwise complete with KErrNoMemory
       
   100             if (memoryAvailable >= iMinimumMemoryRequested)
       
   101                 {
       
   102                 iRequestFreeRam.Complete(memoryAvailable);
       
   103                 }
       
   104             else
       
   105                 {
       
   106                 iRequestFreeRam.Complete(KErrNoMemory);
       
   107                 }
       
   108                }
       
   109         else 
       
   110             iRequestFreeRam.Complete(aMemoryGood ? KErrNone : KErrNoMemory);
       
   111         }
       
   112     }
       
   113 #endif