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

📄 integersummation.cpp

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

// INCLUDE FILES

#include "IntegerSummation.h"
#include "PowerResMan.hrh"

// Creates instance of CIntegerSummation
CIntegerSummation* CIntegerSummation::NewL(MSummationObserver& aObserver)
    {
    CIntegerSummation* self = new (ELeave) CIntegerSummation(aObserver);
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(self);
    return self;
    }
    
// Constructor
CIntegerSummation::CIntegerSummation(MSummationObserver& aObserver)
 :	CActive(EPriorityLow), iObserver(aObserver)
    {
	iStage = EStart;
    }

// Destructor
CIntegerSummation::~CIntegerSummation()
    {
	// Make sure this active object is cancelled 
	Cancel();
    }

// 2nd Phase Constructor
void CIntegerSummation::ConstructL()
    {
	// Add this active object to the active scheduler
	CActiveScheduler::Add(this);
    }

// This function is called to initiate the calculation
void CIntegerSummation::StartSum()
	{
	// Values for the stages & sum are reset
	iStage = EStart;
	iTotal =0;
	
	// The first part of the task (calculation is started)
	DoStage();

	}

// Completes one step of the task and then requests
// more time from the Active Scheduler if processing is not complete
void CIntegerSummation::DoStage()
	{
	// Add the next 100 numbers to the total
	// iStage keeps track of where we are up to in the calculation
	for (TInt i = iStage*100; i < (iStage+1)*100; i++)
		iTotal += i;

	// If we have not reached the final stage then update the iStage
	// parameter and put in a request for more processor time so we can do the next stage
	if(iStage != EFinalPhase)
		{
		iStage++;
		iStatus=KRequestPending;
		SetActive();
		TRequestStatus* status = &iStatus;
		User::RequestComplete(status, KErrNone);
		}
	else
		Completed();

	}

// Handles request completion - called by the Active Scheduler
void CIntegerSummation::RunL()
	{	
	// We've been allocated some time
	// so we do another stage of the task
	DoStage();
	}

// Cancel outstanding request - called by Cancel()
void CIntegerSummation::DoCancel()
	{
	// Nothing to do
	}

// Called when the task is complete
// Notifies the observer of the result
void CIntegerSummation::Completed()
	{
	// Task completed - so let the obserser know
	iObserver.SummationComplete(iTotal);
	}

⌨️ 快捷键说明

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