📄 statevarobserver_3rd.cpp
字号:
/**
*
* Definition of CStateVarObserver
*
* Copyright (c) 2004 Nokia Corporation
* version 2.0
*/
// INCLUDE FILES
// User includes
#include "StateVarObserver.h"
#include "PowerResManContainer.h"
#include <etel3rdparty.h>
#include <sacls.h>
#include <aknglobalnote.h>
// Creates instance of CStateVarObserver
CStateVarObserver* CStateVarObserver::NewL(TUid aUid, CPowerResManContainer& aAppContainer,
CTelephony &aTelephony)
{
CStateVarObserver* self = NewLC(aUid, aAppContainer, aTelephony);
CleanupStack::Pop(self);
return self;
}
// Creates instance of CStateVarObserver and leaves it on the cleanup stack
CStateVarObserver* CStateVarObserver::NewLC(TUid aUid, CPowerResManContainer& aAppContainer,
CTelephony &aTelephony)
{
CStateVarObserver* self = new (ELeave) CStateVarObserver(aUid, aAppContainer, aTelephony);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
// Constructor
CStateVarObserver::CStateVarObserver(TUid aUid, CPowerResManContainer& aAppContainer,
CTelephony &aTelephony) : CActive(EPriorityStandard),
iAppContainer(aAppContainer),
iSigStrengthV1Pckg(iSigStrengthV1),
iBatteryInfoV1Pckg(iBatteryInfoV1),
iIndicatorV1Pckg(iIndicatorV1),
iTelephony(aTelephony),
iObservingUid(aUid)
{
//nothing to do
}
// Destructor
CStateVarObserver::~CStateVarObserver()
{
// Make sure this active object is cancelled and close connection to the System Agent
Cancel();
}
// 2nd phase constructor
void CStateVarObserver::ConstructL()
{
// Add this active object to the active scheduler
CActiveScheduler::Add(this);
}
// Called when the monitoring of the variable should begin
void CStateVarObserver::StartL()
{
if ( iObservingUid == KUidNetworkStrength )
{
iTelephony.GetSignalStrength(iStatus, iSigStrengthV1Pckg);
}
else if ( iObservingUid == KUidBatteryBars )
{
iTelephony.GetBatteryInfo(iStatus,iBatteryInfoV1Pckg);
}
else if ( iObservingUid == KUidChargerStatus )
{
iTelephony.GetIndicator(iStatus, iIndicatorV1Pckg);
}
else
{
User::Leave(KErrNotSupported);
}
SetActive();
}
// Handles request completion - called by the Active Scheduler
void CStateVarObserver::RunL()
{
if( iStatus.Int() != KErrNone )
{
//TODO error handling
return;
}
//Read once, now register to observe changes
if ( iObservingUid == KUidNetworkStrength )
{
iSignal = iSigStrengthV1.iBar;
iObservedValue = iSignal;
iTelephony.NotifyChange(iStatus,CTelephony::ESignalStrengthChange,
iSigStrengthV1Pckg);
}
else if ( iObservingUid == KUidBatteryBars )
{
iBattery = iBatteryInfoV1.iChargeLevel;
iObservedValue = iBattery;
iTelephony.NotifyChange(iStatus,CTelephony::EBatteryInfoChange,
iBatteryInfoV1Pckg);
}
else if ( iObservingUid == KUidChargerStatus )
{
//this same technique can be used to see if there's
//network available (with KIndNetworkAvailable)
//and if there's a call in progress (KIndCallInProgress)
if(iIndicatorV1.iIndicator & CTelephony::KIndChargerConnected)
{
iCharger = 1;
}
else
{
iCharger = 0;
}
iObservedValue = iCharger;
iTelephony.NotifyChange(iStatus,CTelephony::EIndicatorChange,
iIndicatorV1Pckg);
}
else
{
//TODO error handling
}
ProcessCurrentStateL();
SetActive();
}
// Cancel outstanding request - called by Cancel()
void CStateVarObserver::DoCancel()
{
if ( iObservingUid == KUidNetworkStrength )
{
iTelephony.CancelAsync(CTelephony::EGetSignalStrengthCancel);
iTelephony.CancelAsync(CTelephony::ESignalStrengthChangeCancel);
}
else if ( iObservingUid == KUidBatteryBars )
{
iTelephony.CancelAsync(CTelephony::EGetBatteryInfoCancel);
iTelephony.CancelAsync(CTelephony::EBatteryInfoChangeCancel);
}
else if ( iObservingUid == KUidChargerStatus )
{
iTelephony.CancelAsync(CTelephony::EGetIndicatorCancel);
iTelephony.CancelAsync(CTelephony::EIndicatorChangeCancel);
}
}
// Gets the current value of the state variable and informs the container of it
// Demonstrates getting current values of state variables from the System Agent
void CStateVarObserver::ProcessCurrentStateL()
{
iAppContainer.ProcessStateVarChangeL(iObservingUid, iObservedValue);
}
//TODO: RunError function should be added with proper error handling
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -