appsupport_plat/oom_monitor_api/inc/oommonitorsession.h
author Pat Downey <patd@symbian.org>
Wed, 01 Sep 2010 12:24:48 +0100
branchRCL_3
changeset 20 c2c61fdca848
parent 19 924385140d98
permissions -rw-r--r--
Revert incorrect RCL_3 drop: Revision: 201033 Kit: 201035

/*
* Copyright (c) 2006 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:  Client/server interface for OOM Monitor.
*
*/


#ifndef R_OOMMONITORSESSION_H
#define R_OOMMONITORSESSION_H

#include <e32std.h>

const TInt KOomMaxAllocationWithoutPermission = 1048576;
const TUid KOomMemoryMonitorStatusPropertyCategory = {0x10207218};
const TUint32 KOomMemoryMonitorStatusPropertyKey = 0;
enum TMemoryMonitorStatusPropertyValues
    {
    // Above Treshhold: Free Ram is above good treshhold point and memory monitor isn't freeing any memory
    EAboveTreshHold,
    
    // Freeing Memory: Memory monitor is in the middle of freeing memory
    EFreeingMemory,
    
    // Below Treshhold: Memory monitor has tried to free some RAM but total memory is still below treshhold and memory monitor has given up freeing more memory.
    EBelowTreshHold
    };
class ROomMonitorSession : public RSessionBase
    {
public:

    /**  Defines the application priorities of OOM monitor. */
    enum TOomPriority
        {
        /**
        * Application can be closed if needed.
        */
        EOomPriorityNormal = 0,

        /**
        * Application should not be closed if possible.
        */
        EOomPriorityHigh,

        /**
        * Application is busy and should not be closed.
        */
        EOomPriorityBusy
        };

public:
    /**
    * Connects a new session.
    * Sessions must be connected before any other APIs can be used.
    * When the client has finished using a session, Close() must be called.
    * @return KErrNone if successful, error code otherwise.
    */
    IMPORT_C TInt Connect();

    /**
    * Request that the OOM monitor attempts to free some memory.
    * This function may take several seconds to execute, depending on
    * the memory state. It will not return until the attempt to recover
    * memory has completed.
    * @param aBytesRequested The number of bytes of free memory that the client requests.
    * @return KErrNone if the request memory is free. KErrNoMemory if that
    *         amount of memory could not be recovered. Other error codes may
    *         also be returned.
    */
    IMPORT_C TInt RequestFreeMemory(TInt aBytesRequested);

    /**
    * Request that the OOM monitor attempts to free some memory.
    * This is an asynchronous version of the request for free memory.
    * @param aBytesRequested The number of bytes of free memory that the client requests.
    * @param aStatus will be completed when the attempt to recover memory
    *        has finished. This may take several seconds, depending on
    *        the memory state. On completion, aStatus will be set to 
    *        KErrNone if the request memory is free. KErrNoMemory if that
    *        amount of memory could not be recovered. Other error codes may
    *        also be set.
    */
    IMPORT_C void RequestFreeMemory(TInt aBytesRequested, TRequestStatus& aStatus);
    
    /**
    * Request that the OOM monitor attempts to free some memory for an optional allocation.
    * The passed in plugin ID is used to determine the priority for this allocation.
    * Lower priority OOM actions may be executed to free enough RAM for this allocation.
    * This function may take several seconds to execute, depending on
    * the memory state. It will not return until the attempt to recover
    * memory has completed.
    * @param aBytesRequested The number of bytes of free memory that the client requests.
    * @param aPluginId The ID of the plugin that may delete the allocation in event of low memory.
    * @return KErrNone if the request memory is free. KErrNoMemory if that
    *         amount of memory could not be recovered. Other error codes may
    *         also be returned.
    */
    IMPORT_C TInt RequestOptionalRam(TInt aBytesRequested, TInt aMinimumBytesNeeded, TInt aPluginId, TInt& aBytesAvailable);
    
    /**
    * Request that the OOM monitor attempts to free some memory for an optional allocation.
    * The passed in plugin ID is used to determine the priority for this allocation.
    * Lower priority OOM actions may be executed to free enough RAM for this allocation.
    * This function may take several seconds to execute, depending on
    * the memory state. It will not return until the attempt to recover
    * memory has completed.
    * @param aBytesRequested The number of bytes of free memory that the client requests.
    * @param aPluginId The ID of the plugin that may delete the allocation in event of low memory.
    * @param aStatus The TRequestStatus (completes with the number of bytes freed (aStatus >= 0) or an error (aStatus <= 0))
    * @return None
    */
    IMPORT_C void RequestOptionalRam(TInt aBytesRequested, TInt aMinimumBytesNeeded, TInt aPluginId, TRequestStatus& aStatus);

    /**
    * Cancels the asynchronous request for free memory.
    */
    IMPORT_C void CancelRequestFreeMemory();

    /**
    * Notify the OOM monitor that this application is not responding
    * to the EEikCmdExit request to exit the application.
    * This function is used by the Avkon framework's app shutter.
    * @param aWgId the window group identifier of the app that is not exiting.
    */
    IMPORT_C void ThisAppIsNotExiting(TInt aWgId);

    /**
    * Notify the OOM monitor that this application has the specified priority
    * @param aPriority the priority of the application
    */
    IMPORT_C void SetOomPriority(TOomPriority aPriority);
    
    };

#endif // R_OOMMONITORSESSION_H