uiacceltk/hitchcock/goommonitor/src/goommonitorplugin.cpp
changeset 0 15bf7259bb7c
child 8 46927d61fef3
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006 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:  GOOM Monitor plug-in interface.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <apgwgnam.h>
       
    20 #include "goommonitorplugin.h"
       
    21 #include "goommemorymonitor.h"
       
    22 #include "goomtraces.h"
       
    23 
       
    24 // TLS is used to store the CMemoryMonitor pointer, CMemoryMonitor
       
    25 // being the main object in the GOOM monitor thread. This allows
       
    26 // plugins to access the CMemoryMonitor object easily.
       
    27 EXPORT_C void SetGMemoryMonitorTls(CMemoryMonitor* aMonitor)
       
    28     {
       
    29     FUNC_LOG;
       
    30 
       
    31     Dll::SetTls(aMonitor);
       
    32     }
       
    33 
       
    34 CMemoryMonitor* MemoryMonitorTls()
       
    35     {
       
    36     FUNC_LOG;
       
    37 
       
    38     return static_cast<CMemoryMonitor*>(Dll::Tls());
       
    39     }
       
    40 
       
    41 
       
    42 void GOomMonitorPluginPanic(TGOomMonitorPluginPanic aReason)
       
    43     {
       
    44     FUNC_LOG;
       
    45 
       
    46     _LIT(KCat, "GOomMonitorPlugin");
       
    47     User::Panic(KCat, aReason);
       
    48     }
       
    49 
       
    50 
       
    51 EXPORT_C CGOomMonitorPluginBase::CGOomMonitorPluginBase()
       
    52 : iMemoryMonitor(MemoryMonitorTls())
       
    53     {
       
    54     FUNC_LOG;
       
    55     RDebug::Print(_L("CGOomMonitorPluginBase::CGOomMonitorPluginBase"));
       
    56 
       
    57     __ASSERT_ALWAYS(iMemoryMonitor, GOomMonitorPluginPanic(EGOomMonitorPluginPanic_PluginConstructedOutsideGOomMonitorThread));
       
    58     RDebug::Print(_L("CGOomMonitorPluginBase::CGOomMonitorPluginBase EXIT"));
       
    59     }
       
    60 
       
    61 EXPORT_C CGOomMonitorPluginBase::~CGOomMonitorPluginBase()
       
    62     {
       
    63     FUNC_LOG;
       
    64     }
       
    65 
       
    66 EXPORT_C void CGOomMonitorPluginBase::ConstructL()
       
    67     {
       
    68     FUNC_LOG;
       
    69 
       
    70     // CAppGOomMonitorPlugin assumes ConstructL is empty
       
    71     }
       
    72 
       
    73 EXPORT_C void CGOomMonitorPluginBase::ExtensionInterface(TUid /*aInterfaceId*/, TAny*& /*aImplementaion*/)
       
    74     {
       
    75     FUNC_LOG;
       
    76     }
       
    77 
       
    78 EXPORT_C RFs& CGOomMonitorPluginBase::FsSession()
       
    79     {
       
    80     FUNC_LOG;
       
    81 
       
    82     return iMemoryMonitor->iFs;
       
    83     }
       
    84 
       
    85 EXPORT_C RWsSession& CGOomMonitorPluginBase::WsSession()
       
    86     {
       
    87     FUNC_LOG;
       
    88 
       
    89     return iMemoryMonitor->iWs;
       
    90     }
       
    91 
       
    92 EXPORT_C CAppGOomMonitorPlugin* CAppGOomMonitorPlugin::NewL(TUid aAppUid)
       
    93     {
       
    94     CAppGOomMonitorPlugin* self = new(ELeave) CAppGOomMonitorPlugin(aAppUid);
       
    95     // ConstructL() currently not needed
       
    96     return self;
       
    97     }
       
    98 
       
    99 CAppGOomMonitorPlugin::CAppGOomMonitorPlugin(TUid aAppUid)
       
   100 : iAppUid(aAppUid)
       
   101     {
       
   102     }
       
   103 
       
   104 void CAppGOomMonitorPlugin::FreeRam(TInt)
       
   105     {
       
   106     SendMessageToApp(KAppGOomMonitor_FreeRam);
       
   107     }
       
   108 
       
   109 void CAppGOomMonitorPlugin::MemoryGood()
       
   110     {
       
   111     SendMessageToApp(KAppGOomMonitor_MemoryGood);
       
   112     }
       
   113 
       
   114 void CAppGOomMonitorPlugin::SendMessageToApp(TInt aMessage)
       
   115     {
       
   116     RWsSession& ws = WsSession();
       
   117     TInt wgId = 0;
       
   118 
       
   119     do
       
   120         {
       
   121         CApaWindowGroupName::FindByAppUid(iAppUid, ws, wgId);
       
   122         if (wgId>0)
       
   123             {
       
   124             TWsEvent event;
       
   125             event.SetType(aMessage);
       
   126             event.SetTimeNow();
       
   127             ws.SendEventToWindowGroup(wgId, event);
       
   128             }
       
   129         }
       
   130     while (wgId>0);
       
   131     }