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

📄 inactivitytimer.cpp

📁 基于Symbian OS的手机开发与应用实践第12章代码。主要讲各种时钟
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CInactivityTimer from InactivityTimer.cpp
*  Part of  : Autolock
*  Created  : 05.02.2006 by ToBeReplacedByAuthor
*  Implementation notes:
*     
*  Version  :
*  Copyright: ToBeReplacedByCopyright
* ============================================================================
*/

// INCLUDE FILES
#include "InactivityTimer.h"

// ================= MEMBER FUNCTIONS =======================

// Two-phased constructor.
CInactivityTimer* CInactivityTimer::NewL(MObserver& aObserver)
    {
    CInactivityTimer* self = new (ELeave) CInactivityTimer(aObserver);
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop();
    return self;
    }

// destructor
CInactivityTimer::~CInactivityTimer()
    {
    Cancel();
    }


void CInactivityTimer::Start(TTimeIntervalSeconds aTimeout)
    {
    Cancel();
    iTimeout = aTimeout;
    iInactivity = ETrue;
    Inactivity(iTimeout); 
    }

void CInactivityTimer::Stop()
    {
    Cancel();
    }


// constructor
CInactivityTimer::CInactivityTimer(MObserver& aObserver)
:CTimer(EPriorityStandard), iObserver(aObserver)
    {
    // No implementation required
    }

// EPOC default constructor can leave.
void CInactivityTimer::ConstructL()
    {
    //this is explicitly decareded in the CTimer document
    CTimer::ConstructL();

    // The following line is also essential!
    CActiveScheduler::Add(this);
    }
    

void CInactivityTimer::RunL()
    {
    if(iStatus!=KErrNone)
        {
        return;
        }

    if (iInactivity)
        {
        TTimeIntervalSeconds inactivity = User::InactivityTime().Int();
        if (inactivity >= iTimeout)
            {
            iObserver.OnTimerL(ETrue);
            if(!IsActive())
                {
                Inactivity(0);
                iInactivity = EFalse;
                }
            }
        else
            {
            Inactivity(iTimeout);
            }
        }
    else
        {
        iObserver.OnTimerL(EFalse);
        if (!IsActive())
            {
            Inactivity(iTimeout);
            iInactivity = ETrue;
            }
        }

    if (!IsActive())
        {
        SetActive();
        }
    }

// End of File  

⌨️ 快捷键说明

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