resonance 1.0.1
Loading...
Searching...
No Matches
timetask.h
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4
5#include "app/attachment.h"
6#include "sch/cmdid.h"
7
8namespace Sch {
9class TimeClock;
10} // namespace Sch
11
23class TimeTask : public Attachment {
24public:
31 TimeTask(Sch::TimeClock *pClock, long long nPeriodNs);
32
39 virtual ~TimeTask();
40
50 virtual void Print(std::ostream &stream);
51
60 virtual int Tick(long long nElapsedNs) = 0;
61
73 void Start(long long nEpochOffsetNs);
74
83 void Run();
84
93 void Stop();
94
96 static constexpr long long kNoEpochOffset = -1000000;
97
98private:
99 Sch::TimeClock *mClock; // +0x08 the clock the task is posted against
100 Sch::CmdID mCommand; // +0x0c the handle of the queued command, -2 while none is queued
101 long long mPeriodNs; // +0x10
102 long long mNextNs; // +0x18 the time the next run is due at
103 long long mEpochNs; // +0x20 the time the elapsed count is measured from
104};
Attachment()
Definition attachment.h:26
Handle that identifies one batch of commands the scheduler has queued.
Definition cmdid.h:35
Time base a scheduler measures its due times against, and the base class of Sch::TickClock.
Definition timeclock.h:23
virtual void Print(std::ostream &stream)
Write the literal {TimeTask} to a diagnostic stream.
TimeTask(Sch::TimeClock *pClock, long long nPeriodNs)
static constexpr long long kNoEpochOffset
The epoch offset Start() treats as an epoch at zero.
Definition timetask.h:96
void Stop()
Withdraw the queued command and forget its handle.
virtual ~TimeTask()
Withdraw the queued command.
void Start(long long nEpochOffsetNs)
Start the task now and run it at once.
void Run()
Run Tick() for the run now due and post the next one.
virtual int Tick(long long nElapsedNs)=0
Run the task.
Scheduling of timed commands.
Definition activefilter.h:9