blob: 303dca46db49ca71d959c9f3ba02ae18de95e062 [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Alexander Afanasyev
5 * Zhenkai Zhu
6 *
7 * BSD license, See the LICENSE file for more information
8 *
9 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
10 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
11 */
12
13#ifndef PERIODIC_TASK_H
14#define PERIODIC_TASK_H
15
16#include "task.h"
17#include "scheduler.h"
18#include "interval-generator.h"
19
20class PeriodicTask : public Task
21{
22public:
23 // generator is needed only when this is a periodic task
24 // two simple generators implementation (SimpleIntervalGenerator and RandomIntervalGenerator) are provided;
25 // if user needs more complex pattern in the intervals between calls, extend class IntervalGenerator
26 PeriodicTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler, IntervalGeneratorPtr generator);
27 virtual ~PeriodicTask(){}
28
29 // invoke callback, reset self and ask scheduler to schedule self with the next delay interval
30 virtual void
31 run() _OVERRIDE;
32
33 // set the next delay and mark as un-invoke
34 virtual void
35 reset() _OVERRIDE;
36
37private:
38 IntervalGeneratorPtr m_generator;
39};
40
41#endif // PERIODIC_TASK_H