📄 statevarobserver.cpp
字号:
/**
*
* @brief Definition of CStateVarObserver
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
#include "StateVarObserver.h"
// User includes
#include "SystemAgentDialog.h"
CStateVarObserver* CStateVarObserver::NewL(TUid aUid, CSystemAgentDialog& aDialog)
{
CStateVarObserver* self = NewLC(aUid, aDialog);
CleanupStack::Pop(self);
return self;
}
CStateVarObserver* CStateVarObserver::NewLC(TUid aUid, CSystemAgentDialog& aDialog)
{
CStateVarObserver* self = new (ELeave) CStateVarObserver(aUid, aDialog);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CStateVarObserver::CStateVarObserver(TUid aUid, CSystemAgentDialog& aDialog)
: CActive(EPriorityStandard),
iAppDialog(aDialog)
{
// Set the TRequestStatus for the event to use our iStatus
iSysAgentEvent.SetRequestStatus(iStatus);
// Set the iSysAgentEvent for monitoring the state variable with the requested UID
iSysAgentEvent.SetUid(aUid);
}
CStateVarObserver::~CStateVarObserver()
{
// Make sure this active object is cancelled and close connection to the System Agent
Cancel();
iSysAgent.Close();
}
void CStateVarObserver::ConstructL()
{
// Connect to the system agent
User::LeaveIfError(iSysAgent.Connect());
// Enable the event buffer to ensure no changes in the State Variable are missed,
// the default expiry time is 10s
iSysAgent.SetEventBufferEnabled(ETrue);
// Add this active object to the active scheduler
CActiveScheduler::Add(this);
}
void CStateVarObserver::StartL()
{
iSysAgent.NotifyOnEvent(iSysAgentEvent);
SetActive();
}
void CStateVarObserver::RunL()
{
// Inform the dialog that it needs to update itself due to a change in state variable
iAppDialog.ProcessStateVarChangeL(iSysAgentEvent.Uid(), iSysAgentEvent.State());
StartL();
}
void CStateVarObserver::DoCancel()
{
iSysAgent.NotifyEventCancel();
}
/**
* Gets the current value of the state variable and informs the dialog of it
*
* Demonstrates getting current values of state variables from the System Agent
*/
void CStateVarObserver::ProcessCurrentStateL()
{
TInt state = iSysAgent.GetState(iSysAgentEvent.Uid());
iAppDialog.ProcessStateVarChangeL(iSysAgentEvent.Uid(), state);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -