home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-28 | 4.0 KB | 154 lines | [TEXT/CWIE] |
- // ===========================================================================
- // • LDelayedTask.cp © 1995, Éric Forget. All rights reserved.
- // ===========================================================================
- //
- // ************************************************************************
- // * *
- // * Before using this code you should read the "License Agreement" *
- // * document and agree with it. *
- // * *
- // ************************************************************************
- //
- // LDelayedTask is an abstract class to execute a task after a certain
- // period of time. This class is not really precise: it use TickCount()
- // as time mesure. On another side, you can do about all you want in the
- // ExecuteSelf() method.
- //
- // One example of its use, is to implement a "Find" in a list or table,
- // a la Metrowerks IDE. Each time the user press a key, you call RestartTask().
- // When the user will not have pressed a key for a determined period, you
- // do the search in the ExecuteSelf() method.
- //
- // ---------------------------------------------------------------------------
- //
- // Instruction Notes:
- // -----------------
- //
- // 1) Derive this class (perhaps in mixin) and override ExecuteSelf();
- //
- // 2) In ExecuteSelf() you should return whether you want to continue
- // to be called after the next interval.
- //
- // ---------------------------------------------------------------------------
-
- #include "LDelayedTask.h"
-
- #include "UDelayedTaskQueue.h"
-
-
- // ---------------------------------------------------------------------------
- // • LDelayedTask
- // ---------------------------------------------------------------------------
-
- LDelayedTask::LDelayedTask(
- Int32 inFirstDelay,
- Int32 inNextDelay,
- Boolean inDeleteOnCompletion)
-
- : LTask(inFirstDelay, inNextDelay, inDeleteOnCompletion)
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~LDelayedTask
- // ---------------------------------------------------------------------------
-
- LDelayedTask::~LDelayedTask()
- {
-
- }
-
-
- // ---------------------------------------------------------------------------
- // • StartTask
- // ---------------------------------------------------------------------------
-
- void
- LDelayedTask::StartTask()
- {
- if(!IsExecuting()) {
-
- LTask::StartTask();
-
- UDelayedTaskQueue::AddTask(this);
-
- mStartTime = ::TickCount();
- mIsFirstTask = true;
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • StopTask
- // ---------------------------------------------------------------------------
-
- void
- LDelayedTask::StopTask()
- {
- if(IsExecuting()) {
-
- UDelayedTaskQueue::RemoveTask(this);
-
- LTask::StopTask();
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • ContinueTask
- // ---------------------------------------------------------------------------
-
- void
- LDelayedTask::ContinueTask()
- {
- mIsFirstTask = false;
- mStartTime = ::TickCount();
- }
-
-
- // ---------------------------------------------------------------------------
- // • StartTaskSelf
- // ---------------------------------------------------------------------------
- // For a DelayedTask, it is not necessary to pre allocate all the stuff!
-
- void
- LDelayedTask::StartTaskSelf()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • StopTaskSelf
- // ---------------------------------------------------------------------------
-
- void
- LDelayedTask::StopTaskSelf()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • IsItTimeToExecute
- // ---------------------------------------------------------------------------
-
- Boolean
- LDelayedTask::IsItTimeToExecute()
- {
- Int32 currentTime = ::TickCount();
- Boolean rval = false;
-
-
- if(mIsFirstTask) {
-
- rval = (currentTime >= (mFirstDelay + mStartTime));
-
- } else {
-
- rval = (currentTime >= (mNextDelay + mStartTime));
- }
-
- return rval;
- }
-
-