stopwatchtimer.h

来自「《基于Symbian OS的手机开发与应用实践》这本书的配套源码。」· C头文件 代码 · 共 120 行

H
120
字号
/*
* ============================================================================
*  Name     : CStopwatchTimer from StopwatchTimer.h
*  Part of  : Stopwatch
*  Created  : 05.02.2006 by ToBeReplacedByAuthor
*  Description:
*     Declares the timer engine class.
*  Version  :
*  Copyright: ToBeReplacedByCopyright 
* ============================================================================
*/

#ifndef __STOPWATCH_TIMER_H__
#define __STOPWATCH_TIMER_H__

// INCLUDES
#include <e32base.h> // for CActive

// FORWARD DECLARATIONS

// CLASS DECLARATIONS
/**
 *  A simple timer with observer.
 */
class CStopwatchTimer : public CActive
    {
    public: // interface
        /**
         *  The object which wants to receive timer event will implements 
         *  this interface
         */
        class MObserver
        {
            public:
                /**
                 *  Called when timer request completed
                 *  @param aTime The current time
                 */
                virtual void OnTimerL(const TTime& aTime) = 0;
        };

    public: // standard construction sequence
        /**
         *  Create a CStopwatchTimer object
         *  @param aObserver The timer event observer
         *  @result a pointer to the created instance of CStopwatchTimer
         */
        static CStopwatchTimer* NewL(MObserver& aObserver);

        /**
         *  Create a CStopwatchTimer object
         *  @param aObserver The timer event observer
         *  @result a pointer to the created instance of CStopwatchTimer
         */
        static CStopwatchTimer* NewLC(MObserver& aObserver);

        /**
         *  Destroy the object and release all memory objects
         */
        ~CStopwatchTimer();

    public: // new functions
        void Start();

        void Stop();

        void Resume();

        void Reset();

    private: // standard construction sequence
        /**
         *  Perform the first phase of two phase construction
         *  @param aObserver The timer event observer
         */
        CStopwatchTimer(MObserver& aObserver);

        /**
         *  Perform the second phase construction of
         */
        void ConstructL();

    private: //from CActive
        /**
         *  Used to trigger timer event
         */
        void RunL();

        void DoCancel();

    private: // new functions
        void After(TTimeIntervalMicroSeconds32 aInterval);

    private: // constants
        static const TInt KInterval;

    private: // member variables
        /**
         *  The timer event observer
         */
        MObserver& iObserver;

        /**
         *  The current total time
         */
        TTime iTime;

        /**
         *  The start time
         */
        TTime iStartTime;

    private:
        RTimer iTimer;
    };

#endif // __STOPWATCH_TIMER_H__

// End Of File

⌨️ 快捷键说明

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