sysresmonitoring/oommonitor/src/oommonitorplugin.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 19 Aug 2010 10:05:08 +0300
branchRCL_3
changeset 18 0818dd463d41
parent 2 7645e9ce10dc
child 19 924385140d98
permissions -rw-r--r--
Revision: 201031 Kit: 201033

/*
* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). 
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  OOM Monitor plug-in interface.
*
*/


#include <apgwgnam.h>
#include "oommonitorplugin.h"
#include "oommemorymonitor.h"
#include "OomTraces.h"

// TLS is used to store the CMemoryMonitor pointer, CMemoryMonitor
// being the main object in the OOM monitor thread. This allows
// plugins to access the CMemoryMonitor object easily.
EXPORT_C void SetMemoryMonitorTls(CMemoryMonitor* aMonitor)
    {
    FUNC_LOG;

    Dll::SetTls(aMonitor);
    }

CMemoryMonitor* MemoryMonitorTls()
    {
    FUNC_LOG;

    return static_cast<CMemoryMonitor*>(Dll::Tls());
    }


void OomMonitorPluginPanic(TOomMonitorPluginPanic aReason)
    {
    FUNC_LOG;

    _LIT(KCat, "OomMonitorPlugin");
    User::Panic(KCat, aReason);
    }


EXPORT_C COomMonitorPlugin::COomMonitorPlugin()
: iMemoryMonitor(MemoryMonitorTls())
    {
    FUNC_LOG;

    __ASSERT_ALWAYS(iMemoryMonitor, OomMonitorPluginPanic(EOomMonitorPluginPanic_PluginConstructedOutsideOomMonitorThread));
    }

EXPORT_C COomMonitorPlugin::~COomMonitorPlugin()
    {
    FUNC_LOG;
    }

EXPORT_C void COomMonitorPlugin::ConstructL()
    {
    FUNC_LOG;

    // CAppOomMonitorPlugin assumes ConstructL is empty
    }

EXPORT_C void COomMonitorPlugin::ExtensionInterface(TUid /*aInterfaceId*/, TAny*& /*aImplementaion*/)
    {
    FUNC_LOG;
    }

EXPORT_C RFs& COomMonitorPlugin::FsSession()
    {
    FUNC_LOG;

    return iMemoryMonitor->iFs;
    }

EXPORT_C RWsSession& COomMonitorPlugin::WsSession()
    {
    FUNC_LOG;

    return iMemoryMonitor->iWs;
    }

//-----------------------------------------------------------------------------
// Function: AppId
// Function returns the UID3 of the application which implements the 
// plugin
//-----------------------------------------------------------------------------
//
EXPORT_C const TUid COomMonitorPlugin::AppId() const
    {
    return KNullUid;
    }

EXPORT_C void COomMonitorPluginV2::FreeRam()
    {
    // Note that OomMonitorV2 will not call this version of the function
    // so it does not need to be implemented in derived classes.
    }



EXPORT_C CAppOomMonitorPlugin* CAppOomMonitorPlugin::NewL(TUid aAppUid)
    {
    CAppOomMonitorPlugin* self = new(ELeave) CAppOomMonitorPlugin(aAppUid);
    // ConstructL() currently not needed
    return self;
    }

CAppOomMonitorPlugin::CAppOomMonitorPlugin(TUid aAppUid)
: iAppUid(aAppUid)
    {
    }

void CAppOomMonitorPlugin::FreeRam()
    {
    SendMessageToApp(KAppOomMonitor_FreeRam);
    }

void CAppOomMonitorPlugin::MemoryGood()
    {
    SendMessageToApp(KAppOomMonitor_MemoryGood);
    }

void CAppOomMonitorPlugin::SendMessageToApp(TInt aMessage)
    {
    RWsSession& ws = WsSession();
    TInt wgId = 0;

    do 
        {
        CApaWindowGroupName::FindByAppUid(iAppUid, ws, wgId);
        if (wgId>0)
            {
            TWsEvent event;
            event.SetType(aMessage);
            event.SetTimeNow();
            ws.SendEventToWindowGroup(wgId, event);
            }
        }
    while (wgId>0);
    }

//-----------------------------------------------------------------------------
// Function: AppId
// Function returns the UID3 of the application which implements the 
// plugin
//-----------------------------------------------------------------------------
//
const TUid CAppOomMonitorPlugin::AppId() const
    {
    return iAppUid;
    }