View Full Version : Using RSystemAgent with TSysAgentEvent and RSAVarChangeNotify


amitaggarwal
18-11-2004, 11:09 AM
I m trying to monitor some system varibles like battery strength and network strength etc using the classes RSystemAgent, TSysAgentEvent and RSAVarChangeNotify.

This is the code i m writing ....


#include "CBatteryReader.h"

CBatteryReader::CBatteryReader(MBatteryObserver* aOb):CActive(0),iBatteryObserver(aOb)
{

}


CBatteryReader::~CBatteryReader()
{
//delete iBatteryObserver;
iSystemAgent.Close();
Cancel();
}

CBatteryReader* CBatteryReader::NewL(MBatteryObserver* aOb)
{
CBatteryReader* self = new(ELeave) CBatteryReader(aOb);
CleanupStack::PushL( self );
self->ConstructL();
CleanupStack::Pop();
return self;
}

void CBatteryReader::ConstructL()
{
User::LeaveIfError(iSystemAgent.Connect());
iSysAgentEvent.SetRequestStatus(iStatus);
iSysAgentEvent.SetUid(KUidBatteryStrength);
CActiveScheduler::Add( this );
}

TInt CBatteryReader::GetBatteryState()
{
//iSysAgentEvent.SetRequestStatus(iStatus);
//iSysAgentEvent.SetUid(KUidBatteryStrength);
iSystemAgent.NotifyOnEvent(iSysAgentEvent);
SetActive();

//return 0;//(iSystemAgent.GetState(KUidBatteryStrength));
}

void CBatteryReader::RunL()
{
TInt state = iSystemAgent.GetState(iSysAgentEvent.Uid());
// do what you want with state here
iBatteryObserver->OnBatteryChange(iSysAgentEvent.State());

//Reenable
//GetBatteryState();
}

void CBatteryReader::DoCancel()
{

}

TInt CBatteryReader::RunError( TInt aError )
{

}



but i receive a Panic Code 36 CONE
which says

Open handles were found during application shutdown
ANy clues ????