harvester/server/src/harvesteroomao.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 19 Feb 2010 23:14:48 +0200
branchRCL_3
changeset 8 6752808b2036
parent 1 acef663c1218
child 9 04bdd8f58f0e
child 15 3cebc1a84278
permissions -rw-r--r--
Revision: 201003 Kit: 201007

/*
* Copyright (c) 2009 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:  Low memory observer for havester server
*
*/


#include "harvesteroomao.h"
#include "harvestercommon.h"

// ---------------------------------------------------------------------------
// NewL
// ---------------------------------------------------------------------------
//
CHarvesterOomAO* CHarvesterOomAO::NewL( MHarvesterOomObserver& aObserver )
	{
	CHarvesterOomAO* self = new (ELeave) CHarvesterOomAO( aObserver );
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop(self);
	return self;
	}

// ---------------------------------------------------------------------------
// CHarvesterOomAO
// ---------------------------------------------------------------------------
//
CHarvesterOomAO::CHarvesterOomAO( MHarvesterOomObserver& aObserver ) : 
		CActive( CActive::EPriorityUserInput )
	{
	iObserver = &aObserver;
	}


// ---------------------------------------------------------------------------
// ~CHarvesterOomAO
// ---------------------------------------------------------------------------
//
CHarvesterOomAO::~CHarvesterOomAO()
	{
    Cancel();
	iOomMsgQueue.Close();
	}

// ---------------------------------------------------------------------------
// ConstructL
// ---------------------------------------------------------------------------
//
void CHarvesterOomAO::ConstructL()
	{
	CActiveScheduler::Add( this);
	
	iOomMsgQueue.OpenGlobal( KHarvesterOomQueue );
	iOomMsgQueue.NotifyDataAvailable( iStatus );
	SetActive();
	}

// ---------------------------------------------------------------------------
// RunL
// ---------------------------------------------------------------------------
//
void CHarvesterOomAO::RunL()
	{
	User::LeaveIfError( iStatus.Int() );
	
	TInt oomStatus( 0 );
	const TInt err = iOomMsgQueue.Receive( oomStatus );
	
	if( oomStatus == TMdsOomFreeRam )
		{
		iObserver->MemoryLow();
		}
	else
		{
		iObserver->MemoryGood();
		}
	
	iOomMsgQueue.NotifyDataAvailable( iStatus );
	SetActive();
	}

// ---------------------------------------------------------------------------
// DoCancel
// ---------------------------------------------------------------------------
//
void CHarvesterOomAO::DoCancel()
	{
	iOomMsgQueue.CancelDataAvailable();
	}

// ---------------------------------------------------------------------------
// RunError
// ---------------------------------------------------------------------------
//
TInt CHarvesterOomAO::RunError( TInt /*aError*/ )
	{
	return KErrNone;
	}