statevarobserver.cpp

来自「series60 应用程序开发的源代码 series60 应用程序开发的源代码」· C++ 代码 · 共 90 行

CPP
90
字号
/**
* 
* @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 + =
减小字号Ctrl + -
显示快捷键?