Nokia N97 SDK
Example Applications Guide

MemoryRequester.cpp

00001 /*
00002  * ============================================================================
00003  *  Name        : MemoryRequester.cpp
00004  *  Part of     : OomMonitor Example Application
00005  *  Description : ?Description
00006  *  Version     : %version: 1 % << Don't touch! Updated by Synergy at check-out.
00007  *
00008  *  Copyright © 2009 Nokia.  All rights reserved.
00009  *  This material, including documentation and any related computer
00010  *  programs, is protected by copyright controlled by Nokia.  All
00011  *  rights are reserved.  Copying, including reproducing, storing,
00012  *  adapting or translating, any or all of this material requires the
00013  *  prior written consent of Nokia.  This material also contains
00014  *  confidential information which may not be disclosed to others
00015  *  without the prior written consent of Nokia.
00016  * ============================================================================
00017  * Template version: 4.2
00018  */
00019 
00020 #include <oommonitorclient.h>
00021 
00022 #include "MemoryRequester.h"
00023 
00024 _LIT(KOomMointorApp, "OomMonitorApp");
00025     
00026 enum TOoMonitorAppPanicCodes
00027     {
00028     ECRamRequesterStartCalledTwice
00029     };
00030 
00031 CMemoryRequester::CMemoryRequester(ROomMonitorSession& aOomMonitorSession,
00032         MMemoryRequesterObserver& aObserver)
00033 :       CActive(CActive::EPriorityStandard),
00034     iOomMonitorSession(aOomMonitorSession),
00035     iObserver(aObserver)
00036     {
00037     CActiveScheduler::Add(this);
00038     }
00039 
00040 CMemoryRequester::~CMemoryRequester()
00041     {
00042     Cancel();
00043     }
00044 
00045 CMemoryRequester* CMemoryRequester::NewL(ROomMonitorSession& aOomMonitorSession,
00046         MMemoryRequesterObserver& aObserver)
00047     {
00048     return new ( ELeave ) CMemoryRequester(aOomMonitorSession, aObserver);
00049     }
00050 
00051 void CMemoryRequester::Start(TInt aBytesRequested)
00052     {
00053     __ASSERT_ALWAYS(!IsActive(), User::Panic(KOomMointorApp, ECRamRequesterStartCalledTwice));
00054 
00055     // The asynchronous memory request to the OomMonitor
00056     iOomMonitorSession.RequestFreeMemory(aBytesRequested, iStatus);
00057     
00058     SetActive();
00059     }
00060 
00061 void CMemoryRequester::RunL()
00062     {
00063     // The memory request has been completed
00064     // The request status variable will return one of the system wide error codes
00065     // if the request has not completed successfully
00066     iObserver.MemoryRequestCompleteL(iStatus.Int());
00067     }
00068 
00069 void CMemoryRequester::DoCancel()
00070     {
00071     // The asynchronous memory request can be cancelled if no longer required
00072     iOomMonitorSession.CancelRequestFreeMemory();
00073     
00074     TRAP_IGNORE(iObserver.MemoryRequestCompleteL(KErrCancel));
00075     }

© Nokia 2009

Back to top