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

📄 integersummationidle.cpp

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

// INCLUDE FILES

#include "IntegerSummationIdle.h"
#include "PowerResMan.hrh"

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

// Destructor
CIntegerSummationIdle::~CIntegerSummationIdle()
    {
	// Make sure the active object is cancelled 
	if(iSumMore)
		{
		iSumMore->Cancel();
		delete iSumMore;
		}
    }

// 2nd Phase Constructor
void CIntegerSummationIdle::ConstructL()
    {
    }

// This function is called to initiate the calculation
void CIntegerSummationIdle::StartSumL()
	{
	// Reset the stage value and the summation total
	iStage = EStart;
	iTotal= 0;

	if (!(iSumMore))
		{
		// Create the CIdle object
		iSumMore = CIdle::NewL(CActive::EPriorityIdle);
		}
	 // Starts the background task
	 // The task is encapsulated in a TCallback object
	 // The function BackgroundSum will be called
	 // everytime this Idle time active object is scheduled to run
	 iSumMore->Start(TCallBack(BackgroundSum,this));
	}

// When we have been assigned some time to run this function will be called
// It should do some processing then return 0 if the task
// is complete, a positive value otherwise
TInt CIntegerSummationIdle::BackgroundSum(TAny* aIntSumIdle)
	{
	// Call DoBackgroundSum to do the actual processing
	return ((CIntegerSummationIdle*)aIntSumIdle)->DoBackgroundSum();
	}

// Implementation of one stage of the task
// If whole task is complete, returns 0, a positive integer otherwise
TInt CIntegerSummationIdle::DoBackgroundSum()
	{
	// 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 - by returning 
	// a +ve value - so we can do the next stage
	
	if(iStage != EFinalPhase)
		{
		iStage++;
		return TInt(ETrue);
		}
	else 
		{
		Completed();
		return TInt(EFalse);
		}
	}

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

⌨️ 快捷键说明

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