skins/AknSkins/oomplugin/aknskinsoomplugin.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 16 Apr 2010 16:01:57 +0300
changeset 43 1951b3078691
parent 0 05e9090e2422
child 54 08459e712984
permissions -rw-r--r--
Revision: 201011 Kit: 201015

/*
* Copyright (c) 2007-2008 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 plugin for skin server.
*
*/

#include <ecom/ecom.h>
#include <ecom/implementationproxy.h>
#include <oommonitorplugin.h>
#include <AknsSrvClient.h>
#include <w32std.h>

class CAknSkinsOomMonitorPlugin : public COomMonitorPlugin
    {
public:
    CAknSkinsOomMonitorPlugin();
    ~CAknSkinsOomMonitorPlugin();
    void ConstructL();

public:
    void FreeRam();
    void MemoryGood();

private:
    RAknsSrvSession iSkinSrvSession;
    };

// -----------------------------------------------------------------------------
// C++ constructor.
// -----------------------------------------------------------------------------
//
CAknSkinsOomMonitorPlugin::CAknSkinsOomMonitorPlugin()
    {
    }

// -----------------------------------------------------------------------------
// Destructor.
// -----------------------------------------------------------------------------
//
CAknSkinsOomMonitorPlugin::~CAknSkinsOomMonitorPlugin()
    {
    iSkinSrvSession.Close();
    }

// -----------------------------------------------------------------------------
// Symbian two-phased constructor (2nd phase).
// -----------------------------------------------------------------------------
//
void CAknSkinsOomMonitorPlugin::ConstructL()
    {
    COomMonitorPlugin::ConstructL();
    User::LeaveIfError( iSkinSrvSession.Connect() );
    }

// -----------------------------------------------------------------------------
// Gets display type.
// -----------------------------------------------------------------------------
//
TAknsSrcScreenMode GetDisplayTypeL(RWsSession& aSession)
    {
    CWsScreenDevice* sc = new (ELeave) CWsScreenDevice(aSession);
    CleanupStack::PushL(sc);
    sc->Construct();
    TSize screensize(0,0);
    screensize = sc->SizeInPixels();
    CleanupStack::PopAndDestroy();// screendevice
    if (screensize.iWidth > screensize.iHeight)
        {
        return EAknsSrvScrModeLandscape;
        }
    else if (screensize.iWidth < screensize.iHeight)
        {
        return EAknsSrvScrModePortrait;
        }
    else // square
        {
        return EAknsSrvScrModeSquare;
        }
    }

// -----------------------------------------------------------------------------
// Tries to free RAM.
// -----------------------------------------------------------------------------
//
void CAknSkinsOomMonitorPlugin::FreeRam()
    {
    TInt err(KErrNone);
    TAknsSrcScreenMode mode = EAknsSrvScrModeSquare;
    TRAP(err, mode = GetDisplayTypeL(WsSession()));
    if (mode != EAknsSrvScrModeSquare)
        {
#if defined(_DEBUG)
        RDebug::Print(_L("CAknSkinsOomMonitorPlugin: Starting to free memory, mode %d"), mode);
#endif
        iSkinSrvSession.FreeUnnecessaryLayoutBitmaps(mode);
        }
    }

// -----------------------------------------------------------------------------
// CAknSkinsOomMonitorPlugin::MemoryGood
// -----------------------------------------------------------------------------
//
void CAknSkinsOomMonitorPlugin::MemoryGood()
    {
    }

// -----------------------------------------------------------------------------
// Creates plugin.
// -----------------------------------------------------------------------------
//
TAny* CreatePlugin()
    {
    CAknSkinsOomMonitorPlugin* plugin = new(ELeave) CAknSkinsOomMonitorPlugin;
    CleanupStack::PushL(plugin);
    plugin->ConstructL();
    CleanupStack::Pop(plugin);
    return plugin;
    }

// -----------------------------------------------------------------------------
// Implementation table for plugin.
// -----------------------------------------------------------------------------
//
const TImplementationProxy ImplementationTable[] =
    {
    {{0x10207140}, ::CreatePlugin}
    };

// -----------------------------------------------------------------------------
// ImplementationGroupProxy
// -----------------------------------------------------------------------------
//
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
    {
    aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy) ;
    return ImplementationTable;
    }

// End of file