⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statevarobserver.cpp

📁 基于Symbian平台下随心所欲控制屏幕的灯亮熄.在观看视频和发短信时这一点非常重要.
💻 CPP
字号:
/**
* 
* Definition of CStateVarObserver
*
* Copyright (c) 2004 Nokia Corporation
* version 1.0
*/

// INCLUDE FILES
// User includes

#include "StateVarObserver.h"
#include "PowerResManContainer.h"

// Creates instance of CStateVarObserver
CStateVarObserver* CStateVarObserver::NewL(TUid aUid, CPowerResManContainer& aAppContainer)
    {
    CStateVarObserver* self = NewLC(aUid, aAppContainer);
    CleanupStack::Pop(self);
    return self;
    }

// Creates instance of CStateVarObserver and leaves it on the cleanup stack    
CStateVarObserver* CStateVarObserver::NewLC(TUid aUid, CPowerResManContainer& aAppContainer)
    {
    CStateVarObserver* self = new (ELeave) CStateVarObserver(aUid, aAppContainer);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }

// Constructor
CStateVarObserver::CStateVarObserver(TUid aUid, CPowerResManContainer& aAppContainer)
 :	CActive(EPriorityStandard), 
	iAppContainer(aAppContainer)
    {
    
    
	// 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); 
    }

// Destructor
CStateVarObserver::~CStateVarObserver()
    {
	// Make sure this active object is cancelled and close connection to the System Agent
	Cancel();
	iSysAgent.Close();
    }

// 2nd phase constructor
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);
    }

// Called when the monitoring of the variable should begin
void CStateVarObserver::StartL()
	{
    iSysAgent.NotifyOnEvent(iSysAgentEvent);
    SetActive();
	}

// Handles request completion - called by the Active Scheduler
void CStateVarObserver::RunL()
	{
	// Inform the container that it needs to update itself due to a change in state variable
	iAppContainer.ProcessStateVarChangeL(iSysAgentEvent.Uid(), iSysAgentEvent.State());
	StartL();
	}

// Cancel outstanding request - called by Cancel()
void CStateVarObserver::DoCancel()
	{
	iSysAgent.NotifyEventCancel();
	}


// 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()
	{
	TInt state = iSysAgent.GetState(iSysAgentEvent.Uid());
	iAppContainer.ProcessStateVarChangeL(iSysAgentEvent.Uid(), state);
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -